Java 9 is inching toward its general availability (23 March, 2017). JDK committers are hard at work to deliver because the countdown has begun. Java Enhancement Proposals (JEP) has published a long list of features as its improvement proposals. It includes many major/minor improvements in the form of new capabilities, syntactical changes, performance tweaks, and the much anticipated modularity. These improvements will soon bring about some noticeable changes in the way we program in Java. This article picks up ten key areas from the JEP index that are going to influence Java programmers in the years to come.
1. Flagship Feature: Project Jigsaw
If lambda is a flagship feature of Java 8, modularity is the flagship feature of Java 9. Modularity is the result of the heavy influence of Project Jigsaw. It is actually a deferred feature that was supposed to be included from Java 8, but got a go-ahead with Java 9. It is expected to change the paradigm of Java coding in maintaining dependency issues popularly called jar hell, something that rhymes with DLL hell. Although Maven has provided a certain respite, Project Jigsaw is anticipated to be the core response to the much needed capability of Java. Maintaining a transitive dependency in an application is and always has been a pain in the neck. Java 9 will better understand the dependency across modules and resolve them at compile time or run time. According to JEP, the primary goal of this feature is to:
- Enhance scalability of the Java SE platform and JDK down to small computing devices
- Improve security and maintainability
- Provide easy construction and maintenance of libraries
The enhancement will have an overall impact on both the Java SE and Java EE platforms.
2. Process API Updates (JEP 102)
Another major improvement can be seen with the APIs dealing with controlling and arranging operating system processes. Until Java 8, this had been a neglected area and Java API support was quite limited. Programmers had to resort to native codes to handle many of the core features of the underlying operating system. The new APIs will provide considerable support in this area.
3. Multi-resolution Images (JEP 251)
The API dealing with images in the java.awt.image package is also revamped. The API enhancement will enable a set of images to be encapsulated into a single multi-resolution image. The variance of resolution can be retrieved based upon DPI metrics and a set of image transformation APIs.
4. Stack-walking API (JEP 259)
Java 8 does not have any efficient APIs to traverse selected frames on the execution stack and to access the Class instance of each frame. The new stack-walking APIs will enable us to filter and lazy load the information in stack traces.
5. Logging API and Service (JEP 264)
Java 9 enhanced the logging infrastructure used by the JDK classes with the help of new Service Loader APIs. Until now (Java 8), JDK classes use their own logging infrastructure. With Java 9, we’ll have a choice to use the default logging implementation based upon the java.util.logging or route platform log messages to the logging framework such as SLF4J or Log4J.
6. Language Updates (JEP 213)
There are many minor tweaks introduced with Java 9 language syntaxes, apart from improving the capabilities of interfaces. A Java 9 interface can declare private methods, keeping intact the feature of the default method introduced by Java 8. The try-with-resource statement syntax has been improved. The syntaxes with anonymous class now can infer their designated type. Other improvements included in the area such as annotation @SafeVarargs, deprecated syntaxes, and so forth.
7. Concurrency Updates (JEP 266)
Concurrency updates are minimal and are supposed to be a response in support of the Reactive System public-subscribe network. A handful of interfaces is provided, which can help developers build custom components to support interoperability across various async systems running in JVMs.
8. Factory Methods for Collections (JEP 269)
Java 9 made important changes in the process of creating an ad-hoc collection with the help of the static factory method. This will work on the Collection interface to create an unmodifiable collection instance. Java 8 and its predecessors had been quite verbose even in creating a simple list, as follows:
List<String> list1 = new ArrayList<>(); list1.add("Un"); list1.add("Deux"); list1.add("Trois"); list1 = Collections.unmodifiableList(list1);
Alternatively,
List<String> list2 = Collections.unmodifiableList(new ArrayList<> (Arrays.asList("Quatre", "Cinq", "Six")));
or,
List<String> list3 = Collections.unmodifiableList(new ArrayList<String>() { { add("Sept"); add("Huit"); add("Neuf"); add("Dix"); }});
With Java 9, we’ll be able to achieve the same with the help simple factory method, as follows:
List<String> list4=List.of("Onze", "Douze", "treize");
9. Desktop Features (JEP 272)
Java 9 introduces an API to support the manipulation of platform-specific desktop features. Targeted platforms are Windows, Linux, and Mac OS X. The public APIs will enable programmers to interact with the taskbar or dock, or listening for systems or application events.
10. Enhancement on Serialization Process (JEP 290)
There has been criticism on the object serialization mechanism conventionally implemented by the core JVM framework. Data transmission is a serialization task and may be compromised, which in turn may make the JVM itself vulnerable. Java 9 seems to take on the issue and provides a sort of filtering mechanism on incoming streams to improve the security and robustness of the existing system of the serialization and deserialization processes.
Conclusion
Apart from these ten, there are many other tweaks and enhancements to be served once the feature complete Java 9 is released. Other improvements areas are in the arena of low-level APIs, networking, XML, Nashorn parsing APIs, existing API extensions, jshell, and so on. Many old APIs have been removed from the core library. Moreover, the JDK 9 file structure also has been revamped. Java 8 and its prior version users will find something new right from the installation directory. However, nothing appeases us until we see the final release. Until then, we wait for the final countdown.