โ† All 1Z0-819 Flashcard Decks

Modular Development & Deployment Practices Flashcards

9 cards from real 1Z0-819 practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 9 Modular Development & Deployment Practices flashcards as text
  1. What feature was introduced in Java 9 to support modular development?

    Answer: Modules

    Java 9 introduced the Java Platform Module System (JPMS), often referred to as Project Jigsaw, as a major feature to support modular development. This system allows developers to organize code into distinct, self-contained modules, improving encapsulation, reliability, and maintainability of large applications. It also enables the creation of smaller, custom runtime images.

  2. Which file defines a module in Java?

    Answer: module-info.java

    In the Java Platform Module System, a module is formally defined by a `module-info.java` file. This file, located at the root of the module's source directory, contains declarations such as the module's name, its dependencies on other modules (`requires`), and the packages it makes available to other modules (`exports`). It serves as the module descriptor.

  3. What keyword is used to declare a module requirement?

    Answer: requires

    The `requires` keyword is used within a `module-info.java` file to declare a dependency on another module. This explicitly states that the current module needs the functionality (exported packages) provided by the required module to compile and run correctly. This mechanism enforces strong encapsulation and explicit dependencies between modules.

  4. What does the 'exports' keyword do in module-info.java?

    Answer: Exposes packages to other modules

    In a `module-info.java` file, the `exports` keyword is used to specify which packages within the current module are accessible to other modules. By default, all packages inside a module are strongly encapsulated and not visible externally. `exports` explicitly opens up selected packages, allowing other modules to use their public types, thereby controlling the module's public API.

  5. What is jlink used for?

    Answer: To create a custom Java runtime image

    `jlink` is a command-line tool introduced in Java 9 that allows developers to create a custom, minimal Java runtime image. This image contains only the Java modules required by a specific application, significantly reducing the size of the runtime environment. This is particularly beneficial for deploying self-contained applications with a smaller footprint.

  6. Which command compiles modules?

    Answer: javac --module-source-path

    To compile Java modules, the `javac` command is used, but with the `--module-source-path` option. This option specifies the path where the compiler can find the source code for modules, allowing it to resolve module dependencies and compile the `module-info.java` files along with the regular Java source files. Other options like `java` run code, `jar` packages, and `jmod` creates module archives.

  7. What is a named module?

    Answer: A module with a defined name in module-info.java

    A named module is a module that has a defined name and explicitly declares its dependencies and exported packages in a `module-info.java` file. This contrasts with unnamed modules, which are typically created from classes on the classpath that are not part of a named module. Named modules benefit from the strong encapsulation and explicit dependency management provided by the Java Platform Module System.

  8. What tool is used to package compiled modules?

    Answer: jar

    The `jar` tool is the standard utility in Java for packaging compiled Java classes, resources, and metadata into a single archive file. For modules, `jar` is used to create a modular JAR file, which includes the compiled `module-info.class` file at its root, making it a deployable unit for the Java Platform Module System.

  9. What is the benefit of modular programming?

    Answer: Improved encapsulation and modular deployment

    Modular programming, especially with the Java Platform Module System, significantly improves encapsulation by explicitly defining what parts of a module are accessible externally. This leads to more reliable and maintainable code. It also facilitates modular deployment, allowing applications to be built and shipped with only the necessary components, reducing size and complexity.