Data Structure
 Networking
 RDBMS
 Operating System
 Java
 MS Excel
 iOS
 HTML
 CSS
 Android
 Python
 C Programming
 C++
 C#
 MongoDB
 MySQL
 Javascript
 PHP
- Selected Reading
 - UPSC IAS Exams Notes
 - Developer's Best Practices
 - Questions and Answers
 - Effective Resume Writing
 - HR Interview Questions
 - Computer Glossary
 - Who is Who
 
Using Variables in JShell of Java 9
In JShell 9, variables can be declared during a session. Once the user has logged into the session, they can declare a variable as follows −
jshell> int val = 56 ;
Italics indicate the terminal, once the user has logged in to their session.
The above line would print the below output. The semicolon in the above line is optional, and it will run fine without the semicolon also.
Output
val = = > 56
When an integer value is defined by assigning it to a variable name on the JShell, and it is executed, by pressing ‘Enter’ key, it is displayed on the next line of JShell command line.
Incase we don’t assign a variable to a value and just print it on the JShell, it will assign a variable to the value −
jshell> 79
Output
$3 = = > 79
When an integer value is defined without assigning it to a variable name on the JShell, and it is executed, by pressing ‘Enter’ key, it is displayed on the next line of JShell command line. Here, JShell itself assigns a variable name to the most recently entered variable value.