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, libraries that your project depends on are available to the JShell Console. You can use the Use classpath of list to select specific modules. If you want the JShell Console to reference classes and methods defined by your project, make the output of your project available to IntelliJ IDEA as a library:
Open the Project Structure dialog Ctrl+Shift+Alt+S and select Libraries in the left part.
Click , select Java, and specify the location of the output classes of your project.
Click OK to apply the changes.