Some weeks ago, NetBeans 8.2 had been released. Currently a patch version is available.  Although NetBeans has moved to Apache, it is still developed by the NetBeans team and a vibrant community. So, let’s look at a great feature of the future version: The Java Shell.

Today I’m not talking about the command line tool called JShell, which is part of Java 9. However, JShell is not only a command line tool, but an API which can be used in other applications. Since JShell is written in Java, it can be used right now. And this is what you find within the current NetBeans development version [1]. The Java Shell is integrated into NetBeans and offers lots more comfort than the command line version. There is no need to wait for Java 9. You may run NetBeans including the Java Shell by Java 8.

There a two different ways to invoke the Java Shell:

  1. From the menu Tools, Open Java Platform Shell
  2. Within the project tree’s context menu Execute Java Shell

Both will open the Shell, but with different contexts. Either the NetBeans platform or your application. The following series of screenshots will illustrate the second choice.

The shell immediately adds the compiled project classes to its classpath. Thus, it is possible to use classes of the project. And NetBeans offers you its great autocompletion.

More than that: if you choose a class from the autocompletion, NetBeans automatically inserts the appropriate import statement just before the line you are typing.

In the presented example, it is not possible to create a new instance of the PersonManager by new PersonManager(), but you can retrieve the instance of the singleton object. NetBeans investigates the source and offers the correct autocompletion within the shell.

After you developed some code interactive, you may want to persist it into the application. There is no need for some copy-paste-loose actions. NetBeans is able to save the session context into a class.

Simply add a classname…

…and NetBeans creates a class for you.

If I had use a pretty variable to assign the result instead of simply computing the stream, then the class would have contained this name instead of the default $ variable…

By the way, the PersonManager is part of the little application I used to explain Java Lambdas and Parallel Streams [2].

I’ll continue to observe the Java Shell withing NetBeans and to share some highlights with you.

Stay tuned!

 

[1] bits.netbeans.org/download/trunk/nightly/latest

[2] apress.com/de/book/9781484224861