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 directive in module-info.java allows a module to expose a package for deep reflection at runtime without exporting it for compile-time access?
Answer: opens
The `opens` directive allows reflective access to a package at runtime but does not export it for use at compile time.
What happens when a module declares `requires transitive com.utils;` and another module depends on that module?
Answer: Downstream modules automatically read com.utils without declaring requires
`requires transitive` implies readability, so any module that reads the declaring module also automatically reads com.utils.
Which tool is used to create a custom runtime image that contains only the modules needed by an application?
Answer: jlink
`jlink` assembles a set of modules and their dependencies into a custom, minimal JVM runtime image.
A module named `com.app` contains package `com.app.internal`. Which declaration restricts its export to only `com.trusted` module?
Answer: exports com.app.internal to com.trusted;
The `exports ... to` qualified export restricts which specific modules can access the exported package.
Which command-line option allows code in an unnamed module to access a package from a named module that does not export it?
Answer: --add-exports
`--add-exports` overrides module boundaries at runtime or compile time to expose a package that is not otherwise exported.
What is the term for a JAR placed on the module path that does not contain a module-info.class?
Answer: Automatic module
A JAR on the module path without module-info.class becomes an automatic module, deriving its name from the JAR filename.
Which of the following statements about split packages is TRUE in the Java Module System?
Answer: The same package cannot exist in two named modules on the module path
The JPMS strictly prohibits the same package from being present in two different named modules; this causes a module resolution error.