☕ Java Advanced

What are Java 9 modules (JPMS)?

Why Interviewers Ask This

This is a differentiating question used for senior and lead roles. Interviewers want to see if you can explain not just what happens, but why — and what the trade-offs are in different approaches.

Answer

The Java Platform Module System (JPMS), introduced in Java 9 (Project Jigsaw), allows you to organize code into modules — named, self-describing groups of packages with explicit declarations of what they export and what they require. Each module has a module-info.java file: module com.example.myapp { requires java.sql; exports com.example.myapp.api; }. Benefits: strong encapsulation (internal packages cannot be accessed by default, unlike jars), explicit dependencies (the JVM verifies that all required modules are present at startup), and smaller JREs (you can create minimal custom runtimes with only the needed modules using jlink). The JDK itself was modularized — java.base is the foundational module all others implicitly depend on.

Pro Tip

This topic has Java-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.