Your Privacy

This site uses cookies to enhance your browsing experience and deliver personalized content. By continuing to use this site, you consent to our use of cookies.
COOKIE POLICY

Skip to main content

Java 9 | When to Use Modules

Java 9 | When to Use Modules
Back to insights

The release of Java 9 added strong encapsulation to the module system. This seemingly small addition has major implications for improving software development efforts – the module system offers additional support for SOLID development.

When to Use Java Modules

There are a couple of reasons why it makes sense to choose modules during development. Many Java development houses select Spring or Spring Boot just to satisfy the “D” in SOLID development. If a Java project only requires Dependency Injection, Java 9 can do this without any additional frameworks. Spring, and occasionally Spring Boot, require configuration files to map Java class implementation to interfaces. Creating these configuration files can be tedious. Modules do not require the same configuration files, which saves development time and, therefore, money. Modules also support the “S” in SOLID development. Software developers can decompose a monolithic Java application into many single-purpose modules. Properly architected applications using SOLID principles and modules can yield applications that are easier to maintain than if the application were a monolith, which again saves money.

Code Example

If you’d like to get started with an example implementation, download the code located on Github here. Edit the build script variables as necessary to match your file system and then run it. The output of the main class will display. Notice that the main class only imports interfaces Coffee and CoffeeService to achieve its goal. Further inspection shows that interfaces are encapsulated inside of their own modules, com.example.coffee and com.example.coffeeservice. Implementation files are in different modules, com.example.coffee.impl and com.example.coffeeservice.impl.

Modularization requires a module-info.java file for each module. Compare the module-info.java files inside of com.example.coffee and com.example.coffee.impl for guidance on the visibility keywords required for separating interfaces from implementation.

It is important to point out the ServiceLoader class in the main class. The ServiceLoader is the class responsible for resolving the implementation files. Given an interface, the ServiceLoader can return an Iterable containing the files that implement the interface. The desired implementation is selected from the Iterable.

Conclusion

It makes sense to select Java modules over Spring or Spring Boot if you just need a lightweight system for SOLID development. UDig has a crew of excellent Java developers that are skilled in everything from Spring Boot to Adobe Experience Manager and can be a great resource for your next Java project.

About Cody Halbleib

Cody Halbleib is a Senior Consultant on the Software team. His family is his partner, Jamie, and his Border Collie mix, Walter.

Digging In

  • Digital Products

    Inside Config 2025: What’s New in Figma

    Config 2025 kicked off with a bang on Day 1. Figma’s annual conference brings together designers, developers, and all those involved in the making of a product. The 2-day event has a stacked lineup of accomplished speakers ready to share their insights on the world of product building. At today’s opening keynote, the Figma team, […]

  • Digital Products

    Choosing the Right Modernization Approach

    When organizations decide it’s time to modernize their technology infrastructure, choosing the right approach is crucial. Modernization isn’t merely a technical upgrade; it’s a strategic business move that significantly impacts growth, agility, and long-term success. Here’s how your company can effectively begin to select the best modernization strategy tailored to your goals and challenges. In […]

  • Digital Products

    TAG Panel: Differentiate Your Customer Experience

    Join the CX and Product Management Societies to hear from our panel of Human-Centered Design experts on the business value of Agentic AI.

  • Digital Products

    The Bloated SaaS Era: Paying More for Less While Businesses Wait

    SaaS was supposed to make business faster, smarter, and more efficient. Instead, it’s become bloated, expensive, and painfully slow to change. The platforms we rely on—Salesforce, Workday, SAP, and others—haven’t truly innovated in years. Yet, they demand massive investments in re-implementation, process re-engineering, and data migration just to keep up. It’s time to ask: Are […]

  • Digital Products

    Reid Braswell Joins UDig as Vice President, Software Engineering

    UDig is proud to welcome Reid Braswell as our new Vice President of Software Engineering. With over 13 years of experience in technology consulting, Reid brings deep expertise in digital transformation, modern software engineering, and client-focused solutions. His leadership and passion for solving complex challenges make him an exceptional addition to the UDig team. Reid’s […]

  • Digital Products

    Energy 2025 – Expansion of Fossil Fuels or Carbon Reduction?

    Now that the election is behind us, we have an opportunity to anticipate the possible effects on the energy industry under this new administration. What strategies will be impacted? What will remain the same? What opportunities can we take advantage of in 2025? This blog is meant to dig into these questions and provide some […]