JPMS: Java Platform Module System


JPMS stands for Java Platform Module System. It is the new feature in Java 9. Our java applications and Java packages may be packaged into Java Modules with the aid of Java Module System. The Java Module allows us to designate which of the module’s packages and other Java Modules should be able to see. A Java Module also lists the Java Modules it needs in order to function.

The Java Platform System is also known as Java Jigsaw or Project Jigsaw. Jigsaw's name was used at the time of its development. The main intention of developing this is to make the JRE more modular. JPMS addresses a few major problems namely Classpath/JAR Hell, Massive Monolithic JDK, Version conflicts, security issues.

Now, let’s dive more into the Java Platform Modular System to know more about them.

Why does Java need Modules?

It is important to remember that JPMS is a SE (Standard Edition) feature and affects Java at every level. Despite this, the patch is intended to enable most programs to run without modification while switching from Java 8 to Java 9. Its main purpose is to enable the gatherings of related packages that are visible to the module while concealing some components from the module’s external consumers.

JPMS was launched with the following stated goals −

  • Easy to organize large applications and libraries.

  • Improves the security

  • Improves the app performance

  • Manage the platform’s breakdown for small devices.

  • Improves the structure.

Class path VS Module path

The class path has up until now been the main determinant of what is accessible to a program when executed in Java. Despite serving this role and being clearly known, the class path ultimately becomes a large, undifferentiated bucket into which all dependencies are inserted.

A level is added above the class path by the module path. It acts as a storage space for packages and chooses which ones are accessible to the application.

CLASS PATH

MODULE PATH

Applicable to all Java versions

Only applicable to the version Java 9 and above

Does not require module-info.java

Does require module-info.java

Adding Libraries work only if project does not have module-info.java

Libraries can work without module-info.java

Only add non-modularized libraries

Both modularized and non-modularized can be added

Encapsulation and Abstraction is weak

Encapsulation and Abstraction is strong

Modularity is weak

Modularity is strong

It is not possible to add part of the library to project by adding it in classpath

We can only add required part of the library to project by adding it in modulepath

Modules in JAVA

The JDK is composed of modules. If you are working with JDK on your system, then you also have the source. If you are unaware of that and then look into this to know more about it.

Inside the JDK install directory is a /lib directory. Inside that directory you will find a src.zip file. Then unzip that into a /src directory. After this look into /src directory and find the /java.base directory then you will find the module-info.java file and at last open it up.

After the Javadoc comments at the top, you’ll find a folder named module section.base followed by the exports line. The format is a bit esoteric, so we won’t get too into it.

As you can see, the java.base module exports several of the well-known Java Packages, including java.io. This is how a module that collects packages functions.

The requirement for instruction is the opposite of exporting. As a result, a module may be necessary for the module that is being specified. You specify the module path the same as the way you supply the class path while running the Java compiler against modules. This makes it possible to address the dependencies.

Backward Compatibility

Java 9 was created with backward compatibility in mind. The new module structure is such a significant shift, though, that you could encounter problems particularly in large codebases.

The following command might be useful for problems that originate from your code base − when the command jdeps is directed at a class, it will look for any dependents and the modules that need dependencies.

You can hope that the package you depend on has an updated version of Java 9 compliant to build if your dependencies cause issues. If not, you might need to look for options.

COMMON ERROR

How to resolve java.lang.NoClassDefFoundError −

Javax/xml/bind/JAXBException

This is the code complaining that the assigned class is not found, because it has migrated to the module without visibility to the consuming code. There are several solutions for this.

JPMS is a rather significant shift, thus adoption will take some time. Fortunately, since Java 8 is a long-term support version, there is no pressing need.

Nevertheless, in the long-term, it will be necessary for older projects to migrate, and new projects must use modules wisely in order to, perhaps, acquire some of the benefits that have been given.

Conclusion

JPMS stands for Java Platform Module System, which is also known as project jigsaw in its initial stage of development. It makes it easier for developers to organize large applications and libraries. It improves the structure and increases the level of security of the platform. It is also used to improve application performance and it is useful for the decomposition of the platform for smaller devices. The main idea behind this is to enable the collection of related packages that are visible to the module, while hiding the elements from external consumers on the module.

Updated on: 01-Aug-2023

87 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements