JShell is a Java REPL tool introduced in JDK 9 (for more information, see JEP 222 ). It enables you to interactively evaluate Java expressions without the overhead of creating an executable class, compiling your code, and so on.
IntelliJ IDEA includes a basic console for working with JShell from inside the IDE, similar to the Groovy Console. You can use the JShell Console to try out code snippets, which can even reference the classes defined in your project.
Open the JShell Console
From the main menu, select.
This opens the JShell Console tab in the editor, where you can type Java code, for example:
Press Ctrl+Enter to run this code in JShell. You should see the following output in the Run tool window:
In order to use the JShell Console, you need to have Java 9 or later available. You can run IntelliJ IDEA on an older runtime, and your project can use an older JDK, but you must select a supported Java version from the JRE list at the top of the JShell Console tab. Or click to specify the path to a valid Java version.
By default, all libraries that your project depends on are available to the JShell Console. You can use the Use classpath of list to select a specific module.