How to define variables in Java9 jshell
1 Answer
7 years ago by Divya
The following series of commands shows how to define primitive data types with values
jshell> byte byteVal = 127;
byteVal ==> 127
jshell> short shortVal = 32767;
shortVal ==> 32767
jshell> int intValue = 2147483647;
intValue ==> 2147483647
jshell> long longValue = 9223372036854775807L;
longValue ==> 9223372036854775807
jshell> float floatValue = 1.5F;
floatValue ==> 1.5
jshell> double doubleVaue = 12.678;
doubleVaue ==> 12.678
jshell> char charValue= 'f';
charValue ==> 'f'
jshell> boolean booleanValue = true;
booleanValue ==> true
jshell>
You can define Strings as shown in following example
jshell> String stringValue = "Foo";
stringValue ==> "Foo"
jshell>
You can access these variables with variable names on shell as shown in following example
jshell> System.out.println(stringValue);
Foo
jshell>
7 years ago by Karthik Divi