3 Defining modules and their properties


This chapter covers

  • What modules are, and how module declarations define them
  • Discerning different types of modules
  • Module readability and accessibility
  • Understanding the module path
  • Building module graphs with module resolution

We’ve talked a lot about modules already. They’re the core building blocks not only of modular applications, but also of a true comprehension of the module system. As such, it’s important to build a deeper understanding of what they are and how their properties shape a program’s behavior.

Of the three essential steps of defining, building, and running modules, this chapter explores the first (for the other two, see chapters 4 and 5). This chapter explains in detail what a module is and how a module’s declaration defines its name, dependencies, and API (section 3.1). Some examples from the JDK give you a first look at the module landscape we’re going to explore from Java 9 on and categorize the kinds of modules to help you navigate.

We also discuss how the module system—and, by extension, the compiler and runtime—interact with modules (sections 3.2 and 3.3). Last but not least, we examine the module path and how the module system resolves dependencies and builds a graph from them (section 3.4).

3.1 Modules: The building blocks of modular applications

3.1.1 Java modules (JMODs), shipped with the JDK

3.1.2 Modular JARs: Home-grown modules

3.1.3 Module declarations: Defining a module’s properties

3.1.4 The many types of modules

3.2 Readability: Connecting the pieces

3.2.1 Achieving reliable configuration

3.2.2 Experimenting with unreliable configurations

3.3 Accessibility: Defining public APIs

3.3.1 Achieving strong encapsulation

3.3.2 Encapsulating transitive dependencies

3.3.3 Encapsulation skirmishes

3.4 The module path: Letting Java know about modules

3.4.1 Module resolution: Analyzing and verifying an application’s structure

3.4.2 Module graph: Representation of an application’s structure

3.4.3 Adding modules to the graph

3.4.4 Adding edges to the graph

3.4.5 Accessibility is an ongoing effort