Modules   «Prev  Next»

Modular Dev with JDK 9

Oracle JDK 9 has a lot in it. Some of the features are performance improvements such as compact strings. Some are tooling improvements like the search box in Java doc that Mark showed in the keynote and the new J shell tool.

JShell Tool

JShell Tool
Some of course on this vast list are updates to existing features such as support for Unicode 8, but the main feature and the one that's taken many years to come to fruition is the Module System.

Modular JDK 9
Modular JDK 9

What is a Module

Modularity adds a higher level of aggregation above packages. The key new language element is the module, which is a uniquely named, reusable group of related packages, as well as resources (such as images and XML files) and a module descriptor specifying
  1. the module's name
  2. the module's dependencies (that is, other modules this module depends on) the packages it explicitly makes available to other modules (all other packages in the module are implicitly unavailable to other modules)
  3. the services it offers
  4. the services it consumes
  5. to what other modules it allows reflection

Which Components make up the Java 9 Module System

The Java 9 module system consists of the following components:
  1. Module declaration: A module is a named, self-describing collection of code and data. Each module has its own module descriptor (module-info.java), which declares its name, dependencies, and other information.
  2. Module path: The module path is a new feature in Java 9 that replaces the classpath. It is a list of directories and JAR files that contain the modules that are available to the Java Virtual Machine (JVM).
  3. Modules and the module graph: The module graph is the set of all modules and their dependencies. The JVM uses this graph to determine which modules are visible to other modules, and to resolve any conflicts that may arise due to overlapping packages.
  4. Encapsulation: Modules can encapsulate their internal implementation details, making them inaccessible to other modules by default. This allows for better encapsulation and encapsulation of internal implementation details.
  5. Services: The module system allows for the use of services, which is a way to allow a module to make some of its functionality available to other modules.
  6. Strong encapsulation: The module system provides strong encapsulation, which means that modules cannot use types that are not exported by other modules, unless they explicitly declare a dependence on them.
  7. Readability: The module system allows for the use of readability, which means that a module can use types from other modules, but not export them.
  8. Services: The module system allows for the use of services, which is a way to allow a module to make some of its functionality available to other modules.

Module System

The module system is a big deal because it enables modular development all the way down the 1)java language and 2) java virtual machine. Understand modules very deeply so that the applications you write and the libraries you consume and even the jdk itself can all be developed, tested, packaged and deployed as modules with clear API's and well protected internals making everyone play by the same modular rules has great benefits for 1) reliability, 2) maintainability and security. So with the theme of modules all the way down in minds

We have 3 three parts.

  1. The first part explains how modules are a long overdue building block in the structure of application code
  2. the second part is about how applications and the libraries they depend on can migrate to modules, that is it is about how you can mix modular and non modular code.
  3. The third part is about the structure of the modular JDK, including some of the compatibility issues that arise from that