Java 9 Modules With Examples

Java 9 modules are one of the biggest change in the structure of java. Here I am going to give a brief high level introduction about “Java 9 Module System”.

Java 9 Modules

We will look into following topics about java 9 modules system.

  1. Introduction
  2. Java SE 9: Jigsaw Project
  3. Problems of Current Java System?
  4. Advantages of Java SE 9 Module System
  5. Compare JDK 8 and JDK 9
  6. What is Java 9 Module?
  7. Mother of Java 9 Module System
  8. Compare Java 8 and Java 9 Applications


Oracle corp has postponed Java 9 release from March 2017 to September 2017.

As we know, Java SE 8 came with three big new features (plus few more enhancements and new features).

  1. Lambda Expressions
  2. Stream API
  3. Date API

In the same way, Java SE 9 is coming with three big features (plus few more enhancements and new features):

  1. Java Module System (Jigsaw Project)
  2. Java REPL
  3. Milling Project Coin

In this post, we will discuss Oracle Jigsaw project basics.

Java SE 9: Jigsaw Project

Jigsaw project is going to introduce completely new concept of Java SE 9: Java Module System.

It is very big and prestigious project from Oracle Corp in Java SE 9 release. Initially, they have started this project as part of Java SE 7 Release. However, with huge changes, it’s postponed to Java SE 8 then again postponed. Now it is about to release with Java SE 9 in September 2017.

Main Goals of Jigsaw Project:

    • The Modular JDK

As we know, Current JDK system is too big. So they have decided to divide JDK itself into small modules to get a number of benefits (We will discuss them soon in the coming sections).

    • Modular Source Code

Current source code jar files are too big, especially rt.jar is too big right. So they are going to divide Java Source code into smaller modules.

    • Modular Run-Time Images

The main goal of this Feature is “Restructure the JDK and JRE run-time images to accommodate modules”.

    • Encapsulate Most Internal APIs

The main goal of this feature is “Make most of the JDK’s internal APIs inaccessible by default but leave a few critical, widely-used internal APIs accessible”.

    • Java Platform Module System

The main goal of this Feature is “Allowing the user to create their modules to develop their applications”.

    • jlink: The Java Linker

The main goal of this jlink Tool is “Allowing the user to create executable to their applications”.

If you don’t understand these things clearly, do NOT worry. We will discuss these concepts in-depth with some useful examples in the coming sections and also in my coming posts.

Problems of Current Java System?

In this section, we will discuss “Why we need Java SE 9 Module System” that means the problems of Current Java System.

Java SE 8 or earlier systems have following problems in developing or delivering Java Based applications.

  • As JDK is too big, it is a bit tough to scale down to small devices. Java SE 8 has introduced 3 types of compact profiles to solve this problem: compact1, compact2, and compact3. But it does not solve this problem.
  • JAR files like rt.jar etc are too big to use in small devices and applications.
  • As JDK is too big, our applications or devices are not able to support better Performance.
  • There is no Strong Encapsulation in the current Java System because “public” access modifier is too open. Everyone can access it.
  • As JDK, JRE is too big, it is hard to Test and Maintain applications.
  • As the public is too open, They are not to avoid the accessing of some Internal Non-Critical APIs like sun.*, *.internal.* etc.
  • As User can access Internal APIs too, Security is also big issue.
  • Application is too big.
  • Its a bit tough to support Less Coupling between components.

To solve all these problems, Oracle Corp is going to release Java Module system in Java SE 9 Release.

Advantages of Java SE 9 Module System

Java SE 9 Module System is going to provide the following benefits

  • As Java SE 9 is going to divide JDK, JRE, JARs etc, into smaller modules, we can use whatever modules we want. So it is very easy to scale down the Java Application to Small devices.
  • Ease of Testing and Maintainability.
  • Supports better Performance.
  • As public is not just public, it supports very Strong Encapsulation. (Don’t worry its a big concept. we will explore it with some useful examples soon).
  • We cannot access Internal Non-Critical APIs anymore.
  • Modules can hide unwanted and internal details very safely, we can get better Security.
  • Application is too small because we can use only what ever modules we want.
  • Its easy to support Less Coupling between components.
  • Its easy to support Single Responsibility Principle (SRP).

We will explore all these concepts one by one soon.

Compare JDK 8 and JDK 9

We know what a JDK software contains. After installing JDK 8 software, we can see a couple of directories like bin, jre, lib etc in Java Home folder.

However, Oracle Corp has changed this folder structure a bit differently as shown below.

Compare JDK 8 and JDK 9

JDK 8 Folder Structure:


JDK 9 Folder Structure:


Here JDK 9 does NOT contain JRE. In JDK 9, JRE is separated into a separate distribution folder. JDK 9 software contains a new folder “jmods”. It contains a set of Java 9 Modules as shown below.

In JDK 9, No rt.jar and No tools.jar


As of today, “jmods” contains 95 modules. It may increase in the final release.
“jmods” folder is available at ${JAVA_HOME}/jmods. These are known as JDK Modules.

What is Java 9 Module?

A Module is a self-describing collection of Code, Data, and some Resources. It is a set of related Packages, Types (classes, abstract classes, interfaces etc) with Code & Data and Resources.

Each Module contains only a set of related code and data to support Single Responsibility (Functionality) Principle (SRP).


The main goal of Java 9 Module System is to support Modular Programming in Java.

We will discuss on “What is a Module Descriptor” and “How to develop Java Modules” in my coming posts.

Mother of Java 9 Module System

As of now, Java 9 Module System has 95 modules i
n Early Access JDK. Oracle Corp has separated JDK jars and Java SE Specifications into two set of Modules.

  • All JDK Modules starts with “jdk.*”
  • All Java SE Specifications Modules starts with “java.*”

Java 9 Module System has a “java.base” Module. It’s known as Base Module. It’s an Independent module and does NOT dependent on any other modules. By default, all other Modules dependent on this module.

That’s why “java.base” Module is also known as The Mother of Java 9 Modules.

It’s default module for all JDK Modules and User-Defined Modules.

Compare Java 8 and Java 9 Applications

We have already developed many Java applications using Java 5, 6,7, or 8. We know how a Java 8 or earlier applications looks like and what it contains.

In brief, I have depicted a Java 8 applications in a diagram as shown below:


In a Java 8 or earlier applications, Top level component a Package. It groups a set related to types into a group. It also contains a set of resources.

Java 9 Applications does not have much difference with this. It just introduced a new component called “Module”, which is used to group a set of related Packages into a group. And one more new component that Module Descriptor (“”). That’s it.

Rest of the application is same as earlier versions of applications as shown below.


Like Java 8 applications have Packages as a Top level components, Java 9 applications have Module as Top Level components.

Each Java 9 Module have one and only one Module and one Module Descriptor. Unlike Java 8 Packages, We cannot create multiple modules into a single Module.

In brief I can say a Java 9 Module contains the following main components:

  • One Module
  • Module Name
  • Module Descriptor
  • Set of Packages
  • Set of Types and Resources

Here Resources may be (Module Descriptor) or any other properties or XML.

We have discussed too much theory in this post. I think that is enough to understand the basics of Java 9 Module system. We will start some basic Module development in my coming post. I will discuss some more Theory concepts or Java 9 Module System terminology as and when required.

That’s it all about “Introduction to Java 9 Module System” topic. We will discuss some more Java SE 9 Module System concepts in my coming posts.

Please drop me a comment if you like my post or have any issues/suggestions/type errors.

Thank you for reading my tutorials.

Happy Java SE 9 Learning!

Reference: Project Jigsaw

By admin

Leave a Reply

%d bloggers like this: