JShell – Java 9 REPL

Introduction

Java is soon to release its new version – Java 9 with lots of exciting new features which will make our programming more easy and fast. The new Java release is everything about Project Jigsaw whose aim is to make the Java SE Platform and JDK more scalable for small computing devices. It will also provide more maintained and secure platform to us. This will have a great impact on the application performance with a great improvement and ease to the programmers in constructing and maintaining large applications and libraries for both Java EE and SE Platforms.

Apart from all the above features, the most appealing feature for programmers like me surely is the integration of Java with the REPL, which gives us the new JShell API. Yes, Java 9 is coming with the new command line tool called JShell which will provide us native support to popularize REPL (Read-Eval-Print-Loop). So let’s go deeper and have a look on JShell in more detail.

REPL (Read-Eval-Print-Loop)

REPL is not a new term. Many compiled languages already use REPL tools for statement interpretation. These tools make testing of code snippets rapid without having to create a project for it. When you use REPL, your code will be executed without any delay. The new release Java 9 will have full functional JShell – REPL Environment.

JShell

The code name for JShell is Project Kulla. The main aim of this project is investigating the creation of REPL tool for Java. JShell or Project Kulla is the first Java REPL- a command line tool which lets us run Java statements interactively without having to wrap them in methods and classes. It’s just the same way like the Python interpreter works. Earlier if you wanted to use this feature you would have to use alternatives like repl.it, but now with Java 9, REPL is coming bundled right into JDK with the langtools package.
REPL would serve as a great help for the new programmers who are just getting started with the language. Each expression will give you its type and return value which will provide valuable information for the newbies.

What will REPL bring us?

It is surprising that an established language like Java lacked REPL. But like many other languages, Java was missing it. But it’s a fact that Java needed it the most. Java had something similar to REPL in the form of Java BeanShell, but it was not fully featured REPL as in other languages. It was just a subset of full Java language syntax.

1. Reduced Turnaround time

What’s more important to a developer than giving him more time to think and create more usable code with less turnaround time.REPL will make it happen. It will shorten the turnaround time and feedback loop. A developer can be more productive when the results of the work he had done are seen immediately. Java REPL will make it possible to write and execute code simultaneously without having to exit for running a build. This will give more time to developers to evolve the code while writing it. It is true that many of the systems using Java are very complex, and it will be hard for an interactive REPL to integrate with it, but it can surely bring about a difference to someone who might find some fantastic use case with it in no time.

2. No need of Semicolon on bare statements

Yes, it’s true, and you can now relax and forget about adding semicolons every time at the end of the statements. Isn’t that a relief? And it’s all because of JShell. But that doesn’t mean that semicolons have gone completely they are here to stay as terminators and separators.

3. Freedom for networking access

With JShell you will have freedom from always using your machine to have networking access. Now you can also use your terminal for communicating with your server by connecting with it remotely using REPL as a terminal and controlling some parameters even from outside. You may also use it to query your database. There are also many other ways you may use this feature. So it is a great help for us as a programmer.

4. Saves and loads workspaces

Until now we have just talked about how JShell would be used in evaluating statements, but it will also give us lots of commands that will help us to navigate through REPL environment. We will be able to load and save workspaces and get back to the command prompt after the whole code has been executed. There are also other useful commands available for listing available methods and variables and viewing command history and listing all the written code so far.

5. Checked Exceptions – No more

Now you will not have to worry about checked exceptions ruining your experience with REPL. JShell has wrapped all exceptions in the background. So now on you will not be forced to catch an IOException which goes unnoticed. So that’s a great relief for us. Isn’t it?

6. JShell API

JShell also provides an API which will give all its functionality for all external uses. We can use external tools and use its capabilities. This will surely open some exciting possibilities for IDEs like Eclipse, Netbeans, and IntelliJ. JShell API also provides tools for using it for extending static analysis capabilities and automated testing. We will also be able to work with live JVMs.

7. No worry about changing Definitions

With the JShell changing declaration of variables, methods and classes become easy without the burden of original declarations. While changing the declaration, you will have a prompt message to let you know about what has happened, so it’s helpful for any programmer.

Summary

So in short JShell or Project Kulla is having a complete set of features while will surely be very exciting and beneficial for programmers. It has many use cases which will surely help developers to test the newly learned skills quickly in Java, whether its basic Java or any other new library which he would have just started to learn. So we can say that JShell is bringing Java on the same page with the other languages or even ahead of them. So let’s experience this new version of Java and have great ease and fun while programming.

Like this post? Don’t forget to share it!

Leave a Reply

Your email address will not be published. Required fields are marked *