Wednesday, July 3, 2024
HomeLanguagesJavaUsing Variables in JShell of Java 9

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 integer variable. jshell variable  example Semicolon (;) is optional, we can leave it and it works fine. See, variable b is created without using semicolon. jshell variable

Scratch Variables

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 following screen-shot. 
jhsell variable

Expressions

We can test any valid Java expression to get instant output. See, the following example. Adding two integers jshell add Compound expression Creating and Calling Methods To test method business logic, create a method and get result immediately. See, the following example jshell method jshell calling

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments