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

The Readability Graph

Understand how requires directives build a module graph and how the JVM resolves module dependencies at startup.

The Readability Graph

You'll learn how requires directives create a directed graph of module relationships that the JVM uses to resolve dependencies at startup.

What Is the Readability Graph?

When you declare requires directives in module-info.java, you're not just listing dependencies—you're building a directed graph where each module is a node and each requires creates an edge. This is the readability graph, and the JVM constructs it at startup to determine which modules can "read" (access) which other modules.

Think of it like a network of trust relationships: if Module A requires Module B, then A can read B's exported packages. The graph must be acyclic (no circular dependencies) and complete (all dependencies resolved) for the application to start.

How the JVM Resolves the Graph

At startup, the JVM:

  1. Starts with your root module (the one containing main)
  2. Recursively resolves all requires directives, adding modules to the graph
  3. Follows requires transitive edges to include indirect dependencies
  4. Validates that all required modules exist and are accessible
  5. Checks that no cycles exist
  6. Enforces strong encapsulation based on exports declarations

If any module is missing or a cycle is detected, startup fails with a ResolutionException.

Why This Matters

The readability graph isn't just theoretical—it's the foundation of module security and encapsulation. A module can only access types from modules it reads (directly or transitively). The graph is computed once at startup, making dependency resolution predictable and fast.

Unlike classpath's flat structure where everything could see everything, the readability graph enforces explicit, verifiable relationships.

Key Takeaway:
The readability graph is a directed, acyclic graph built from requires directives that the JVM constructs at startup to enforce module encapsulation and resolve dependencies.