Using Variables in JShell of Java 9
Prerequisite : JShell in Java 9
We can declare variables and use anywhere throughout Jshell session. Let’s create an
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
Semicolon (;) is optional, we can leave it and it works fine. See, variable b is created without using semicolon.
If we don’t provide variable name, Java create implicit variable to store the value. These variables start with $ sign. We can use these variable by specifying implicit variable, as we did in the in the following screen-shot.
We can test any valid Java expression to get instant output. See, the following example.
Adding two integers
Creating and Calling Methods
To test method business logic, create a method and get result immediately. See, the following example