Looking to get certified as a Java SE Developer with Oracle?
Check out this highly rated Udemy course by the Skilltoz team with excellent practice questions that will help you prepare for the Java Certification exam.
For sample Questions, you can also refer to http://talks.skilltoz.com/java-11-certification-exam-questions/
Modules were introduced in Java from version 9.
What is a module declaration?
A module declaration begins with the keyword module, followed by a module name and a module body enclosed in braces.
module modulename {
}
A module declaration is defined in a file named module-info.java. It is placed in the module’s root folder.
What is a module descriptor?
The file that we get when we compile the module-info.java file is the module descriptor. It contains the metadata that specifies the module’s dependencies.
What are some of the advantages of modules?
- Startup time is less
- Memory requirement is low
- It is possible to prevent access of packages by other packages outside the module
- It is possible to omit certain parts of JDK from a custom build
Practice Questions
Q1. Is this a valid module-info file?
public module com.skilltoz {
exports com.skilltoz;
}
No, the modifer public should not be used for a module-info file. So this will not compile.
Q2. Where should the module-info file be placed for the module com.skilltoz declared in this module-info file?
module com.skilltoz {
exports com.skilltoz;
}
A. com folder
B. skilltoz folder
C. None of these
C is correct. It would need to be placed at the root directory of the module, which would be at the same level as the com folder.
Reference
To learn more about Java 9 Modules, visit this link.