Versions
[{“Name”:“Java SE 9 (Early Access)”,“GroupName”:null}]
Introduction
JShell is an interactive REPL for Java added in JDK 9. It allows developers to instantly evaluate expressions, test classes, and experiment with the Java language. Early access for jdk 9 can be obtained from: http://jdk.java.net/9/
Syntax
- $ jshell — Start the JShell REPL
- jshell> /<command> — Run a given JShell command
- jshell> /exit — Exit JShell
- jshell> /help — See a list of JShell commands
- jshell> <java_expression> - Evaluate the given Java expression (semicolon optional)
- jshell> /vars OR /methods OR /types — See a list of variables, methods, or classes, respectively.
- jshell> /open <file> — read a file as input to the shell
- jshell> /edit <identifier> — edit a snippet in the set editor
- jshell> /set editor <command> — set the command to be used to edit snippets using /edit
- jshell> /drop <identifier> — delete a snippet
- jshell> /reset — Reset the JVM and delete all snippets
Remarks
JShell requires the Java 9 JDK, which can currently (March 2017) be downloaded as early access snapshots from jdk9.java.net. If, when you try to run the jshell
command, you get an error beginning with Unable to locate an executable
, make sure JAVA_HOME
is set correctly.
Default Imports
The following packages are imported automatically when JShell starts: