Course contentsShow
← Java
Lesson 2469 of 2,87047. Java Platform Module System (JPMS)Free lesson

Unnamed Modules and Compatibility

Understand the unnamed module concept for classpath-based code and how it interacts with named modules.

Unnamed Modules and Compatibility

You'll learn how classpath-based "legacy" code interacts with the modular system through unnamed modules.

When Java introduced JPMS in Java 9, millions of existing applications still used the traditional classpath. To maintain backward compatibility, Java automatically treats all classpath code as belonging to a special unnamed module.

What Is the Unnamed Module?

The unnamed module is an implicit, automatic module that contains all code loaded from the classpath (not the module path). It has no module-info.java descriptor and follows these rules:

  • Reads all other modules: The unnamed module can access all exported packages from named modules on the module path
  • Exports nothing to named modules: Named modules cannot read or access the unnamed module
  • Exports everything to itself: All packages in the unnamed module are accessible to other classpath code

Think of it like an open neighborhood (unnamed module) next to gated communities (named modules). The neighborhood residents can visit any community that opens its gates, but community residents cannot visit the neighborhood.

Compatibility in Practice

This design allows you to:

  • Run old classpath-based applications without modification on Java 9+
  • Gradually migrate to modules by moving JARs from classpath to module path one at a time
  • Use third-party libraries that haven't been modularized yet

The unnamed module ensures your existing code continues working while you transition to the module system at your own pace.

One-Way Access

Remember: named modules have strong encapsulation and cannot depend on unnamed modules. This prevents modular code from accidentally depending on non-modular, unencapsulated classpath code, maintaining the integrity of the module graph.

Key Takeaway: The unnamed module represents all classpath code, can read named modules, but cannot be read by named modules—ensuring backward compatibility while preserving modular encapsulation boundaries.