JDK 9 Build b90 have been released few days ago and in this build JShell REPL has been integrated. Officially this is the Kulla Project.
REPL - Read- Eval- Print- Loop has been in other languages and now has arrived to Java. Now, we can write code in our terminal and it read, evaluate them, print the output and
Provide an interactive tool to evaluate declarations, statements, and expressions of the Java programming language, together with an API so that other applications can leverage this functionality. - JEP 222
If you want to know more about REPL check JEP 222.
To install the JDK 9 download from here. Make sure you have the right version and remember that build 1.9.0-ea-b90 is integrated with jshell
.
1
|
|
Terminal will display the java version and the build number.
1 2 3 |
|
Now, that you have installed the right version you just need to execute the following command:
1
|
|
Terminal will display something like this:
1 2 3 4 |
|
In the example below, start typing "Hello World"
and the value will be stored in $1
. Then, assign $1
to saludo
which is a String
. Finally, print saludo
.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Good, you have started playing around jshell
. As you can see, jshell
provides autocompletion with tab
key.
If you want test the last successful build from Kulla Project click here. Download the jar and execute it.
1
|
|
Check the REPL tutorial and play with java in your terminal.
If you want to start in java this is a good place to start and if you are an experienced developer then jshell is for you too!