JShell tool has introduced in Java 9 that provides a fast and friendly environment that enables us to quickly explore, discover, and experiment with Java language features and extensive libraries.
When the code entered into the JShell console, it is processed by JLine. It is a Java library that allows us to capture on a console. Once the code has been entered, it is parsed by JShell parser in order to determine its type (method, variable, etc.).
JShell Parser is wrapped in a class with the following rules:
After this step, the generated source code is analyzed and compiled in Bytecode by the Java compiler, then sent to a process running JVM in order to load and execute the code.
In the below code snippet, we can able to launch the JShell tool by simply typing "jshell" in command-line prompt.
C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell>
When JShell starts, we have a command prompt waiting for input. There are two types of commands that can be entered: JShell internal commands begin with a “/” and Java code.
In the below code snippet, we can able to print both internal commands like "/list" and Java code like System.out.println().
jshell> System.out.println("Tutorialspoint") Tutorialspoint jshell> /list 1 : System.out.println("Tutorialspoint")