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

How it works...

The central class in the API is the jdk.jshell.JShell class. This class is the evaluation state engine, whose state is modified with every evaluation of the snippet. As we saw earlier, the snippets are evaluated using the eval(String snippet) method. We can even drop the previously evaluated snippet using the drop(Snippet snippet) method. Both these methods result in a change of the internal state maintained by jdk.jshell.JShell.

The code snippets passed to the JShell evaluation engine are categorized as follows:

  • Erroneous: Syntactically incorrect input
  • Expressions: An input which might or might not result in some output
  • Import: An import statement
  • Method: A method declaration
  • Statement: A statement
  • Type declaration: A type, ...

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