In Part 1 of this Java 9 tutorial series, we covered Java 9 modules. Here in Part 2 of this series, we are going to explore JShell. Any up-to-date programming language has a REPL. In today's world, where you have two-week sprints and you need to learn while coding, it's important to have a fast feedback loop. You don’t want to set up a whole project just to test something in the code, right? The REPL brings that to you. REPLs are common in Scala, Python, Ruby, Shell scripts, and now also in… Java!

Java 9 has the following new features:

Java 9 REPL (JShell)

Factory methods for immutable List, Set, Map, and Map.Entry.

Private methods in Interfaces.

Java 9 module system.

Process API improvements.

Try With Resources improvement.

CompletableFuture API improvements.

Reactive Streams.

In this tutorial, we are going to go from zero into a working JShell.

Our plan:

Download Java 9 from scratch and install.

Run the shell.

Get help from Java 9's REPL.

Run a few calculations in JShell.

Define a function and use it.

Step 1: Download Java 9

Although we already covered downloading Java 9, we always want to start from the ground floor. We don’t want to force you to go to another tutorial in order to get any step, so here is how to download it into your macOS.

Step 5: Let’s Code a Function

Amazing, so we are able to quickly define functions and use them from within the shell. In general, everything looks so smooth.

Summary

After using modules in the previous tutorial, we went on to investigate Java 9 by checking out its REPL. We started again from ground zero. We downloaded Java 9 from scratch, then ran JShell, the new REPL provided by Java 9. We then ran some calculations, saw the variable returned, saw the default imports by the shell, and then quickly defined a function and used it, all without executing javac or java within the REPL. Way to go Java!