Class Loading Differences: Modules vs Classpath
You'll learn how the JVM's class loading model changes when using modules compared to the traditional classpath.
The Traditional Classpath Model
On the classpath, class loading follows the classic parent-delegation model: when a class is needed, the request goes up the hierarchy (Bootstrap → Platform → Application class loader), and the first loader that finds the class loads it. All classes on the classpath are visible to the application class loader, creating a flat namespace where package conflicts can occur.
The Module Path Model
With JPMS, class loading becomes module-aware. The JVM now understands module boundaries:
- Each module has its own internal class loader that respects the module's
exportsandrequiresdirectives - A class in module A can only access classes in module B if:
- Module A
requiresmodule B - Module B
exportsthe package containing the class
- Module A
- Strong encapsulation is enforced at load time—non-exported packages remain invisible even via reflection (unless
opensis used) - The readability graph determines class visibility, not just presence on the path
Key Differences
Classpath: "Can I find this class file anywhere?" → Load it
Module path: "Does my module declare it needs this? Is it exported to me?" → Load it if authorized
The parent-delegation model still exists, but now includes module graph validation. If you request a class that violates module boundaries, you'll get a compile-time or runtime error, not silent class loading.
When mixing both (--module-path and --classpath), classpath code lives in the unnamed module, which can read all named modules but cannot be read by them—a compatibility bridge.
Key Takeaway:
Module-path class loading adds layer of access control on top of parent delegation, enforcing strong encapsulation through exports/requires rather than relying solely on class visibility.