JShell
suggest changeVersions
The original version list named only Java SE 9 (Early Access).
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 builds of JDK 9 were published at 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:
import java.io.*
import java.math.*
import java.net.*
import java.nio.file.*
import java.util.*
import java.util.concurrent.*
import java.util.function.*
import java.util.prefs.*
import java.util.regex.*
import java.util.stream.*
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents