Java 9 modularity details emerge
Following last summer’s announcement that the JDK’s source code would be modularized by Project Jigsaw, Chief Architect Mark Reinhold has now given an insight to the latest developments in the modularization of Java.
Java’s chief architect has described in a new status report that the language’s forthcoming modular system will be a “fundamental new kind of Java program component”. Reinhold claims that Java developers will become “reasonably familiar” with the concept of modular Java in the next few years. Project Jigsaw, which aims to modularise the JDK and other large legacy codebases, is supposed to deliver a more reliable configuration solution and replace the “brittle, error-prone” class-path mechanism. At the same time, the new system should allow individual components to optionally make public types accessible to other components.
Reinhold’s preliminary definition describes the module as a “named, self-describing collection of code and data”. That means code should be comprised of an assortment of packages that contain types (such as Java classes and interfaces). The data consists of resources and other static information.
Modules can self-describe what other modules they need for compilation and operation. To determine which code from other modules refers to types from its own package, a module can describe which packages is exports. In the module system, the required modules are localised. The system should ensure that modules relate to each other only according to their type and described package.
These self-descriptions are expressed in the
module declaration and include neither a version string, nor constraints of the module’s version strings. They should guarantee that the module information is available both in the runtime, as well as in the compilation. Reinhold appears to be sold on the benefits of the new construct:
Expressing module declarations in a source file which is compiled, along with the other source files in a module, into a class file for consumption by the Java virtual machine is the natural way in which to establish fidelity. This approach will be immediately familiar to developers, and not difficult for IDEs and build tools to support. Build tools, in particular, can synthesize module declarations from information already available in project descriptions.
JSR 376 – A way out of the “JAR hell”?
Another innovation in Project Jigsaw is module artifacts, which will be used to adjust existing JAR files, native code and configuration data. Reddit users have already begun debating whether this will take the community out of the dreaded “JAR hell”, whereby various frameworks are based on different versions of the same library:
Curious Java programmers can read up on the module system’s module descriptor, platform modules, module graphs and module paths, as well as various other functions should check out the full status report. The main page of the Java Platform Module System (JSR 376) is also the best place to stay up to date. A documentation of the Quick Start with the module system is available on the Jigsaw project page.
General availability of Java 9 is planned for Autumn 2016. To see what’s planned for Java 9, you can in Article Seven Java 9 features, which you can rejoice to read. Early Access Releases for JDK 9 are on java.net to download.