Introduction to JPMS and the Module System
You'll learn why Java 9 introduced modules and how they fundamentally improve code organization.
The Problem Before Modules
Before Java 9, Java applications were essentially giant buckets of classes thrown together via the classpath. Imagine building a house where every room's contents are visible to every other room—no walls, no doors, no privacy. This led to three major problems:
- Weak encapsulation: Even with
privateand package-private access, internal implementation classes could be accessed if someone knew the fully-qualified name. - JAR hell: Conflicting library versions on the classpath caused runtime failures that were difficult to diagnose.
- Monolithic JDK: The entire Java runtime library loaded regardless of what you actually needed, making Java too heavyweight for modern applications.
What JPMS Brings
The Java Platform Module System (JPMS) introduces modules—named, self-describing collections of packages. Think of modules as contracts that explicitly declare:
- What they export (which packages are public API)
- What they require (dependencies on other modules)
- What they encapsulate (implementation details hidden even from reflection)
This is like adding proper walls and doors to your house—each room (module) controls exactly what's visible to others.
Key Benefits
Stronger encapsulation: Internal packages remain truly internal. Framework code can't accidentally break into your implementation details.
Reliable configuration: Missing dependencies are detected at compile-time and startup, not randomly at runtime.
Scalability: Applications can ship with only the JDK modules they need, reducing footprint dramatically.
Key Takeaway: JPMS transforms Java from a classpath-based "everything is accessible" model to a module-based system with explicit, enforceable boundaries that improve security, maintainability, and application size.