DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Java 27 Makes G1 the Default Everywhere: How to Test Your Small Containers Before You Upgrade
  • Stop Writing Database Migration Scripts: Declarative Schema Sync for Java
  • Searching Kafka Without an Index: Lessons From Building Message Search for Kafdrop
  • ScyllaDB in Enterprise Java: High-Performance NoSQL With Eclipse JNoSQL

Trending

  • From Issue to Reviewable Patch: Build a Sandboxed Coding Agent With Deep Agents and Automated Tests
  • AI Agents Need an Identity Plane: Rethinking Enterprise Authorization for Autonomous Software
  • Guess the Speed: Building a Family Internet Speed Guessing Game
  • Beyond the Wall of Charts: How Advanced Observability Displaced the Telemetry Dashboard

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Java
  4. Java 9 Modular Development (Part 1)

Java 9 Modular Development (Part 1)

Get a glimpse of how to put Java 9's modularity to work, including overviews of module types and module descriptors as well as best practices and advice.

By 
Gowtham Girithar Srirangasamy
·
Jul. 05, 17 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
46.9K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Modularity is a way of writing and implementing a program as a number of unique modules. It avoids monolithic design, and it helps in reducing a system's complexity, minimizing coupling, and a few other features.

Java 9 modularity has been a big project of around 5 years of work that will change a lot of what we do today.

Why Do We Need Modularity?

  1. To avoid small devices running the full JDK unnecessarily. Java 9 solved this by having the Jlink tool with the modularity concept.

  2. Even in larger machines, space is important, so we should use it effectively.

  3. To remove the flaws in encapsulation. In Java 9, Public is no longer visible unless it is exported in module-info.java. It checks dependencies β€” both the compile time and runtime. Even with reflection, we cannot access when it is not exported.

  4. To make our implementation hidden and expose it through interface. So, we can hide the implementation.

  5. Improve security and maintainability. To keep internal APIs from using it. Today, we see untrusted code using work, eg : sun.* , *.internal.*

  6. To improve performance.

Note: Change from class-path to module-path

Java 9 Modules

A module is nothing but a module-info.java file that is called as a module descriptor. It describes our module, hence it is called the module descriptor. The name of the module should be unique.

It explains:

  1. Which other modules our module depends on.

  2. Which packages are to be exported to be used by other modules

Module Types

There are different types of modules, listed below with their descriptions:

  • Application modules: The modules that we create to achieve functionality. All third-party dependencies will fall into this category.

  • Automated modules: JARs placed in the module path without the module descriptor are called automated modules. They implicitly export all the packages and read all other modules. The main purpose of these modules is to use pre-Java 9 build JARs. It removes the file extension and the trailing version number and also replaces all the non-alphanumeric characters with dots to define the module name. Example: mysql-connector-java-6.1.6.jar to mysql.connector.java

  • Unnamed modules: All the JARs and classes on the class path will be in unnamed modules (the class path is not completely removed ). It does not have any name and so it can read and export all the modules.

  • Platform modules: The JDK itself has been migrated into a modular structure. Those modules are called platform modules. Example: java.se , java.xml.ws

Image title











Java.base is the module every module is dependent on it.

Module Descriptors

Java modules have module descriptors, i.e module-info.java, which defines the rules for exporting packages and reading the modules. By default, every module can read the java.base module. It's recommended that module names use a reverse-domain pattern.

Detailed explanations of module descriptors are below:

  • requires <module>

The requires command in the module descriptor is used to define modules in which this module is dependent on.

  • requires transitive <module>

The transitive keyword says, "Whatever I have will be given to a module that asks me."

  • requires static <module>

The static keyword is used to say, "This dependency check is mandatory at compile time and optional at runtime."

  • exports <package-name>

The module exports the package to other modules. If the package is not exported, other modules cannot use this package.

  • exports <package-name> to <module-name>

This export is called a qualified export. It is exporting the package to a specific module and not all the modules.

  • opens <package-name>

Opens is used to access this package through Reflection in runtime, to access the public type at compile time, and the private type at the runtime.

  • opens <package> to <module>

This is a qualified open and is used to access this package through Reflection in runtime by only the specified module.

  • Uses and Provides:

Uses <service-interface>: The interface is in this module and implementation can be in this module or some other module.

Provides <service-interface> with <class1>,<class2>: The implementation is mentioned for the interface.

Important Points

  1. The module can also be open.

  2. We cannot use the open statement inside the open module.

  3. We cannot add the version to the module in module-info.java, but we can do it while building the JAR, which is added to the module info.

ExampleImage title

Package Structure

The sample project structure is given below for the module-based project.

Image title

Part 2 will describe in depth how to package modules as JARs, jmod, and jlink.

Java (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Java 27 Makes G1 the Default Everywhere: How to Test Your Small Containers Before You Upgrade
  • Stop Writing Database Migration Scripts: Declarative Schema Sync for Java
  • Searching Kafka Without an Index: Lessons From Building Message Search for Kafdrop
  • ScyllaDB in Enterprise Java: High-Performance NoSQL With Eclipse JNoSQL

Partner Resources

Γ—

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • πŸ”₯ Jadwal & Hasil: articles/java modularity jigsaw - Info Live Streaming 2026
  • πŸ”₯ Jadwal & Hasil: articles/java modularity jigsaw - Info Live Streaming 2026
  • πŸ”₯ Jadwal & Hasil: articles/java modularity jigsaw - Info Live Streaming 2026

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • πŸ”₯ Jadwal & Hasil: articles/java modularity jigsaw - Info Live Streaming 2026
  • πŸ”₯ Jadwal & Hasil: articles/java modularity jigsaw - Info Live Streaming 2026
  • πŸ”₯ Jadwal & Hasil: articles/java modularity jigsaw - Info Live Streaming 2026