With the release of Java 9, the Java community was introduced to a new level of programming experience with the Java Platform Module System (JPMS), also known as Project Jigsaw. The advent of this feature revolutionised the way Java applications are developed and deployed, bringing the concept of modularity to the Java platform. In this blog post, we delve into Project Jigsaw, exploring its importance, how it works, and how it influences Java programming.
Why Modularity? The Rationale Behind Project Jigsaw
Before Java 9, Java applications were monolithic, leading to several challenges such as bloated deployments, complex classpath issues, and security concerns due to unrestricted access to APIs. The primary goal of Project Jigsaw was to tackle these problems and others, including:
- Reliable configuration: To prevent ‘ClassNotFoundException’ or ‘NoClassDefFoundError’ during runtime.
- Strong encapsulation: To improve security and maintainability by enforcing access controls at the module level.
- Scalable Java: To allow applications to carry only those parts of the JDK they actually need, resulting in smaller, more efficient deployments.
Understanding Modules
A module in Java is a group of related packages, classes, and interfaces. A module:
- Declares which other modules it requires to function.
- Specifies which of its packages are available for use by other modules (all other packages are encapsulated).
Here’s an example of a module definition (module-info.java):
module com.example.myModule { requires java.base; exports com.example.myModule.publicApi; }
Project Jigsaw and the JDK
Project Jigsaw not only brought modularity to user applications but also restructured the JDK itself into modules. The JDK was divided into several modules, with ‘java.base’ at the root. Each other module declares at least ‘java.base’ as its required module.
Advantages of Modularity
- Improved Performance: Applications need only to load the necessary modules, improving startup time.
- Better Encapsulation: Internal APIs can be hidden from external use, thereby reducing security risks.
- Ease of Maintenance: With modules, applications become easier to understand, test, and maintain.
- Smaller Deployments: The jlink tool allows bundling only necessary modules, resulting in smaller runtime images.
Conclusion
Project Jigsaw represents a monumental shift in the Java ecosystem, bringing the advantages of modularity to the Java platform. By using the Java Platform Module System, developers can write more reliable and scalable Java applications that are easier to maintain and have smaller deployment footprints. However, migrating to JPMS from classpath-based applications may not be trivial and needs to be planned carefully, considering the benefits and the learning curve associated with it.
📚 Further Reading & Related Topics
If you’re exploring Project Jigsaw and the Java Platform Module System (JPMS), these related articles will provide deeper insights:
• Java 9 and the Introduction of the Module System: A New Era of Modularity – Learn how Project Jigsaw brought modularity to Java, enabling better package management, modularization, and enhanced security for large Java applications.
• Mastering Dependency Management with Maven – Explore how JPMS integrates with dependency management tools like Maven to handle modular dependencies, simplifying large-scale Java projects.









Leave a reply to Java 25: Streamlining Modularity with Module Imports – Scalable Human Blog Cancel reply