Learning new Java tools

 While I have been using Java for almost 30 years, every now and then, I find new things I was not aware of in the Java toolset. Sometimes it is due to new libraries/classes; other times, it is brand-new tools. 

I have been using Python lately, and I have found the use of an interpreter for testing code snippets very helpful. Unfortunately, that is not something you can do with Java, right?

Well, that was the case till jshell was released. But what is jshell, let us say it is a Java's REPL. Like in Python, you can have an interactive session with the language interpreter, but now using Java. 

How does it work?

jshell is a command line tool you can find in OpenJDK or in Oracle's JDK since JDK 9


Not much different than Python, right? And you can ignore the semicolon at the end of each line :-)
But it is more than just a calculator; you can instantiate any type of object, and it all persists in memory the whole session.


It feels great to be able to have access to all the program state so you can get familiar with the methods and the values they return. You need not declare methods or classes.


There is not even the need to print values, as the tool will print out the value of an object for you.

There is a /help command to get a list of some of the special functions you may need to get the most out of this tool (for example, saving some of the code you wrote to a file). 

And ... yes, I am aware of the release date of JDK 9 :-)


Comments

Popular posts from this blog

VFD control with Arduino using RS485 link

How to get sinusoidal s-curve for a stepper motor

Stepper motor step signal timing calculation