Feedback modes

Command-line tools usually provide relatively sparse feedback in an effort to not overcrowd the screen or otherwise become a nuisance to developers. JShell has several feedback modes in addition to giving developers the ability to create their own custom modes.

As you can see from the following screenshot, there are four feedback modes--concise, normal, silent, and verbose. Here, we entered the /set feedback command without any parameters to list the feedback modes as well as to identify what the current feedback mode is. The first line of output displays the command-line command and argument set that would be used to set the mode to the currently set mode. So, in the following screenshot, the current feedback mode is set to verbose and the other three modes are listed:

We can dictate which mode we want to enter when we first enter JShell by including an option when we launch JShell. Here are the command-line options:

Command-line command and option Feedback mode
jshell -q concise
jshell -n normal
jshell -s silent
jshell -v verbose

You will notice that we use -q for concise mode instead of -c. The -c option has the -c<flag> syntax and is used to pass <flag> to the compiler.

The best way to review the differences between the feedback modes is to use examples. Starting with the normal mode, we will execute command-line commands to accomplish the following ordered feedback demonstration:

  1. Create a variable.
  2. Update the variable's value.
  3. Create a method.
  4. Update the method.
  5. Run the method.

To start our first test, we will execute the /set feedback normal command at the jshell> prompt, which sets the JShell feedback mode to normal. After entering the normal feedback mode, we will enter the necessary commands to run our demonstration:

After entering normal feedback mode, we entered int myVar = 3 to and received myVar ==> 3 as feedback. In our next command, we changed the value of the same variable and received the same output with the new value. Our next statement, void quickMath() {System.out.println("Your result is " + (x*30 + 19));}, used a variable that was not declared and you see the resulting two-part feedback--one part indicating that the method was created and the other to inform that the method cannot be invoked until the undeclared variable is declared. Next, we changed our method to include the myVar variable and the feedback reported that the method was modified. Our last step was to run the method using quickMath(); and the results are as we expected.

Let's try this same feedback demonstration in concise mode:

As you can see from the preceding screenshot, the concise feedback mode provides us with much less feedback. We created and modified the variables and received no feedback. When we created the method with an undeclared variable, we received the same feedback that we did in normal mode. We updated the method without confirmation or other feedback.

Our next use of the feedback demonstration will be in silent mode:

When we entered silent feedback mode, as you can see in the preceding screenshot, the JShell prompt changed from jshell> to ->. There was no feedback provided when we created the myVar variable, modified the myVar variable, or created the quickMath() method. We intentionally created the quickMath() method to use an undeclared variable. Because we were in silent feedback mode, we were not informed that the method had an undeclared variable. Based on this lack of feedback, we ran the method and were not provided any output or feedback. Next, we updated the method to include the myVar declared variable and then ran the method.

The silent feedback mode might seem pointless as no feedback is provided, but there is a great utility with this mode. Using the silent mode might be appropriate for pipelining or simply when you want to minimize the amount of terminal output. You can include specific, conditional, outputs with implicit System.out.println commands, as an example.

Our last use of the feedback demonstration is in verbose feedback mode. This feedback mode, as you would assume from its name, provides the most amount of feedback. Here are our test results:

In our feedback demonstration, using verbose feedback mode, we receive a bit more feedback as well as a nicer format for the feedback.