Here the following benefit of Jigsaw is described:
As part of Project Jigsaw, all the Java Platform APIs have been split up into separate modules. The benefit of splitting all the Java APIs up into modules is that you can now specify what modules of the Java platform your application requires. Knowing what Java Platform modules your application requires, Java can package up your application including only the Java Platform modules that your application actually uses.
But, I can not understand how does it work, because as I know, Java does not put required modules directly in JAR. It just looks for them in module path. So, what the way does Java reduce JAR size by?
A Java module is a set of packages that declares which of them form an API accessible to other modules and which are internal and encapsulated — similar to how a class defines the visibility of its members. A module also declares what other modules it requires for its operation.
Advantages of Java SE 9 Module System 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.
Q 7 - Which of the following is correct about Module System in Java 9? A - javac, jlink, and java have additional options to specify module paths, which further locate definitions of modules.
A modular JAR file is a JAR file that has a module descriptor, module-info. class , in the top-level directory (or root) directory. The module descriptor is the binary form of a module declaration.
Java can package up your application including only the Java Platform modules that your application actually uses.
Since Java 9, it is possible to create custom runtime images using the jlink tool.
Basically, a custom runtime image is a package that not only contains your 3rd party libraries but also required parts of the JVM. This is some kind of self-contained executable image that contains everything you need to run it, without the need to have a JRE installed on your OS. It's a nice feature because you don't have to worry if someone has a particular JRE version installed in order to run the image.
Now, I guess that the sentence you are referring to doesn't want to say that the size of the JAR is reduced when compared to a pre-Java-9 (non-modular) JAR. I think that the author wanted to say that the ability to package only the required modules of the JVM reduces its size in comparison with a JAR that would contain the whole JVM.
For example, imagine you are writing an application which makes use of only some basic Java API's like collections, IO or date & time API (contained in the java.base module). Since you aren't using API's like Swing (java.desktop module) or JDBC (java.sql module), you don't need to have them in your package. Therefore, you can explicitly specify which java modules your application is using (in the module-info.java file) and only those will be bundled with your app. In this case, you would only add the java.base module in the list of required modules. On the other hand, if the need arises to add database access to your application using JDBC, you will add the java.sql module to the list of modules. As you can see, there is no need to have a whole JVM bundled with your application since you can choose which modules of the JVM are needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With