Java 9Java Interview Questions

What is the difference between a module and a package

Posted On
Posted By admin

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.

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

 

If you like this post, please do let me know via the comments box below.  You can also connect with me via my Facebook Page or subscribe to my Youtube channel!

Related Post

leave a Comment