It’s been more than twenty years since the introduction of the Java Platform and Java is still one among the most popular programming languages worldwide with a community of over 9 million developers. Hence every new Java release attracts the interest of millions of software developers. The features included in every release are usually a result of consensus between major vendors and stakeholders of the language such as Oracle and Redhat with Oracle in a leading role.
The latest version of Java i.e. the 9th edition of its platform and the corresponding JDK (Java Development Kit) was released last September. This version includes many interesting features that could boost developers’ productivity and versatility. It’s therefore certainly worth exploring this version in terms of the benefits it can provide to developers. The following paragraphs provide a quick overview of some of the most important features of Java 9 which is considered a milestone release for an additional reason: It is the last version to be released based on the conventional sequential numbering. From now on Oracle plans for more frequent releases which will be every six months and will be versioned after the year of the release and the number of the release within that year (e.g., 18.1, 18.2 and so on).
Java 9: What’s New?
Java 9 provides several new features and capabilities that were not present in previous versions such as listed below.
Java 9 provides exceptional modularity based on a brand new module system. Modularity aims at keeping large codebases manageable through easing code encapsulation and tracking of dependencies. In particular, Java 9 supports modular JAR (Java Archive) files which comprises of an additional module descriptor. The Additional Module Descriptor contains two new statements:
- “Requires” statement which express dependencies and
- “Export” statements which control the packages that are accessible to other modules.
The JVM (Java Virtual Machine) of the 9th version is in charge of verifying whether all modules can be resolved taking into account the “requires” statements of the descriptor. Likewise, it prohibits the use of classes from packages that are not “exported”. Overall, the modularity in Java 9 facilitates the structuring of complex applications in a way that enforces encapsulation and explicitly declares the dependencies.
Java 9 integrates the JShell tool which provides the means for interactive Read-Eval-Print Loops (REPL). The latter are particularly handy when it comes to exploring APIs and testing language features. This is for example needed in the case of Java training and education where trainers want to type and execute Java code interactively. It’s also useful for fast testing and prototyping. Note that many other languages (such as R and Python) provide support for this interactivity. However, this feature was lacking from the Java platform before the advent of Java 9.
One of the common use cases in Java involves the creation of a collection (e.g., an ArrayList) and its population with some elements. In such use cases, the same code is repeated whenever ‘add’ calls are included. Java 9 includes a set of new methods that populate the data structure with only one command. These methods are classified as “collection factory” methods. The merit of these methods is that developers would be able to write less and better readable code while also optimizing the number of elements that might be inserted into the collection. As such they contribute to improved performance and productivity.
Improved Process API
Java has been traditionally divorced from low-level operating system processes and programming. In particular, earlier versions of the language offered very limited abilities for controlling and managing low-level processes. In several cases interaction with such processes required native language programming (e.g., via the JNI (Java Native Interface)) or the development of some low level hack. Likewise this would increase the effort of maintaining process related code for different platforms and operating systems which broke Java’s “write once run everywhere” principle. Java 9 alleviates these limitations based on new methods for handling process identifiers (PIDs), process names and process states. While these features do not concern the majority of Java developers, they are very important for the class of tasks that involve direct interactions with the operating systems.
The default Garbage Collector has changed
Many Java developers ignore the fact that Java has four garbage collectors rather than a single one. In Java 9, the default garbage collector has changed from the “Parallel / Throughput Collector” to the G1 which was introduced in Java 7. This means that Java 9 provides better support for heaps over 4GB size while causing less frequent passes. In essence, this leads to an improved performance in the garbage collection process. This is another low-level feature of Java 9 which operates behind the scenes and makes the platform more efficient.
HTTP 2.0 Support
Java 9 provides new APIs for HTTP calls which support WebSockets and HTTP 2.0 out of the box. Nevertheless, the relevant APIs are in “incubator mode” i.e. they are not final yet. HTTP2.0 support includes new streaming functionalities.
Whenever a new version of Java is released, it usually takes time for application developers to adapt to it and switch to the new version. For example, there are still applications that are compatible with Java 6 and Java 7. The latest Java version provides a multi-release JAR feature which enables the creation of alternate versions of classes that are used in conjunction with specific Java versions notably older versions such as Java 7.
The above list of Java 9 features is not exhaustive yet it is indicative of the new version’s ability to improve developers’ ease and productivity. In addition to these features, Java 9 deprecates some APIs of older versions (such as the Applet API) while introducing some complementary improvements in documentation (Javadoc). It’s also noteworthy that some of the listed improvements are based on known Java projects (such as the JShell), which ultimately made it to the core Java platform. We strongly believe that Java developers will appreciate and enjoy using these features in their Java systems and applications. It’s probably time you download and start using JDK 9!