0Pricing
Java Academy · Lesson

requires and exports

Control dependencies and visibility.

Controlling the Module Graph

Two directives shape the module graph: requires declares what you depend on, and exports declares what you reveal.

This lesson explores their variants and the readability/accessibility rules they create.

Plain requires

A simple requires X; means "this module reads module X." Your code can use X's exported public types, but consumers of your module learn nothing about X.

module com.example.app {
    requires java.sql;
}

All lessons in this course

  1. module-info.java
  2. requires and exports
  3. Services with provides/uses
  4. Migrating to Modules
← Back to Java Academy