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”.
We will look into following topics about java 9 modules system.
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).
In the same way, Java SE 9 is coming with three big features (plus few more enhancements and new features):
In this post, we will discuss Oracle Jigsaw project basics.
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:
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.
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.
To solve all these problems, Oracle Corp is going to release Java Module system in Java SE 9 Release.
Java SE 9 Module System is going to provide the following benefits
We will explore all these concepts one by one soon.
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. 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 NOTE:- 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.
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.
As of now, Java 9 Module System has 95 modules in Early Access JDK. Oracle Corp has separated JDK jars and Java SE Specifications into two set of Modules.
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.
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 (“module-info.java”). 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. NOTE:- 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:
Here Resources may be module-info.java (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
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.
Thank u so much for the post. It is very helping. Another thing I would like to add here that grammatical or typo error hardly matters for people who are here to learn Java 9. This should not be a problem for anyone as long as they are interested in technical things.
- Abha
This article is so descriptive thank you.
- bulent
Awesome.! Great step by step comparison of Java 8 and Java 9 which focus on core differences. Thanks Pankaj
- Rakesh Kumar
“That’s why “java.base” Module is also known as The Mother of Java 9 Modules.” I call it MOM (Mother-of-Modules). Great article, thanks!
- Collin
Excellent post. Thank you.
- Hiten
Rambabu, I don’t mean to be rude, but I struggled to read your article. As a native English speaker, the lack of use of the definite and indefinite article (i…e. “the”, “a” and “an”) made some parts confusing. Your grasp of English is far greater than my grasp of any other language, but using articles (i.e. “the”, “a” and “an”) more will enhance it even more. Many thanks for taking the time to write such useful pieces though.
- John M
awesome post. thanks typo -> Module is also know as
- irfan
Excellent post! Typo -> Spelling of Modules (Mdoules).
- Nitin
Good post. Very Informative. Thanks.
- gaurav
Excellent Job. Very much informative. Awaiting for the other posts.
- Neel