1Z0-819 Modular Development & Deployment Practices 2 — Questions and Answers
Question 1: Which `module-info.java` directive allows a module to read another module's types without the consuming module explicitly requiring it?
- requires transitive (Correct answer)
- exports transitive
- opens transitive
- uses transitive
Correct answer: requires transitive
`requires transitive` causes any module that requires the current module to also implicitly read the specified dependency.
Question 2: A developer runs `java --list-modules`. What does this command display?
- Only the application modules on the module path
- All observable system modules bundled with the JDK (Correct answer)
- The dependency graph of the currently running application
- Modules declared in the current project's module-info.java
Correct answer: All observable system modules bundled with the JDK
`--list-modules` without additional arguments lists all observable system (platform) modules available in the running JDK.
Question 3: Which tool is used to link a set of modules into a custom runtime image in Java 11?
- jdeps
- jmod
- jlink (Correct answer)
- jshell
Correct answer: jlink
`jlink` assembles and optimizes a set of modules and their transitive dependencies into a custom, self-contained runtime image.
Question 4: What happens when you place a modular JAR on the class path instead of the module path?
- The JVM throws a module resolution error at startup
- The module-info.class is ignored and the JAR is treated as unnamed module content (Correct answer)
- The module's exports restrictions are still enforced
- The JAR is automatically promoted to a named module
Correct answer: The module-info.class is ignored and the JAR is treated as unnamed module content
When a modular JAR is placed on the class path, `module-info.class` is ignored and its classes become part of the unnamed module.
Question 5: Which command-line option allows code in an unnamed module to access a specific package in a named module at runtime?
- --add-reads
- --add-exports (Correct answer)
- --add-opens
- --patch-module
Correct answer: --add-exports
`--add-exports` makes a package in a named module accessible to another module (or unnamed module) without modifying `module-info.java`.
Question 6: In a `module-info.java`, what is the purpose of the `uses` directive?
- It declares that the module provides a service implementation
- It declares that the module consumes a service via ServiceLoader (Correct answer)
- It restricts which modules can load the specified type
- It marks a dependency as optional at compile time
Correct answer: It declares that the module consumes a service via ServiceLoader
The `uses` directive specifies a service interface that this module may look up at runtime using `ServiceLoader`.
Question 7: Which `jdeps` flag generates a `module-info.java` template for a non-modular JAR?
- --module-info
- --generate-module-info (Correct answer)
- --suggest-providers
- --multi-release
Correct answer: --generate-module-info
`jdeps --generate-module-info <dir> <jar>` analyzes dependencies and writes a draft `module-info.java` to the specified directory.
Which `module-info.java` directive allows a module to read another module's types without the consuming module explicitly requiring it?