Tuesday, 8 December 2015

New features in Java 9

New features in Java 9

Java 8 described as the major release of lambdas, streams and API changes, then Java 9 is all about Jigsaw, extra utilities and changes under the hood.


1. Java + REPL = jshell

The next release of Java will feature a new command line tool called jshell. It will Java way to REPL (Read-Eval-Print-Loop). 
REPL = If you’ll want to run a few lines of Java on their own you can run is as command prompt. you don’t have to wrap it all in a separate project or method. you don't required to use even semicolons.
-> 2 + 2
| Expression value is: 4
|     assigned to temporary variable $1 of type int

2. Microbenchmarks

The Java Microbenchmarking Harness (JMH) is a Java harness for building, running, and analyzing nano/micro/milli/macro benchmarks. When it comes to accurate benchmarking, there are forces in play like warm up times and optimizations that can have a big impact on results. Especially when you’re going down to micro and nano seconds.
JMH is your best choice if you want to get the most accurate results to help you reach the right decision following your benchmarks – And now it’s becoming a synonym with Java 9.

3. G1 be the new default garbage collector

With Java 9, There’s a running proposal that’s still in debate to replace the default garbage collector (The parallel / Throughput collector) with G1 which was introduced in Java 7.
Generally, G1 was designed to better support heaps larger than 4GB and has been known to cause less frequent GC pauses, but when a pause do comes, it tends to be longer.

4. HTTP 2.0 is the future

The official HTTP 2.0 RFC was approved just a few months ago, building on top of Google’s SPDY algorithm. SPDY has already shown great speed improvements over HTTP 1.1 ranging between 11.81% to 47.7% and its implementation already exists in most modern browsers.
Java 9 will have full support for HTTP 2.0 and feature a new HTTP client for Java that will replace HttpURLConnection, and also implement HTTP 2.0 and websockets.

5. The process API just got a huge boost

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

public static void main(String[] args) throws Exception
Process proc = Runtime.getRuntime().exec(new String[]{ "/bin/sh", "-c", "echo $PPID" });
if (proc.waitFor() == 0)
InputStream in = proc.getInputStream();
int available = in.available();
byte[] outputBytes = new byte[available];
String pid = new String(outputBytes);
System.out.println("Your pid is " + pid);
In Java 9, expect the code for retrieving Linux PIDs, that now looks like this:

System.out.println("Your pid is " + Process.getCurrentPid())

The update will extend Java’s ability to to interact with the operating system: New direct methods to handle PIDs, process names and states, and ability to enumerate JVMs and processes and more.

6. Debugging in Production

Solving errors in production has always been a messy practice, grepping for clues over huge log files, and trying to identify the state that caused each exception or logged error. But what if you could avoid logs altogether? Here’s how it’s done.

7. A standardized lightweight JSON API

On a survey we conducted with 350 developers, the JSON API was just as hyped as Jigsaw but looks like it didn’t make the cut due to funding issues. Mark Reinhold, chief architect of the Java platform, on the JDK 9 mailing list:
“This JEP would be a useful addition to the platform but, in the grand scheme of things, it’s not as important as the other features that Oracle is funding, or considering funding, for JDK 9. We may reconsider this JEP for JDK 10 or a later release. ”

8. Money and Currency API

In other news, it also looks like the expected Money and Currency API is also lacking Oracle support. This is the answer we got from Anatole Tresch, the APIs spec lead:

New features in Java 8

JAVA 9 Schedule

proposed schedule for JAVA 9

JAVA 9 is scheduled for September 2016.

2015-12-10 – Feature Complete – All features implemented and integrated into the master forest
2016-02-04 – All Tests Run – All planned tests have been run on all supported platforms
2016-02-25 – Rampdown Start – Increased level of scrutiny is applied to incoming changes
2016-04-21 – Zero Bug Bounce – The bug backlog is completely addressed
2016-06-16 – Ramp down Phase 2 – A second round of checks is applied to incoming changes
2016-07-21 – Final Release Candidate – The final release candidate has been declared and submitted for testing
2016-09-22 – General Availability – Final release, ready for production use

More Info
New features in Java 9
New features in Java 8