262.
•
•
•
•
•
CHAPTER
01
Modules
What is a module? What benefits do they offer?
Answer:
A module consists of a group of related packages. Just like you
put a set of
related classes into a package, you can put a set of
related packages into a module. Modules offer several benefits
as follows:
If an application
has a large number of packages, it becomes
difficult to keep track. Modules come to the rescue, they help
to
organize packages, that is related packages can be
grouped into a module.
Modules can be deployed by themselves. So, this helps to
reduce the size of an application.
Modules offer better security.
Before modules, the only way to
make a class reusable in other packages was to make it
public. However, this poses a
security issue since public
classes are accessible to everyone. Grouping packages into
modules ensures that the class is not accessible outside the
module.
Since there were no modules before Java 9,
the Java API jar
files like rt.jar were very big in size. Instead Java 9 has split
this into smaller modules which are easier to test and
maintain.
Prior to Java 9, security was
an issue as developers were
able to access internal JDK files. Modules help to overcome
this issue too. So with modules you can control which
263.
a.
b.
c.
d.
e.
f.
packages within the module are visible
and accessible outside
the module.
Do'stlaringiz bilan baham: