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:
- From the menu Tools, Open Java Platform Shell
- 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.
…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
Do you want to support this blog? You may help to finance the needed hardware.
Want to read more about software development? Purchase one of my books:
Start application development with Java. Learn development foundation, quality control and more.
A Journey through Java EE Technologies whilst developing Web Applications with JavaServer Faces.
Java Lambdas and Parallel Streams
The compact starter: Foundation, supporting structures, parallel processing
No software development, just nature:
A photographic image book. Get it for free. Or pay whatever you like.
Hello Michael,
The article seems very interesting, thanks for the constant contribution
I have Netbeans 8.2 running on JDK 1.8 and Windows 10. I can´t see on theTools menu the Java Platform Shell
You mentioned that there is a patch where I can find that?
Regards
Hello Marcello,
The Java Shell isn’t available in NB 8.2 or in the 8.2 patch.
You have to download the development version. Use link no [1] at the end of my article.
Best,
Michael