IntelliJ IDEA 2019.2 Help

JShell Console

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 Tools | JShell Console.

This opens the JShell Console tab in the editor, where you can type Java code, for example:

String name = "John"; System.out.println("Hello " + name);

Press Ctrl+Enter to run this code in JShell. You should see the following output in the Run tool window:

Defined field String name = "John" System.out.println("Hello " + name) Hello John

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 The Add JRE button 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:

  1. Open the Project Structure dialog Ctrl+Shift+Alt+S and select Libraries in the left part.

  2. Click the New Project Library button, select Java, and specify the location of the output classes of your project.

  3. Click OK to apply the changes.

Last modified: 17 October 2019