Java Platform Module System Flashcards
7 cards from real OCP practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Java Platform Module System flashcards as text
Which of the following is NOT a valid module directive in module-info.java?
Answer: exports transitive
`exports transitive` is not valid syntax; `transitive` is a modifier for `requires`, not `exports`.
What does `requires static com.annotation;` mean in a module declaration?
Answer: The module requires com.annotation at compile time but it is optional at runtime
`requires static` is a compile-time-only dependency; the module can still run if com.annotation is absent from the module path at runtime.
When running `java --list-modules`, what does the output show?
Answer: All observable modules in the current JDK/JRE installation
`--list-modules` prints all observable platform and installed modules available in the current Java runtime.
Which of the following best describes an 'open module' declared as `open module com.app { }`?
Answer: All packages are open for deep reflection at runtime by any module
An `open module` implicitly opens all its packages for deep reflection at runtime, equivalent to adding `opens` for every package.
Which `javac` option is used to compile a module-info.java file along with other source files in the correct module source path layout?
Answer: --module-source-path
`--module-source-path` tells javac where to find source files for multiple modules in a modular project layout.
What is the effect of placing a JAR on the classpath (not module path) in a modular application?
Answer: It becomes part of the unnamed module
All JARs on the classpath are consolidated into a single unnamed module, which has no module-info and can access all exported packages.
Which `java` command-line option forces an additional module to be resolved even if it is not required by the root module?
Answer: --add-modules
`--add-modules` adds the specified modules to the default set of root modules during module resolution.