What are the different feedback modes in JShell in Java 9?

JavaObject Oriented ProgrammingProgramming

When performing an operation in the JShell tool, it displays a message in return (success of the command, error, and type of a variable created as well as its value). It has been customized using the command: "/set feedback". This command displays the type of return currently configured as well as the different return modes available.

jshell> /set feedback
| /set feedback normal
| Available feedback modes:
| concise
| normal
| silent
| verbose

There are four feedback modes available in JShell as listed below:

1) /set feedback normal: This is the default JShell feedback. When we evaluate an expression, JShell returns the corresponding result and an internal variable in which the value was stored. In the case of variable creation, JShell returns the name of the variable and the corresponding value. When creating a data type (method or class), JShell sends a return specifying the type we have created.

jshell> /set feedback normal
| Feedback mode: normal

jshell> 5 + 5
$1 ==> 10

jshell> int i = 20
i ==> 20

jshell> int sum(int a, int b) {
...> return a + b;
...> }
| created method sum(int,int)

2) /set feedback verbose: This the most informative feedback mode. When evaluating an instruction, it displays the corresponding result as well as an internal variable in which it has been assigned, and the type of the expression. It will be the same for the creation of a variable. Regarding the creation of a data type, the return is identical to normal mode.

jshell> /set feedback verbose
| Feedback mode: verbose

jshell> 2 + 2
$1 ==> 4
| created scratch variable $1 : int

jshell> String str = "Tutorix"
str ==> "Tutorix"
| created variable str : String

jshell> int div(int a, int b) {
...> return a/b;
...> }
| created method div(int,int)

3) /set feedback concise: This mode displays the minimum amount of information. When evaluating an expression, it tells us the name of an internal variable created as well as the result of the expression. On the other hand, regarding the creation of a data type (variable, method, or class), no return is made from JShell (unless the code is in error).

jshell> /set feedback concise
jshell> 2 + 2
$1 ==> 4
jshell> int i = 10;
jshell> float y = "xyz";
| Error:
| incompatible types: java.lang.String cannot be converted to float
| float y = "xyz";
| ^---^

4) /set feedback silent: This mode doesn't display any information. When we enter an expression to evaluate, JShell stores the result in an internal variable but doesn't indicate the corresponding result on the screen. The same can be true for the creation of a data type (variable, method, or class). Everything has been done internally without displaying any result on the screen (except in the event of order in error).

jshell> /set feedback silent
-> 3+3
-> int x = 7
-> int sum(int x, int y) {
>> return x + y;
>> }
-> double y = "abc";
| Error:
| incompatible types: java.lang.String cannot be converted to double
| double y = "abc";
| ^---^
Published on 06-Apr-2020 14:22:14