More than three years after the release of Java 8, the next version is now just around the corner with a tentative release date of September 21st, 2017. You may have heard about Java 9’s module system, but there’s even more to this new version. Here are nine exciting new features that will ship with Java 9.

1. The Java Platform module system

The defining feature for Java 9 is an all-new module system. When codebases grow larger, the odds of creating complicated, tangled “spaghetti code” increase exponentially. There are two fundamental problems: It is hard to truly encapsulate code, and there is no notion of explicit dependencies between different parts (JAR files) of a system. Every public class can be accessed by any other public class on the classpath, leading to inadvertent usage of classes that weren’t meant to be public API. Furthermore, the classpath itself is problematic: How do you know whether all the required JARs are there, or if there are duplicate entries? The module system addresses both issues.

Modular JAR files contain an additional module descriptor. In this module descriptor, dependencies on other modules are expressed throughrequires statements. Additionally, exports statements control which packages are accessible to other modules. All non-exported packages are encapsulated in the module by default. Here’s an example of a module descriptor, which lives in module-info.java:

Leave a Comment

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

Scroll to Top