Java Platform Module System (JPMS)

The neat feature of any programming language is the code reusability. Such feature helps to evolve a program from the small one to the way bigger one. Java is Object Oriented Language, it follows the concept of the OOP which is nicely described by the acronym APIE (Abstraction, Polymorphism, Interfaces and Encapsulation). As the basic unit of the Java Programming language can be seen the Class. The class may use an abstraction for reusing the its behavior or interfaces to reusing the defined abstractions. Those approaches support the code reusability but when the code base grows and requires to split an application across the multiple packages and related jar files. It may easily become quite unclear who is using what and who depends on what.

The Java Platform already offers the concept of packages. The package is the a mechanism that helps to encapsulate a group of classes. The Java also provides the concept of Access Modifiers (public, private, default, protected). Those modifiers can be used inside the packages and limit the visibilities on fields and class levels.

What happens when the code needs to be shared across the application domain? The public access modifier is used (previously the only way), which means that anyone can reuse the code inside the application and it may become to be hard to control who is reusing what and how.

Java introduces the Modules by the Java Platform Module System ( previously known as the project JigsawJava SE 9). The Java Modules concept provides a strong encapsulation of packages. Which allows to control their reusability inside the application codebase. The dependencies composition of the application code becomes to be transparent. It also increases the code maintainability, reliability and security.

The Module can be seen as the set of reusable packages.

The Java Module is maybe the one fo the most important improvement in Java since its beginning.

Java Module/Java Platform Module System motivation in bullets (JSR-376):
  • Strong encapsulation: In the past Java and JVM has no possibility to prevent other components from accessing the internal packages of others. Java Platform Module System has introduced the access-control mechanism through the specification. It is possible to declare a packages accessibilities and relation to others.
  • Reliable configuration:  JMPS provides a solution to poor, brittle and error-prone class-path mechanism of configuring components. The class-path can not express the relations between the components. JMPS allows to declare dependencies and relations among the components, packages
  • A scalable platform: Due to the increasing size of Java Platform it has made incredible difficult to run it on small devices. The Compact Profiles (JSR-337) were not flexible enough to fulfill the expectation. JMPS allows to decompose the Java Platform into the small customary  assembled configuration. Such configuration contains only required functionality.
  • Greater platform integrity: Accidental usage of  Java platform internal APIs may cause the security risk and a maintenance issue.
  • Improved Performance: support to application optimization techniques by known class and packages references and relations. Components are transparently linked between each other, rather then to all ones loaded at the run-time

Read Next: