Goals of the Modular JDK – Java Module System

Goals of the Modular JDK

Specific goals of the modular JDK, not surprisingly, align with the benefits of modules extolled in §19.1, p. 1163.

  • Stronger encapsulation: This results in well-defined communication boundaries between modules and stricter encapsulation of their internal implementation.
  • Reliable configuration: Any combination of modules must satisfy all dependencies both at compile time and runtime.
  • Enhanced performance: Modularized code is more amiable to program optimizations.
  • Improved scalability: The evolution of the Java platform can continue in a modularized fashion, as modules can be worked on in parallel.
  • Better security: Modularized code decreases the attack surface, and access through reflection is strictly controlled at runtime.

Overview of the Modular JDK

The monolithic library of the JDK has now been split into many modules, with each module defining a specific functionality of the JDK. The installation directory of the JDK, shown in Figure 19.1, gives an overview of how the JDK is organized. The path of the installation directory will vary depending on the OS platform.

Figure 19.1 Structure of JDK 17 Installation

  • The bin directory: This is where the executables are found—the Java Runtime Environment (JRE), which includes the Java Virtual Machine (JVM), and the JDK command-line tools, among others, that are necessary to develop and run Java programs.
  • The jmods directory: This directory epitomizes the modular JDK. It contains the platform modules of the JDK. These are compiled modules used to create custom runtime images of applications.

Each platform module is archived in a file having the name of the module and the extension .jmod—for example, java.base.jmod, java.se.jmod, and jdk.jartool.jmod. The modules beginning with the prefix “java.” implement the Java SE specification, often called standard modules. These are present in all implementations of the Java SE platform. The modules beginning with the prefix “jdk.” are platform specific, often called non-standard modules. These are not necessarily available for all implementations of the Java SE platform.

JMOD archives use a special archive format reserved for the platform modules, that are created using the JDK tool jmod. All JDK tools understand JMOD archives. The platform modules can be explored like any other application module. Examples of exploring such modules can be found in §19.13, p. 1211. There is seldom any need to create a JMOD archive or change the contents of the jmods directory.

Note that modules can be packaged both as JARs and as JMOD archives.

  • The lib directory: This directory contains additional class libraries and support required by the JDK. These files are not meant for external use.

Comments

Leave a Reply

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