1Z0-819 Modules System 3 — Questions and Answers
Question 1: Which JDK tool creates a custom runtime image from a set of modules?
- jmod
- jdeps
- jlink (Correct answer)
- jimage
Correct answer: jlink
'jlink' assembles and optimizes a custom runtime image containing only the specified modules and their transitive dependencies.
Question 2: What does the 'jdeps' tool primarily do in the context of the module system?
- Deploys modular JARs to a runtime image
- Analyzes class files to determine module and package dependencies (Correct answer)
- Lists all modules available in the current JDK
- Creates module-info.java files automatically from JAR metadata
Correct answer: Analyzes class files to determine module and package dependencies
'jdeps' analyzes class-file bytecode and reports module-level and package-level dependencies.
Question 3: What is the unnamed module in Java's module system?
- A module declared without a name in module-info.java
- The bootstrap module containing java.lang classes
- A special module that contains all classes loaded from the classpath (Correct answer)
- An automatic module with no Automatic-Module-Name manifest entry
Correct answer: A special module that contains all classes loaded from the classpath
The unnamed module is a catch-all module that contains all types loaded from the classpath, enabling backward compatibility.
Question 4: Which JVM option allows deep reflection from one named module into a package of another module at runtime without modifying source?
- --add-exports
- --add-reads
- --add-modules
- --add-opens (Correct answer)
Correct answer: --add-opens
'--add-opens module/package=targetModule' grants reflective access similar to an 'opens' directive without modifying module-info.
Question 5: A module-info.java contains 'exports com.example.util to com.app.core;'. This means:
- com.example.util is exported to all modules with com.app.core getting priority
- com.app.core can access all types (including private) in com.example.util
- com.app.core must explicitly import com.example.util to use it
- Only com.app.core can access the public types in com.example.util (Correct answer)
Correct answer: Only com.app.core can access the public types in com.example.util
A qualified export restricts access to the exported package's public types to only the specified module(s).
Question 6: What is the primary purpose of JMOD files created by the 'jmod' tool?
- To serve as runtime JARs on the module path
- To store module source code for documentation
- To package modules including native code for use with jlink (Correct answer)
- To provide binary module descriptors for faster JVM startup
Correct answer: To package modules including native code for use with jlink
JMOD is a packaging format used mainly for JDK modules; it supports native libraries and config files that regular JARs can't include, used by jlink.
Question 7: What happens if two named modules on the module path export the same package?
- The module listed first on the module path takes precedence
- A split package error occurs at startup or compile time (Correct answer)
- The JVM merges the packages and all types are accessible
- Both modules load silently and types are disambiguated by module name
Correct answer: A split package error occurs at startup or compile time
Split packages (the same package in more than one named module) are forbidden and result in an error.
Which JDK tool creates a custom runtime image from a set of modules?