1Z0-819 Modules System 4 — Questions and Answers
Question 1: What is the correct location for module-info.java in a standard Maven project layout?
- src/main/resources/module-info.java
- src/module/module-info.java
- META-INF/module-info.java
- src/main/java/module-info.java at the root of the source tree (Correct answer)
Correct answer: src/main/java/module-info.java at the root of the source tree
module-info.java lives at the root of the module's source tree, directly in src/main/java for Maven projects.
Question 2: Which statement correctly describes an automatic module's readability?
- An automatic module reads all other named modules and the unnamed module (Correct answer)
- An automatic module can only read modules explicitly listed in MANIFEST.MF
- An automatic module reads only the java.base module by default
- An automatic module cannot be required by named modules
Correct answer: An automatic module reads all other named modules and the unnamed module
Automatic modules have unrestricted readability — they read every module on the module path plus the unnamed module, enabling legacy code to work.
Question 3: What is the effect of passing '--module-source-path' to javac?
- It sets the output directory for compiled module-info.class files only
- It enables multi-module compilation by specifying the root of multiple module source trees (Correct answer)
- It adds an extra source path searched before the regular source path
- It instructs javac to generate automatic module-info.java stubs
Correct answer: It enables multi-module compilation by specifying the root of multiple module source trees
'--module-source-path' enables javac to compile multiple modules simultaneously by specifying the directory that contains each module's source folder.
Question 4: Which 'opens' syntax in module-info.java opens a package to ALL other modules for deep reflection?
- opens com.example.internal to *;
- opens com.example.internal to ALL;
- exports com.example.internal opens;
- opens com.example.internal; (Correct answer)
Correct answer: opens com.example.internal;
An 'opens' directive without a 'to' clause makes the package open for deep reflection to all modules.
Question 5: What does 'requires static com.example.annotation;' mean in module-info.java?
- The dependency is always required but loaded lazily
- All annotation types from com.example.annotation are statically imported
- The dependency is required at compile time but optional at runtime (Correct answer)
- The module's static initializers run before the annotation module loads
Correct answer: The dependency is required at compile time but optional at runtime
'requires static' declares a compile-time-only dependency; the module is not required to be present at runtime.
Question 6: When using ServiceLoader.load(MyService.class), which module system requirements must be satisfied?
- The providing module must export the package containing MyService to the consuming module
- The consuming module must open its own package to the providing module
- MyService must be declared in the java.base module
- The consuming module needs 'uses MyService' and provider modules need 'provides MyService with ...' (Correct answer)
Correct answer: The consuming module needs 'uses MyService' and provider modules need 'provides MyService with ...'
ServiceLoader requires the consumer to declare 'uses' and each provider to declare 'provides ... with ...' in their respective module descriptors.
Question 7: Which java command-line option grants a named module access to unexported public types of another named module?
- --add-opens
- --add-reads
- --add-exports (Correct answer)
- --patch-module
Correct answer: --add-exports
'--add-exports sourceModule/package=targetModule' allows the target module to access public types in the package as if it were exported.
What is the correct location for module-info.java in a standard Maven project layout?