JPMS: Java Platform Module System
JPMS stands for Java Platform Module System. This is a new feature in Java 9. Our java applications and Java packages can be packaged into Java modules with the help of the Java module system. Java modules allow us to specify which packages of the module and other Java modules should be able to see it. Java module also lists the Java modules required for it to run.
Java Platform System is also known as Java Jigsaw or Project Jigsaw. The name Jigsaw was used at the time of its development. The main purpose of developing this is to make the JRE more modular. JPMS solves several major problems, namely Classpath/JAR Hell, large-scale single JDK, version conflicts, and security issues.
Now, let’s delve deeper into the Java platform modular systems to learn more about them.
Why does Java need modules?
It is important to remember that JPMS is an SE (Standard Edition) feature and affects all levels of Java. Nonetheless, the purpose of this patch is to enable most programs to run without modification when switching from Java 8 to Java 9. Its main purpose is to collect relevant packages visible to the module while hiding some components from external users of the module.
JPMS was launched with the following stated objectives -
Easily organize large applications and libraries.
Improve security
Improve application performance
Platform failure for managing small devices.
Improve structure.
Class path VS module path
To date, the classpath has been the primary determinant of what a program can access when executing in Java. Despite playing this role and being clearly understood, the classpath ends up becoming one big, undifferentiated bucket into which all dependencies are plugged.
The module path adds one level above the classpath. It acts as a storage space for packages and selects which packages an application can access.
Classpath |
Module path |
---|---|
Applies to all Java versions |
Only applicable to Java 9 and above |
No need module-info.java |
Do you need module-info.java |
Adding the library is only effective if the project does not have module-info.java |
The library can work without module-info.java |
Add non-modular libraries only |
Both modular and non-modular can be added |
Weak encapsulation and abstraction |
Strong encapsulation and abstraction |
Weak modularity |
Very modular |
Cannot add a library to a project by adding part of it to the classpath |
We can only add the required parts of the library to the project by adding it to the module path |
Modules in JAVA
JDK is composed of modules. If you are using the JDK on your system, you also have the source code. If you didn't know this, check this out to learn more.
There is a /lib directory in the JDK installation directory. In this directory you will find a src.zip file. Then extract it into the /src directory. After that look in /src directory and find /java.base directory then you will find module-info.java file and finally open it.
After the Javadoc comments at the top, you will find a folder called modulesection.base, followed by the export line. The format is a bit esoteric, so we won’t get too deep into it.
As you can see, the java.base module exports several well-known Java packages, including java.io. This is how the module that collects packages works.
directive are opposite to those of export. Therefore, the specified module may require a module. Specify the module path in the same way you provide the classpath when running the Java compiler against the module. This makes it possible to resolve dependencies.
Backwards Compatibility
Java 9 was created with backward compatibility in mind. However, the new module structure is a major shift and you may run into issues, especially in large codebases.
The following command may be useful in troubleshooting issues originating from the codebase - when the command jdeps points to a class, it will look for any dependencies and the modules that require the dependencies.
If your dependencies are causing problems, you may wish to build with a newer version of the package you depend on that is compatible with Java 9. If not, you may want to look for options.
Common mistakes
How to solve java.lang.NoClassDefFoundError -
Javax/xml/bind/JAXBException
This is the code complaining that the assigned class cannot be found because it has been migrated to a module and is not visible to the consuming code. There are several solutions.
JPMS is a pretty significant transition, so adoption will take some time. Fortunately, since Java 8 is a long-term support release, there is no immediate need.
However, in the long run, it will be necessary for old projects to be migrated, and for new projects to use modules wisely, in order to perhaps gain some of the benefits already given.
in conclusion
JPMS stands for Java Platform Module System and was also called project jigsaw in the early stages of development. It makes it easier for developers to organize large applications and libraries. It improves the structure and increases the security level of the platform. It is also used to improve application performance and is useful for platform decomposition for smaller devices. The main idea behind this is to enable a collection of related packages visible to the module, while hiding elements from external consumers on the module.
The above is the detailed content of JPMS: Java Platform Module System. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Use classes in the java.time package to replace the old Date and Calendar classes; 2. Get the current date and time through LocalDate, LocalDateTime and LocalTime; 3. Create a specific date and time using the of() method; 4. Use the plus/minus method to immutably increase and decrease the time; 5. Use ZonedDateTime and ZoneId to process the time zone; 6. Format and parse date strings through DateTimeFormatter; 7. Use Instant to be compatible with the old date types when necessary; date processing in modern Java should give priority to using java.timeAPI, which provides clear, immutable and linear

To correctly handle JDBC transactions, you must first turn off the automatic commit mode, then perform multiple operations, and finally commit or rollback according to the results; 1. Call conn.setAutoCommit(false) to start the transaction; 2. Execute multiple SQL operations, such as INSERT and UPDATE; 3. Call conn.commit() if all operations are successful, and call conn.rollback() if an exception occurs to ensure data consistency; at the same time, try-with-resources should be used to manage resources, properly handle exceptions and close connections to avoid connection leakage; in addition, it is recommended to use connection pools and set save points to achieve partial rollback, and keep transactions as short as possible to improve performance.

DependencyInjection(DI)isadesignpatternwhereobjectsreceivedependenciesexternally,promotingloosecouplingandeasiertestingthroughconstructor,setter,orfieldinjection.2.SpringFrameworkusesannotationslike@Component,@Service,and@AutowiredwithJava-basedconfi

Pre-formanceTartuptimeMoryusage, Quarkusandmicronautleadduetocompile-Timeprocessingandgraalvsupport, Withquarkusoftenperforminglightbetterine ServerLess scenarios.2.Thyvelopecosyste,

SetupaMaven/GradleprojectwithJAX-RSdependencieslikeJersey;2.CreateaRESTresourceusingannotationssuchas@Pathand@GET;3.ConfiguretheapplicationviaApplicationsubclassorweb.xml;4.AddJacksonforJSONbindingbyincludingjersey-media-json-jackson;5.DeploytoaJakar

Use performance analysis tools to locate bottlenecks, use VisualVM or JProfiler in the development and testing stage, and give priority to Async-Profiler in the production environment; 2. Reduce object creation, reuse objects, use StringBuilder to replace string splicing, and select appropriate GC strategies; 3. Optimize collection usage, select and preset initial capacity according to the scene; 4. Optimize concurrency, use concurrent collections, reduce lock granularity, and set thread pool reasonably; 5. Tune JVM parameters, set reasonable heap size and low-latency garbage collector and enable GC logs; 6. Avoid reflection at the code level, replace wrapper classes with basic types, delay initialization, and use final and static; 7. Continuous performance testing and monitoring, combined with JMH

Maven is a standard tool for Java project management and construction. The answer lies in the fact that it uses pom.xml to standardize project structure, dependency management, construction lifecycle automation and plug-in extensions; 1. Use pom.xml to define groupId, artifactId, version and dependencies; 2. Master core commands such as mvnclean, compile, test, package, install and deploy; 3. Use dependencyManagement and exclusions to manage dependency versions and conflicts; 4. Organize large applications through multi-module project structure and are managed uniformly by the parent POM; 5.

TheJVMenablesJava’s"writeonce,runanywhere"capabilitybyexecutingbytecodethroughfourmaincomponents:1.TheClassLoaderSubsystemloads,links,andinitializes.classfilesusingbootstrap,extension,andapplicationclassloaders,ensuringsecureandlazyclassloa
