Modules   «Prev  Next»

Java Modules

A module is a named set of packages, resources, and native libraries. Java 9 introduced the concept of a module, a new java entity that is similar to an executable jar in its production state, but includes 1) a name and 2) descriptor class that provides benefits that did not exist prior to Java 9.

The benefits of a module are :

1. Stronger in capsulation at a higher level which improves security

Prior to Java 9

Prior to Java 9 any class in any package with a public or protected access modifier that was included in a jar on the classpath was by its nature publicly accessible or extensible by all of the application code. There was no way to hide this information. In JDK 9, you have three ways to expose your public types you can make them.
  1. one public to everyone unqualified exposure
  2. public two specific modules deemed friends (qualified exposure)
  3. Not public to any other module but only two the package is included in the module itself

Benefits

A module descriptor will specifically declare which packages are visible to other modules executing in the same application space .
2. Reliable dependencies which improves stability.
A module descriptor requires a module to specifically declare which modules it is dependent upon publishing its dependencies to consumers.

Understanding Modules

  1. Describe the modular JDK
  2. Declare modules and enable access between modules
  3. Describe how a modular project is compiled and run

Java 9 Modularity