Introduction to the Java Module System

Introduction to the Java Module System

Starting with the modular JDK, you'll see modules are all about strong encapsulation and explicit dependencies. Then it's time to write your own modules, with services to decouple modules.

After the mechanics of creating modules, the first part closes with modularity patterns. They are essential to create truly modular applications.

Migration

Migration

We all have existing code. Even though the module system is opt-in, there are many changes affecting classpath-based applications as well.

In the second part we explain how you can migrate to Java 9, and then modularize your application. It also features a case study migrating a Spring and Hibernate application to modules.

Modular Development Tooling

Modular Development Tooling

The last part focuses on tools and processes for modular development, such as Maven. Also, testing modules brings new challenges.

Another exciting tool is jlink. With jlink, you can create small custom runtime images, bundling only the required application modules and JDK modules in a single low-footprint distribution.

All code examples are available on GitHub so you can easily try them yourself. Star

Foreword by Alex Buckley
  1. Modularity Matters
  2. Modules and the Modular JDK
  3. Working with Modules
  4. Services
  5. Modularity Patterns
  6. Advanced Modularity Patterns
  7. Migration Without Modules
  8. Migration to Modules
  9. Migration Case Study: Spring and Hibernate
  10. Library Migration
  11. Build Tools and IDEs
  12. Testing Modules
  13. Scaling Down with Custom Runtime Images
  14. A Modular Future
Book

The art of structuring large codebases is an undervalued one. This is neither a new problem, nor is it specific to Java. However, Java is one of the mainstream languages in which very large applications are built all the time—often making heavy use of many libraries from the Java ecosystem. Under these circumstances, systems can outgrow our capacity for understanding and efficient development. A lack of structure is dearly paid for in the long run, experience shows.

Modularity is one of the techniques you can employ to manage and reduce this complexity. Java 9 introduces a new module system that makes modularization easier and more accessible. It builds on top of abstractions Java already has for modular development. In a sense, it promotes existing best practices on large-scale Java development to be part of the Java language.

The Java module system will have a profound impact on Java development. It represents a fundamental shift to modularity as a first-class citizen for the whole Java platform. Modularization is addressed from the ground up, with changes to the language, Java Virtual Machine (JVM), and standard libraries.

Now is the time to read up on modules. JDK 9 itself is modularized (shown right) so you will encounter modules right from the start. See how they can improve the structure and integrity of your applications.

— Introduction of Java 9 Modularity
(Excerpt from Chapter 1)

Subset of JDK 9 module graph







Sander Mak

Sander Mak

Sander is a Fellow at Luminis in The Netherlands. At Luminis, he crafts modular and scalable software, most often on the JVM but with a touch of TypeScript where needed. He is author of the O'Reilly book 'Java 9 Modularity' and an avid conference speaker.

Sander loves sharing knowledge, through his blog at http://branchandbound.net, and also as Pluralsight instructor.


Author

Paul Bakker

Paul is a senior software engineer with Netflix in the Edge Developer Experience team, where he primarily works on tools to increase developer productivity within the company. Besides his love for writing code, he has a passion for sharing knowledge.

This is his second book after co-authoring "Modular Cloud Apps with OSGi" which was published by O'Reilly in 2013. Paul is also frequently speaking at conferences about modularity, container technology and many other topics. He blogs at http://paulbakker.io.

Below you'll find a number of options to get Java 9 Modularity. Consider leaving a review after reading (for example, on Goodreads or Amazon), it is much appreciated!

Read Online


O'Reilly Safari offers the largest selection of IT books on a subscription basis. You can read Java 9 Modularity with a Safari subscription.

Read on Safari

No subscription? Start a trial!


eBook


Available in all popular formats. Note that only the ebooks.com PDF has the original O'Reilly print typesetting.

Print


Still the best way to read a book!


Pluralsight Course: Java 9 Modularity

This two hour video course gives you insight into the Java module system using practical examples. You'll learn how to create and use modules and how to migrate your applications to Java 9.

Watch (free trial available)

Pluralsight Course: What's New in Java 9

This 3,5 hour video course shows all important new features of Java 9 in a hands-on manner. Topics range from JShell to Stream/Optional API enhancements, new APIs like HttpClient and ProcessHandle, performance and security improvements in Java 9 and much more.

Watch (free trial available)