Java 9 - Module System
JPMS (Java Platform Module System) is the major enhancement in Java 9. module is a self-describing collection of code and data
Java 9 modules are one of the biggest change in the structure of java.
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).
How to Write Modular Codelet’s see how modular code is written in reality.
Create Java Modular Project
Create new modular project.
Create Java Modules
Now add one or two modules in this project.
I have added two modules
test. Let’s see their code and project structure.
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).