Java 9 introduces JShell and a Read-Eval-Print Loop (REPL) for the Java Programming Language. REPL allows us to evaluate code snippets such as declarations, statements, expressions. We can test our code as we create it, and way before we are done with our whole project.

The JShell Java Enhancement Proposal (JEP) for the project indicated that the new feature is the result of academic feedback. Now a days Schools are adopting languages that have Read-Eval-Print Loops (REPL) functionality because it lowers the initial learning curve of programming. The interactive REPL tool gives us rapid evaluation of code to young developers.

Many compiled languages such as C/C++, CINT include tools for statements interpretation. Using these tools we can test code snippets rapidly without creating project. For small snippets we do not need to create main() method.

Run JShell

Once we downloaded jdk9 go to the installed directory there is a jshell executable in a bin(D:\codeNuclear\Jdk9\bin) directory. We suggest running it in verbose (-v) mode for the first time.

Basic Calculation

Each Result of the evaluation holds in a numeric variable starting with $.

Define Variable
Define Method

Update existence method

For more details of available commands in Jshell, Please refer Useful Commands of JShell.

2 Thoughts on “JShell with Example – Java 9”

Leave a Reply

Your email address will not be published. Required fields are marked *