Quick revision
The short answer
All jars on the class path join one unnamed module, so every public type is visible to every other jar, nothing is checked at startup, and when two jars contain the same package they silently merge, with the first matching class on the class path winning. Jars on the module path become named modules, or automatic modules if they have no descriptor, with explicit readability and exports; the module system resolves them at startup, so a missing dependency or a package found in two modules, a split package, stops the application before it runs.
What to remember
In this answer, we saw that jars on the class path all join the unnamed module, where every public type is visible to every jar and nothing is checked until a class is needed. Split packages there are silently merged, and the first class found on the class path wins, which leads to late NoSuchMethodError and similar failures. On the module path, jars become named or automatic modules with explicit readability, resolution runs at startup, missing dependencies are reported immediately, and a package found in two modules is a split package that stops the application before it runs.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
All jars on the class path join one unnamed module, so every public type is visible to every other jar, nothing is checked at startup, and when two jars contain the same package they silently merge, with the first matching class on the class path winning. Jars on the module path become named modules, or automatic modules if they have no descriptor, with explicit readability and exports; the module system resolves them at startup, so a missing dependency or a package found in two modules, a split package, stops the application before it runs.
Why this question is asked
The class path has been with Java since the beginning, and most of us have been bitten by it at least once: a NoSuchMethodError in production because two versions of a library were both present, or a NoClassDefFoundError an hour after startup because a jar was missing. The module path, added in Java 9, was designed to prevent exactly those problems. Interviewers ask this to see whether we understand the two models and especially what happens to split packages in each, because that is where migrations usually get stuck. In this answer, we will recap the class path model, see how shadowing works with an example, look at the module path and its checks at startup, and then compare split packages in both worlds.
1A Quick Recap: How the Class Path Works
The class path is a list of jars and directories. When the JVM needs a class, the application class loader looks through that list in order and loads the first match it finds. There is no notion of which jar a class belongs to or which jar depends on which; everything on the class path is treated as one big pool of classes.
In module system terms, all of that pool lives in a single unnamed module. The unnamed module reads every other module and exports all its packages, and every public type in any jar can be used by any other jar. That is simple and flexible, and it is why the class path still works for almost all existing applications.
2Split Packages on the Class Path: Silent Merging
A split package is a package whose classes come from more than one jar. On the class path this is allowed and invisible. Classes from both jars are loaded into the same package, and if both jars contain the same class, the one from the jar listed first wins. The other copy is never seen. This is called shadowing.
Notice what happened. The application started without any complaint, and the failure appeared only when a code path called the method that exists only in the newer copy. Change the order of the jars, which a build tool can do when dependencies change, and the behaviour changes. This is the classic class path problem: missing or conflicting classes are discovered at first use, sometimes hours after startup and only on rare code paths.
3How the Module Path Works
The module path is also a list of jars and directories, but each jar on it becomes a module with a name. A jar with a module-info.class becomes a named module with exactly the requires and exports its descriptor declares. A jar without one becomes an automatic module, named from its manifest's Automatic-Module-Name or from its file name, which reads every other module and exports all its packages.
At startup, before running any application code, the module system performs resolution: starting from the main module, it finds every required module, checks that each one is present, builds the graph of which module reads which, and checks that every package belongs to exactly one module. Only if all of that succeeds does the application start. This is what the module system calls reliable configuration.
So the module path turns the class path's late surprises into early, explicit failures. A missing jar is reported at startup with the name of the module that needed it, not as a NoClassDefFoundError on some later code path.
4Split Packages on the Module Path: Resolution Fails
On the module path, a package may belong to only one module in a layer. If two modules contain the same package, the module system refuses to start, whether or not the classes inside conflict.
| Question | Class path | Module path |
|---|---|---|
| What does a jar become? | Part of the one unnamed module | A named or automatic module |
| Who can see a public type? | Everyone | Modules that read it, if exported |
| Missing dependency | NoClassDefFoundError at first use | FindException at startup |
| Same package in two jars | Merged; first class found wins | Startup fails: split package |
| Same class in two jars | Shadowed silently, order decides | Startup fails |
| Deep reflection on internals | Allowed within class path code | Only into opened packages |
The exact message differs depending on whether the packages are exported and on the JDK version, but the effect is the same: the configuration is rejected before any code runs. The reason for the strict rule is that a package is the unit of encapsulation and of class loading in the module system; it cannot belong to two modules at once. The fix is to remove the duplicate jar, or, when two different libraries really share a package name, to rename one of them, which is why split packages are the most common blocker when moving an existing application to the module path.
5Mixing Both Paths
An application can use both at the same time, which is common during migration. Named modules on the module path cannot see class path code at all, because the unnamed module has no name to require. Automatic modules, however, read the unnamed module, so they act as a bridge. And there is one more rule worth knowing: if a package exists both in a named module and on the class path, the class path copy is ignored, because the module's package takes precedence. That can make classes seem to disappear when a library is moved from the class path to the module path, which is another reason to look for split packages before starting a migration. jdeps and simple scripts that list the packages in each jar make that check easy.
6Follow-up questions
Why did the module system forbid split packages instead of merging them?
Because a package is the unit of encapsulation and of class loader ownership. If a package could span modules, one module could add classes to another's package and reach its package-private members, defeating encapsulation, and the JVM could not tell which module a class in that package belongs to.
How do you find split packages before moving to the module path?
List the packages in every jar, for example with jar --list or jdeps, and look for packages that appear in more than one jar. Maven Enforcer has rules for banning duplicate classes, which catches the worst cases even on the class path.
Does the module path make startup slower?
Resolution adds a little work at startup, usually small, and the JDK's own modules are pre-resolved and archived. In practice the difference is rarely noticeable compared with framework startup.
7Conclusion
In this answer, we saw that jars on the class path all join the unnamed module, where every public type is visible to every jar and nothing is checked until a class is needed. Split packages there are silently merged, and the first class found on the class path wins, which leads to late NoSuchMethodError and similar failures. On the module path, jars become named or automatic modules with explicit readability, resolution runs at startup, missing dependencies are reported immediately, and a package found in two modules is a split package that stops the application before it runs.
Open with
On the class path, all jars are one big pool, which the module system calls the unnamed module. Every public type in any jar is visible to every other jar, nothing is checked at startup, and the class loader just searches the jars in order and loads the first match.
Then, if they want more
So if two jars contain the same package, they silently merge, and if they contain the same class, the first one on the class path wins and the other is shadowed. That is how we get NoSuchMethodError in production when an old version of a library comes first, and NoClassDefFoundError hours after startup when a jar is missing.
On the module path, each jar becomes a module: a named module if it has a module-info, otherwise an automatic module named from its manifest or file name. Modules declare what they require and export, and at startup the module system resolves the whole graph before running anything.
So a missing module fails immediately with a FindException naming who needed it. And a package that appears in two modules is a split package, which is not allowed: the boot layer fails to start.
That strictness is why split packages are the most common blocker when migrating to the module path, so I would check for them with jdeps or jar listings first.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 9
- 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.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
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 "What is the difference between putting a jar on the class path and on the module path?...": https://scrivio-interview-library.netlify.app/java/modules/88fe793b6c/