O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the JShell Java API

JDK 9 provides the Java API for creating tools such as jshell for evaluating Java code snippets. This Java API is present in the jdk.jshell module (http://cr.openjdk.java.net/~rfield/arch/doc/jdk/jshell/package-summary.html). So, if you want to use the API in your application, then you need to declare a dependency on the jdk.jshell module.

In this recipe, we will use the JShell JDK API to evaluate simple code snippets, and you'll also see different APIs to get the state of JShell. The idea is not to recreate JShell but to show how to make use of its JDK API.

For this recipe, we will not be using JShell; instead, we will follow the usual way of compiling using javac and running using java.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required