One of the new and I think my favorite feature of the Java 9 SDK is the new tool called JShell. I have found the tool very useful in playing with legacy code. Legacy Java code can be very complex and I find it useful to be able to experiment with snippets of it without having to recompile and run the full project from an IDE or application server. This blog post will cover the basics of getting up and running with JShell. I will also use the technique in other blog posts.

Three steps to get jshell started:

          Install Java 9…

          Open a command prompt and navigate to the bin folder of the Java 9 SDK

          Execute jshell

I guess I could describe it in one step: C:\Program Files\Java\jdk-9\bin> .\jshell.exe

JShell will meet you with a suggestion to run /help intro, which I recommend to do. First time I used it I didn’t and it took me some time to figure out that all commands start with a forward slash, including /exit to quit the tool. After running “/help intro” and “/help” you will have a good overview of what this tool can do for you.

JShell is great for trying out snippets of old code that you are not quite sure how it works. Take a look at the post about the good old Hashtable for an example.

It is also great when you are learning Java or refreshing your Java skills. Preparing for the Java certification exam I used it quite a lot.