English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
REPL (Read Eval Print Loop) means an interactive programming environment.
JShell is Java 9 A new interactive programming environment tool. It allows you to execute Java statements without using class or method wrapping. It is similar to Python's interpreter and can directly input expressions to view their execution results.
Execute JSHELL
$ jshell | Welcome to JShell -- Version 9-ea | For an introduction type: /help intro jshell>
View JShell commands
Input /The 'help' command can be used to view JShell-related commands:
jshell> /help | Type a Java language expression, statement, or declaration. | Or type one of the following commands: | /list [<name or id>|-all|-start] | list the source you have typed | /edit <name or id> | edit a source entry referenced by name or id | /drop <name or id> | delete a source entry referenced by name or id | /save [-all|-history|-start] <file> | Save snippet source to a file. | /open <file> | open a file as source input | /vars [<name or id>|-all|-start] | list the declared variables and their values | /methods [<name or id>|-all|-start] | list the declared methods and their signatures | /types [<name or id>|-all|-start] | list the declared types | /imports | list the imported items
Execute JShell command
/The 'imports' command is used to view imported packages:
jshell> /imports | 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.* jshell>
JShell Executing Calculations
The following examples execute simple calculations in JShell:
jshell> 3+1 $1 ==> 4 jshell> 13%7 $2 ==> 6 jshell> $2 $2 ==> 6 jshell>
JShell Creating and Using Functions
Create a function doubled() that multiplies the integer parameter by 2 after returning:
jshell> int doubled(int i){ return i*2;} | Created method doubled(int) jshell> doubled(6) $3 ==> 12 jshell>
Exit JShell
Input /The 'exit' command exits jshell:
jshell> /exit | Goodbye