Skip to content

Chapter 36 of 37

Java Module System

Build Java 9+ modules with requires, exports, opens, services, and module paths.

38 minutes 10 quick checksBy Subha Prasad
Lesson 36 of 37Course navigation

Lesson content

Read, practise, then check your understanding

A named module has module-info.java, explicit dependencies, and strongly encapsulated packages.

Descriptor

module com.example.orders {
    requires java.sql;
    exports com.example.orders.api;
    opens com.example.orders.model to com.example.framework;
    uses com.example.orders.spi.PaymentProvider;
}

requires reads another module, exports exposes a package’s public types, and opens permits deep reflection. provides ... with ... registers service implementations. Compile and run named modules on the module path. Keep internal packages unexported, avoid cyclic dependencies and split packages, and use automatic modules only as a migration bridge.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement best describes module descriptor?
Which Java term matches this description: The module-info.java declaration defining a named module.
Which statement best describes requires?
Which Java term matches this description: A directive declaring dependence on another module.
Which statement best describes exports?
Which Java term matches this description: A directive making a package accessible to other modules.
Which statement best describes opens?
Which Java term matches this description: A directive permitting deep reflection into a package.
Which statement best describes module path?
Which Java term matches this description: The location from which the module system resolves named modules.

0 of 10 checks passed

Your progress is saved on this device.