Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

Java 9 introduced the module system, and JDK 16 and 17 strongly encapsulated JDK internals so illegal reflective access is denied. Looking back, why was the flat class path a long-term problem, and how should a large organisation decide whether to adopt JPMS modules for its own applications?

The flat class path gave no reliable configuration: missing or duplicate jars were only discovered at run time, split packages were allowed, and every public class was usable by everyone. JPMS gave the JDK itself strong encapsulation, smaller runtimes through jlink and the freedom to change its internals, but application adoption stayed low because frameworks rely on reflection, many libraries ship only as automatic modules, and the gain for a single deployable is modest. A sensible policy modularises shared libraries and platform code where encapsulation pays, uses jlink for runtime images, keeps services on the class path, and enforces boundaries inside applications with build modules, ArchUnit or Spring Modulith.

Why this question is asked

The module system is one of the largest changes Java ever made, and yet most Spring Boot services in 2026 still run on the class path. Senior engineers are expected to understand both facts: why the JDK needed modules, and why applications mostly did not adopt them. Interviewers ask this to see whether we can look back at a platform decision honestly and turn it into a practical policy for a large organisation. In this answer, we will recap the problems of the flat class path, see what JPMS and strong encapsulation gave the JDK, understand why applications lagged, and then set out a policy and the cheaper alternatives for module boundaries.

1Why the Flat Class Path Was a Long-Term Problem

The class path is a flat list of jars and directories. The JVM does not know which jars belong together, which depend on which, or whether anything is missing. It only searches the list in order when a class is needed. This gave three long-term problems.

First, there was no reliable configuration. A missing jar showed up as NoClassDefFoundError when a code path first ran, perhaps days after deployment, and duplicate jars silently shadowed each other depending on order, the familiar JAR hell. Second, split packages were allowed: the same package could be spread across several jars, which made it impossible to say which component owned a package. Third, there was no encapsulation beyond public and private. Any public class in any jar could be used by anyone, so internal classes such as the JDK's sun.misc.Unsafe or a library's impl package became de facto APIs. For the JDK this was a serious problem: thousands of libraries used its internals, so the JDK developers could not change them without breaking the ecosystem.

2What JPMS Gave the JDK

Java 9 introduced the Java Platform Module System, JPMS. A module is a named set of packages with a descriptor, module-info.java, that declares what it requires and what it exports. The JVM checks the module graph at startup, so missing modules and split packages fail immediately instead of later, and only exported packages are accessible to other modules.

Java
// module-info.java of a shared library
module com.acme.payments {
requires java.net.http;
requires transitive com.acme.money; // consumers get it too
exports com.acme.payments.api; // the only package others can use
// com.acme.payments.internal is not exported: inaccessible, even its public classes
opens com.acme.payments.dto to com.fasterxml.jackson.databind; // reflection for Jackson only
}
Class path versus module path
ConcernClass pathModule path
Missing dependencyfound at run time, on first usefound at startup
Duplicate or split packagesallowed, first jar winsrejected at startup
Encapsulationevery public class usableonly exported packages
Reflectionalways allowedonly into opened packages
Runtime imagefull JDKjlink with only needed modules

The JDK itself was split into about 70 modules, which enabled jlink to build runtime images with only the modules an application needs, and gave the JDK a way to hide its internals. That last part came in stages: from Java 9, illegal reflective access to internals only printed a warning; JDK 16 denied it by default (JEP 396); and JDK 17 removed the switch that allowed it globally (JEP 403), leaving only targeted --add-opens and --add-exports options. A few critical internals, such as sun.misc.Unsafe, stayed reachable through the jdk.unsupported module while replacements were built. As a result, the JDK can now change its internals far more freely, which has helped speed up its development.

3Why Applications Adopted It Slowly

For applications, the trade looked different. Frameworks like Spring, Hibernate and Jackson work by reflection: they inspect and instantiate our classes, inject fields and create proxies. Under JPMS, every package they touch must be opened to them, which adds a long list of opens directives and surprises. Many libraries ship only as automatic modules, plain jars given a module name derived from their file name or manifest, which provide no real encapsulation and can change names. Some popular libraries had split packages or depended on internals, and fixing them took years.

And the gain for a single deployable was modest. A Spring Boot service is one team's code packaged as one artifact; most of its encapsulation needs are within the team's control anyway, and startup-time checks are a small benefit compared with the migration effort. Build tools and IDE support also took time to mature. So the module system succeeded where its benefits were biggest, in the JDK and in some libraries, and stayed rare in services.

4A Policy for a Large Organisation

We decide per kind of code, by whether encapsulation pays. Shared libraries and platform code used by many teams benefit most, because their internal packages are exactly what consumers misuse, and a module-info that exports only the API turns a convention into a rule the compiler enforces. We modularise them, or at least give them a stable Automatic-Module-Name in the manifest so they work well on the module path for anyone who uses it.

