What’s In Store For The Next Java

Pubblicato il - Ultima modifica il

The long-awaited Java Development Kit (JDK) 9 finally came on September 21, with a couple of fancy options. Oracle is planning a few upgrades, including ones for Java 18.3, scheduled for release around March 2018. This is part of the six-month standard Java release schedule.

It is over 3 years since the release of Java 8, and it might seem as if Java 9 was long overdue. There is more to the new version besides the module system that makes Java 9 worth the wait. For the next and subsequent versions of Java SE, Oracle has hinted at some features that are under consideration. These include:

1. Project Panama

This will interconnect native code with JVM. It features native data access from JVM and calling of native function from JVM.

2. Amber Project

The amber project has been the breeding ground for tiny productivity-oriented language features. It is expected to cut the stress associated with writing Java codes because of the local-variable type inference. The enums have also been improved to enhance expressiveness by executing sharper type-checking for enum, and letting type variables in the enum. Lambda usability also got a boost from lambda leftovers.

3. Valhalla

This is the platform for advanced language feature and Java VM, like generic specialization and value types.

4. Project Loom

The essence of project Loom is to cut down the intricacy in writing synchronized applications. Project Loom involves call-stack handling, restricted continuations, and user-mode thread executions. This proposal’s main goal is to present an alternative to thread implementation which Java-written schedulers manage.

Many describe the major feature of the Java 8 as API, streams, and lambdas. Judging by that standard, Java 9 is primarily about Jigsaw, API updates, and jshell. There are other exciting features about the Java 9 which will keep programmers busy.

During the countdown to the release of Java 9, there was an early access build. Besides the usual suspects, project Jigsaw is on the mission to break down the JRE and bring modularity to the core of Java’s components. Some of the other exciting features that come with Java 9 include:

1. Module system

The all-new module system is the key feature of Java 9. As codebases grow, there is an exponential increase in the odds of tangled, complicated “spaghetti code.” Two fundamental problems emerge from this; it becomes hard to encapsulate the codes, and there is no dependency between separate sections (JAR files) of a system. A public class can be retrieved by another public class, which can result in the usage of classes that were originally not intended to be public API. It is also hard to tell if the entire JARs are there, or if there are duplicate entries. The new module system solves both issues.

Modular JAR files have an additional module descriptor. This module descriptor has dependencies expressed as ‘require’ statements, while ‘exports’ statements decide which packages are available to other modules. The modules give you the power to better structure your application with strong implementation of encapsulation and plain dependencies.

2. Linking

A module with a modularized JDK and explicit dependencies springs new possibilities. Your application modules state their dependencies on the modules it gets from the JDK. This information can be exploited to create a minimal runtime environment, with only the necessary modules for your application.

This possibility is as a result of the new jlink tool that comes with Java 9. Instead of getting a shipment with the entire JDK installation, you can opt for a minimal runtime image-optimized version for your application.

3. jshell

Before the release of Java 9, many people were uncertain that project Kulla would make it. The new release has a command line tool known as jshell that adds native support, and brings the new Java REPL (Read-Eval-Print-Loop) into the limelight. This means that if you want to run a few lines of Java autonomously, there won’t be any need to wrap them in separate methods or projects.

The new Java REPL also takes out semicolons. jshell was available in the early release, which allowed programmers to test and try to get familiar with it. With jshell, Java joins the league of languages with interactive REPL. The instant feedback provided by jshell makes it an indispensable tool to further explore APIs.

4. Javadoc

The little things are often the ones that make the biggest difference in programming. In the past, many programmers use Google to search for the right Javadoc pages. In Java 9, that will no longer be required. This is because the Javadoc itself now has search in the API documentation.

As a bonus, the Javadoc output is now compliant with HTML5. Every page of Javadoc also has a sort of guide on which JDK module comes with the class or interface.

5. Stream API

It is easy to argue that the best improvement the Java standard library in a long time is the Stream API that features in Java 9. With Java 9, there are four new Stream interfaces, namely takeWhile, dropWhile, and ofNullable.

6. Private interface

Default methods on interfaces were one of the lauded features of Java 8. Instead of only method signatures, an interface can now contain behaviors. When there are several default methods on an interface with code that has almost the same effect, the normal approach would be to refactor the methods to call a private method encompassing the joint functionality.

There are several problems with this. Firstly, a default method cannot be private. Also, trying to create another default method that has the shared code will not work, because it will become part of the public API. Java 9 solves this glitch by allowing you to add private helper methods to interfaces.

7. HTTP 2.0

Java 9 presents a new way of performing HTTP calls. Although this has been long expected to replace the ‘HttpURLConnection’, the new API also supports HTTP/2 and WebSockets. The catch in Java 9 is that the new HttpClient API comes as _incubator module. The incubator module is usually an experimental feature that may advance into the next version or be erased - depending on its acceptance by users.

HTTP 2 was built on the algorithm of Google’s SPDY. SPDY has implemented great speed improvements over HTTP 1.1, and is currently present in many modern browsers.

8. G1

The new default garbage collector for Java 9 is the G1. Java actually has 4 garbage collector but there is a common misconception that there is only 1. Throughput Collector was the default garbage collector prior to the arrival of the Java 9. This is now replaced with the G1 which got its first appearance in Java 7.

The intended design of the G1 is for it to better support heaps larger than 4 gigabytes. It also causes fewer GC pauses. In the eventuality of a pause, it tends to last longer.

9. Debugging

This is not an exclusive feature of Java 9, but it helps in solving errors in production. The process has been a messy task as you would try to spot the state that caused the logged error or exception. Debugging in production can help you to avoid logs altogether.

Any feature missed out in the first release will likely come in six months’ time, when the next release is scheduled. Oracle has not given a clear hint as to when the proposed new features will be available in Java.

There is a lot to learn when you become a part of a developer community. Freelancer.com has great developers in the community where you can also find jobs that will help you explore the new Java 9.

If you have had a stint with the new Java 9, which of the features stood out for you? Did it meet your expectations? Share your thoughts with us in the comment box. Don’t forget to share this article with your friends!

Pubblicato 18 novembre, 2017

LucyKarinsky

Software Developer

Lucy is the Development & Programming Correspondent for Freelancer.com. She is currently based in Sydney.

Prossimo Articolo

Optimizing The New Version Of A System