Eddú Meléndez

Java 9: JShell

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
java -version

Terminal will display the java version and the build number.

1
2
3
java version "1.9.0-ea"
Java(TM) SE Runtime Environment (build 1.9.0-ea-b90)
Java HotSpot(TM) 64-Bit Server VM (build 1.9.0-ea-b90, mixed mode)

Now, that you have installed the right version you just need to execute the following command:

1
jshell

Terminal will display something like this:

1
2
3
4
|  Welcome to JShell -- Version 1.9.0-ea
|  Type /help for help

->

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
-> "Hello World"
|  Expression value is: "Hello World"
|    assigned to temporary variable $1 of type String

-> String saludo = $1
|  Added variable saludo of type String with initial value "Hello World"

-> System.out.print
print(     printf(    println(   

-> System.out.println(saludo)
Hello World

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
java -jar kulla--20151104010121.jar

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!

Comments