For runtime images, we use jlink to build curated JDK runtimes with only the needed modules, which works even when the application stays on the class path. For services, we keep the class path, because the friction with reflection-heavy frameworks outweighs the benefit. We revisit the policy at each LTS, as library support for modules keeps improving.

Step throughShould this codebase be a JPMS module?
  1. Shared library or platform code used by many teams?
    YesModularise: export only the APINoContinue
  2. Heavy use of reflection-based frameworks?
    YesStay on the class pathNoContinue
  3. Is a small runtime or strict boundary worth the effort?
    YesConsider modules, measure the costNoStay on the class path
  4. Boundaries inside the servicebuild modules, ArchUnit or Spring Modulith

4 steps in order. Play them, or step through them one at a time.

5Cheaper Ways to Get Module Boundaries

Most of the value people want from modules inside an application is boundaries: the billing code must not reach into the inventory code's internals. We can get that without JPMS. Splitting the codebase into build modules, separate Maven modules or Gradle subprojects, makes dependencies explicit and compile-checked. ArchUnit tests express rules such as no class in ..billing.. may depend on ..inventory.internal.. and fail the build when someone breaks them. Spring Modulith treats each top-level package of a Spring Boot application as an application module, verifies that modules only use each other's public API, and documents the structure.

These tools give most of the benefit at a fraction of the cost, and they work with the frameworks rather than against them. For many organisations, that is where the real return on the idea of modularity lies.

Java
// ArchUnit rule, run as a normal unit test
@ArchTest
static final ArchRule billingRespectsInventory =
noClasses().that().resideInAPackage("..billing..")
.should().dependOnClassesThat().resideInAPackage("..inventory.internal..");
// a violation fails the build with the offending class and dependency

6Follow-up questions

Which risks come from libraries that still depend on JDK internals such as sun.misc.Unsafe?

They can break on a JDK upgrade. Unsafe's memory-access methods were deprecated for removal in JDK 23 and print warnings by default since JDK 24, with the plan to remove them later, so libraries still using them must move to VarHandle or the Foreign Function and Memory API. Other internals are already strongly encapsulated, so such libraries need --add-opens flags, which tie us to an internal detail that can change in any release and widen what code can reach. We find these dependencies with jdeps --jdk-internals before each upgrade and push for upgrades or replacements.

Was JPMS a mistake, given low application adoption?

No. Its main goal was to modularise and secure the JDK itself, and it achieved that: strong encapsulation, jlink and the faster evolution of the JDK depend on it. Low adoption in applications reflects the cost of the migration for reflection-heavy frameworks, not a failure of the design for the platform.

Should a new greenfield library start as a module?

Usually yes, if it is meant to be shared. Adding a module-info from the start is cheap, it forces a clear API, and the library still works on the class path for consumers who do not use modules.

7Conclusion

In this answer, we saw that the flat class path offered no reliable configuration, allowed split packages and gave no encapsulation, which blocked the JDK from changing its internals. JPMS and strong encapsulation fixed that for the JDK and enabled jlink, while applications adopted modules slowly because of reflection-heavy frameworks, automatic modules and modest gains. The policy we chose modularises shared libraries, uses jlink, keeps services on the class path and enforces boundaries with build modules, ArchUnit or Spring Modulith.

What to say in the interviewAbout 90 seconds aloud

Open with

The flat class path had three structural problems. There was no reliable configuration: a missing jar showed up only when a code path first ran, and duplicate jars silently shadowed each other by order.

Then, if they want more

Split packages were allowed, so nobody clearly owned a package. And there was no encapsulation beyond public, so internals like sun.misc.Unsafe became APIs that the JDK could not change without breaking thousands of libraries.

JPMS fixed that for the JDK: modules declare what they require and export, the graph is checked at startup, the JDK became around 70 modules so jlink can build small runtimes, and after warnings from Java 9, JDK 16 denied illegal reflective access by default and JDK 17 removed the global switch.

Applications adopted it slowly because Spring, Hibernate and Jackson rely on reflection, which needs opens everywhere, many libraries are only automatic modules, and for a single Spring Boot deployable the gain is modest.

So my policy would be: modularise shared libraries and platform code, where exporting only the API really stops misuse; use jlink for curated runtime images; keep services on the class path; and get internal boundaries in services with build modules, ArchUnit rules or Spring Modulith, which give most of the benefit at much lower cost.

I would also run jdeps before upgrades to catch libraries still using internals like Unsafe.

About this answer

Last updated
12 November 2026
Versions it names
Java 9, Java 16, Java 17, Java 23
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Java 9 introduced the module system, and JDK 16 and 17 strongly encapsulated JDK...": https://scrivio-interview-library.netlify.app/java/class-loading/2c46590500/