Learnitweb

Java 9 – Explain differences between JAR file and module

Differences between JAR file and module can be summarized in following points:

JARModule
JAR stands for Java Archive and is a file format based on the ZIP file format. It is used for aggregating many files and associated metadata and resources(text, images etc) into one file to distribute as a library or application software.Modules is a language feature introduced in Java 9. Module is a group of packages and has information about module dependencies and types it exports to other modules. This information is saved in module-info.java file.
JAR file does not provide information about dependencies on other JAR files.A module can define dependency on other modules using module-info.java file.
Using a JAR file may result in NoClassDefFoundError error as there is no way to check if all dependencies are met before execution.While working with modules, JVM checks for all module dependencies at the beginning of execution. So there is no possibility to get NoClassDefFoundError during execution.
JAR is not a programming feature and is not related to application design as such.Module is a programming feature and is related to the design of application.
JAR does not impact encapsulation of types it contains. public types are available for all types outside JAR file.Module enhances strong encapsulation of types it contains. public is not so much public in case of types in modules.
JAR does not define what types it holds are available for other types (outside the JAR).Module defines which types(it contains) are accessible and which types are not.
JAR has no impact in reducing the size of distributed software.Module helps in reducing the size of distributed software and thus helps developing applications for small devices.
JAR is used to aggregate files. So, name of JAR can be changed easily as long as JVM classloader is able to find class.The name of a module can be explicitly referenced in the declaration of other modules, so name of module can not be changed easily.