Java9 With JShell

Although most of the programming languages tend to come and go, Java is one that’s here to stay. As one of the most popular and widely adopted languages with a high performance, scalable runtime and innovations towards the JDK, it has a large impact on the world’s computing infrastructure.

The motive for evaluating Java9 is to make JDK more modular and to make Java more scalable for smaller computing devices, secure, performant, and to improve developer productivity. With the boom of the Internet of Things (IoT), enabling Java to run on the smaller devices is instrumental for continued growth.

Among the most popular web protocols, HTTP has been getting its own upgrade to HTTP/2, boasting significant network performance gains. API implementing HTTP/2 and WebSocket to replace the effect of HttpURLConnection, which predates HTTP/1.1 has various limitations such as the one thread per request/ response behavior. Using HTTP/2 in Java 9, applications will have better performance and scalability with memory usage on par or lower than HttpURLConnection, Apache HttpClient, and Netty. Hence, Java 9 will get its own HTTP client.

JDK9 users will get the shell (called JShell which is combination of Java and REPL (Read-Eval-Print-Loop)) like interface to interactively evaluate declarations, statements, and expressions in Java which is similar to Python or Ruby interpreters or other JVM languages like Scala and Groovy. Now Java users will be able to run Java code without any need of wrapping in classes or methods, allowing for a much easier, faster learning & experimentation.

Why JShell in java?

JShell Java Enhancement Proposal (JEP) for the project indicated that the new feature is the result of academic feedback. Schools are adopting languages that have REPL (Read-Eval-Print-Loop) functionality because it lowers down the initial learning curve of programming. Interactively REPL tool gives rapid evaluation of code to young developers.

For example:

jshell> void myJShell() { System.out.println("I am working in  JShell"); }
|  created method myJShell()
 
jshell> myJShell();
I am working in  JShell
 
jshell> void myJShell() { System.out.println("wow, I replaced a  method"); }
|  modified method myJShell()
|    update overwrote method myJShell()

Functionality:

The JShell API will provide all of JShell’s evaluation functionality. The code fragments that are input to the API are referred to as “snippets”. JShell tool will also use the JShell completion API to determine when input is incomplete (and the user must be prompted for more) or would be complete if a semicolon were added (in which case the tool will append the semicolon). The tool will have a set of commands for query, saving and restoring work, and configurations. Commands will be distinguished from snippets by a leading slash in the command.

Java Interaction of Java with Operating System:

So far there has been a limited ability for controlling and managing the operating system processes with Java. For example, in order to do something as simple as getting your process process ID in earlier versions of Java, you would need to either access the native code or use some sort of a magical workaround. However, it would require a different implementation for each platform to guarantee that you are getting the expected result.

Now Java has the ability to interact with the operating system: New direct API’s to handle PIDs, process names and states, and ability to enumerate JVMs and processes and more.

Performance:

The JVM Code Cache is critical to application performance and can be set at startup time using the following flag: -XX:InitialCodeCacheSize=32m.When the code cache memory is fully utilized, the JVM losses JIT and goes into interpreted mode, significantly affecting application runtime performance. In Java 9, this section of memory is getting divided into the following three distinct heap segments in order to improve performance .

  1. JVM internal (non-method) code.
  2. Profiled code.
  3. Non-profiled code.
Arpit Arora

Arpit Arora

Development Engineer at Calsoft Inc.
Very enthusiastic person and hardworking.Always try to take new responsibilities and make to deliver the best to fulfill the tasks. Has good understanding of tasks which are assign to him. Has a good hands on in Java.
Arpit Arora

Latest posts by Arpit Arora (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *