What is the difference between a module and a package

Java 9 has introduced the concept of modules in Java. You can take a look at this article which explains more about modules.

Here, I will be explaining the difference between a module and a package in Java.

Edit
PackageModule
A package cannot be deployed by itselfA module can be deployed by itself
A package groups together related classesA module groups together related packages
Packages are present in Java right from the beginningModules were added by Java 9
Packages were added to keep related classes together and to allow developers to have a class with the same name in a different packagesModules were added for security reasons and to reduce the size of the JDK
Classes defined within a package are accessible via reflection even if they are privateClasses defined within a module are not accessible outside the module via reflection
Packages do not require a package descriptorModules require a module descriptor which is a file called module-info.java

 

Comments

Popular posts from this blog

How to use logging in SpringBoot with code samples

Python While Loop with code samples

How to convert a List to a Set