Core java interview Questions You'll Most Likely Be Asked (Second Edition)


Download 1.52 Mb.
Pdf ko'rish
bet103/171
Sana07.01.2023
Hajmi1.52 Mb.
#1081886
1   ...   99   100   101   102   103   104   105   106   ...   171
Bog'liq
Core JAVA Interview Questions Youll M...

What is the module descriptor?
Answer:
A module descriptor is a Java file named module–info.java. It
contains information about the module. It needs to be present at
the root of the module. The following lines demonstrate the
structure of the module descriptor:
module demomodule {
//optional directives
}
The module descriptor can contain some optional directives.
Some of the directives that can be specified within the module
descriptor are as follows:
Name: This specifies the name of the module.
exports: This specifies the names of the packages within this
module that will be available to other modules.
requires: This specifies the names of the modules that the
current module depends on. So if these modules are not
specified, the current module may not work.
provides: This specifies the services that the current module
provides. This directive should be used when a module acts
as a service provider.
uses: This specifies the services that the current module
consumes. This directive should be used when the module is
a service consumer.
open: This specifies that the classes in the currently module
can be accessed via Java reflection.


264.






265.
What is the difference between a package and a module?
Answer:
Both packages and modules are a logical unit and encapsulate
some Java files. However, there are several differences between
the two as follows:
Packages are present right from the early versions of Java.
Modules on the other had are added by Java 9.
Packages were added by Java to avoid name clashes that it
they allow having a class with the same name in different
packages. Modules were added by Java to modularize the
JDK and to improve security.
A package contains a group of related files. A module on the
other hand contains a group of related packages.
A package does not require a package descriptor, a module
requires a module descriptor called module–info.java.
Packages cannot be deployed by themselves; modules can
be deployed by themselves.
The classes within a package are visible via reflection. The
classes within a module are not visible via reflection unless
the open directive is specified in the module descriptor.

Download 1.52 Mb.

Do'stlaringiz bilan baham:
1   ...   99   100   101   102   103   104   105   106   ...   171




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling