1Z0-819 Modules System 2 — Questions and Answers
Question 1: What keyword is used in a module-info.java to grant reflective access to all packages in a module to another module?
- exports
- opens (Correct answer)
- provides
- requires
Correct answer: opens
The 'opens' directive grants deep reflective access (including private members) to another module at runtime.
Question 2: Which command-line option adds a module to the set of root modules resolved by the module system?
- --module-path
- --add-opens
- --add-modules (Correct answer)
- --patch-module
Correct answer: --add-modules
'--add-modules' explicitly adds one or more modules to the root module set during resolution.
Question 3: In module-info.java, 'requires transitive com.example.api;' means that:
- com.example.api is required only at compile time, not runtime
- com.example.api is an optional dependency
- The current module re-exports all packages from com.example.api
- Any module requiring the current module implicitly also requires com.example.api (Correct answer)
Correct answer: Any module requiring the current module implicitly also requires com.example.api
'requires transitive' creates an implied readability dependency so consumers of your module also read com.example.api without declaring it themselves.
Question 4: Which command inspects the module descriptor of a modular JAR file?
- jar --describe-module (Correct answer)
- javap -m
- jlink --list-modules
- jmod describe
Correct answer: jar --describe-module
'jar --describe-module' (or '-d') prints the module descriptor of a modular JAR file.
Question 5: What happens when you place a non-modular JAR on the module path?
- It is rejected and a ModuleNotFoundException is thrown
- It becomes an automatic module with a name derived from the JAR filename (Correct answer)
- It is treated identically to being on the classpath
- It must have a module-info.class or it is silently ignored
Correct answer: It becomes an automatic module with a name derived from the JAR filename
Non-modular JARs on the module path become automatic modules, with a name derived from the JAR filename or Automatic-Module-Name manifest entry.
Question 6: Which directive declares that a module provides an implementation of a service interface?
- exports com.example.impl to com.example.Service
- uses com.example.impl.ServiceImpl
- provides com.example.Service with com.example.impl.ServiceImpl (Correct answer)
- implements com.example.Service with com.example.impl.ServiceImpl
Correct answer: provides com.example.Service with com.example.impl.ServiceImpl
The 'provides ... with ...' directive registers a service provider implementation with the module system.
Question 7: What is the purpose of the 'uses' directive in a module-info.java?
- It marks a package as open for reflection
- It imports static members from another module's package
- It specifies which JDK platform modules the module depends on
- It declares that the module may discover service providers via ServiceLoader (Correct answer)
Correct answer: It declares that the module may discover service providers via ServiceLoader
The 'uses' directive declares a service dependency, enabling ServiceLoader to find implementations at runtime.
What keyword is used in a module-info.java to grant reflective access to all packages in a module to another module?