โ† 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. In a `module-info.java`, which directive is used to declare that a module consumes a service defined by an interface?

    Answer: uses

    The `uses` directive declares that the module is a consumer of a service interface via ServiceLoader.

  2. What does the `--limit-modules` command-line option do during module resolution?

    Answer: Restricts the universe of observable modules to a given set

    `--limit-modules` restricts the observable module universe to the specified modules and their transitive dependencies.

  3. Which of the following correctly declares a service provider in module-info.java for a service interface `com.api.Processor` with implementation `com.impl.FastProcessor`?

    Answer: provides com.api.Processor with com.impl.FastProcessor;

    The `provides ... with` directive registers a concrete implementation class for a service interface in the module system.

  4. Which module contains the `java.lang` package in a standard JDK modular installation?

    Answer: java.base

    `java.base` is the foundational module that contains core packages like java.lang, java.util, and java.io.

  5. What is the name derived for an automatic module created from a JAR file named `my-library-2.1.0.jar` when no Automatic-Module-Name manifest entry is present?

    Answer: my.library

    The JVM strips version numbers and converts hyphens to dots, deriving `my.library` as the automatic module name.

  6. Which option in the `jar` command is used to specify the main class when creating a modular JAR?

    Answer: --main-class

    The `--main-class` option in the `jar` command records the application entry point in the JAR manifest's Main-Class attribute.

  7. A module `com.app` opens package `com.app.data` to `com.framework`. Which statement about this is TRUE?

    Answer: com.framework can reflectively access all members, including private ones, in com.app.data

    A qualified `opens ... to` directive grants the specified module deep reflective access, including private members, to that package.