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

Reading the Unnamed Module from Automatic Modules

Understanding how automatic modules can access classes from the classpath via the unnamed module.

Reading the Unnamed Module from Automatic Modules

You'll learn: How automatic modules bridge the gap by accessing classpath-based code through the unnamed module.


When you migrate to JPMS incrementally, you'll often have automatic modules (modularized JARs on the module path) coexisting with traditional JARs on the classpath. Here's a crucial capability: automatic modules can read the unnamed module, meaning they can access all classes loaded from the classpath.

How It Works

The unnamed module is where all classpath code lives. It's the compatibility bucket that contains every non-modular JAR and loose class file from your classpath.

Automatic modules are special because they implicitly declare requires on all observable modules, including the unnamed module. This means:

  • If you place a third-party JAR on the module path (making it an automatic module)
  • And you have utility classes or legacy libraries on the classpath (in the unnamed module)
  • The automatic module can freely access those classpath classes

Why This Matters

This design enables smooth migration. You can move one dependency to the module path without immediately modularizing everything it depends on. The automatic module acts as a bridge between the modular world and the classpath world.

Think of it like an embassy: the automatic module operates under modular rules but maintains diplomatic access to the classpath territory (the unnamed module). This bidirectional access wouldn't be possible with explicit modules, which must declare specific requires directives.

The Trade-off

While convenient for migration, this accessibility weakens encapsulation. Your automatic module depends on code that has no module descriptor and no formal boundaries. It's a transitional state, not a destination.

Key Takeaway: Automatic modules implicitly read the unnamed module, allowing them to access all classpath code—a critical feature for incremental migration to JPMS.