0% found this document useful (0 votes)
9 views

ajp project

ajp micro project
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

ajp project

ajp micro project
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Modules

Java Modules

• Java Module System provides an additional layer of


encapsulation to our programs as we can specify which
package can be utilized by the modules, and which
modules could have entry to to them.

• Before entering into the exclusive types of modules in


Java, we will first learn the differences among
applications and modules.

• We recognize that there are numerous applications in


Java including IO bundle, AWT package, swing bundle,
and so on.

Difference Between Module and Package


The principal difference between the module and package is
given below.
1. Module: In easy words, we can say that the module is a
set of related applications or It is a collection of related
applications such that it affords an API handy to different
modules that are internal and encapsulated.

Suppose permits take an example from the built-in module in


Java let's take java.util for example. If we expect java.util as a
module we recognize that there are a variety of instructions
and sub-packages inside the java.util. Now we've assumed
that java.util is a package deal the modules could be like
java.util.Collections and java.util.stream.

2. Package: A package is a set of classes, interfaces, and


sub-packages that are similar. There are mainly two
types of packages in Java, they are:

• User Defined packages: The packages that contain the


classes or interfaces which are built based on the user
and it is nothing but they are just defined by the user.

• Built-In Packages: The packages that come pre-installed


when we configure the Java in our system are called the
built-in packages. For example, as we specified earlier
such as java.net, java.awt, javax.swing, java.sql etc
Java 9 Module System

• Java 9 has one of the major changes in its features which


is the Java module System.

• The main aim of the system is to collect Java packages


and code to be collected into a single unit called a
Module.

• The reason to add this feature in Java is that when we


want to create modular applications using Java the
earlier versions before 9 have no system like this that's
why the size of the application has increased.

• Even the JDK file in the earlier version of Java has a large
size only the rt.jar file size was around 64 MB.

To avoid this situation Java 9 has split the JDK into a set of
modules. so that we can use the required module to develop
our application. Apart from this, the Java 9 version has also
provided a feature so that the user could create their own
module and develop their own applications.
The modules in Java have the below options mentioned:

• This version of Java includes various options for Java


tools such as javac and java etc. In which we can specify
the module path and help us to locate the location of
the module in the Java 9.

• The JAR [ java Archive] file was introduced in this version


of java. The JAR contains module-info.class file in the
folder. [ JAR is a file format which is a zip file which is
used for aggregation of many files into one ]

• As we specified earlier the earlier versions of java has no


modular system and the size of rt.jar file was large so
the JDK and JRE was split into modules so that we can
use the modules we want to develop our application.

• Another thing is that the java 9 has introduced a new


URL method for naming the class and modules.
• JMOD file format is also introduced which is used to
handle other configuration files in java.
How to Create a module in java?

Earlier we supposed that our java module name is


org.geeksforgeeks which has followed the reverse domain
pattern to overcome the naming conflicts.
Creating the java modules involves three steps to be created
in java. The three steps to be followed are:

• We want to create a directory structure.

• We want to create a module declarator as we


mentioned earlier which is used to describe the module.

• we have to create a source code in that module


Conclusion

What is a module, actually? A module is a new level of


packages and resources aggregation, or as developers
say: “a uniquely named, reusable group of related
packages, as well as resources and a module
descriptor.”
Modules are delivered in JAR files with packages and a
module descriptor — module-info.java. The module-
info.java file contains: name, dependencies, public
packages, consumed and offered services, reflection
permissions.
Reference

https://medium.com/javarevisited/java-9-
modules-60c372ca0882

https://www.geeksforgeeks.org/java-modules/

https://www.baeldung.com/java-modularity

Thank you

You might also like