โ† All OCP Flashcard Decks

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
  1. Two modules `com.a` and `com.b` each declare `requires` on each other. What happens during module resolution?

    Answer: The JVM detects a cyclic dependency and throws an error

    The JPMS does not allow cyclic dependencies between named modules; a cyclic requires graph causes a resolution error at startup.

  2. Which `jmod` sub-command is used to create a new JMOD file from compiled classes and resources?

    Answer: jmod create

    `jmod create` packages compiled classes, native libraries, configuration files, and other resources into a JMOD file.

  3. Which reflection method is used at runtime to load service provider implementations declared via `provides ... with` in module-info.java?

    Answer: ServiceLoader.load()

    `ServiceLoader.load(ServiceInterface.class)` discovers and instantiates all implementations registered via the module system's `provides` directive.

  4. What is the purpose of the `--patch-module` option when running a Java application?

    Answer: Merges additional classes into an existing module at runtime

    `--patch-module` injects additional classes or resources into a named module, overriding or augmenting its content at runtime.

  5. A class in module `com.reader` calls `Module.addOpens("com.reader.data", targetModule)` at runtime. When is this call permitted?

    Answer: Only when the caller's module is com.reader itself (a module can only open its own packages)

    A module can only dynamically open its own packages to other modules; attempting to open another module's packages throws IllegalCallerException.

  6. Which `javac` flag is required to compile code in a single named module when the module-info.java is in the source root?

    Answer: --module-source-path .

    `--module-source-path .` tells the compiler to find module source directories under the current path, enabling single or multi-module compilation.

  7. Which statement about the `java.se` module is TRUE?

    Answer: java.se is an aggregator module that requires transitive all standard Java SE modules

    `java.se` is an aggregator module that uses `requires transitive` to group all Java SE API modules, but contains no classes itself.