1Z0-811 Java Development and Deployment 3 — Questions and Answers
Question 1: Which tool introduced in Java 9+ creates a custom runtime image containing only the modules your application needs?
- jlink (Correct answer)
- jdeps
- jpackage
- jmod
Correct answer: jlink
`jlink` assembles a custom runtime image from a set of modules, reducing the deployment footprint.
Question 2: What is the purpose of the `jdeps` tool?
- Analyze class and package-level dependencies of a JAR or class file (Correct answer)
- Generate Javadoc from source files
- Package an application into a native installer
- Compile Java source files to bytecode
Correct answer: Analyze class and package-level dependencies of a JAR or class file
`jdeps` analyzes dependencies between packages and modules, helping identify which modules a class or JAR requires.
Question 3: Which file in a JAR is responsible for specifying the Main-Class and other metadata?
- META-INF/MANIFEST.MF (Correct answer)
- META-INF/module-info.class
- META-INF/services/
- WEB-INF/web.xml
Correct answer: META-INF/MANIFEST.MF
The `MANIFEST.MF` file inside `META-INF/` stores JAR metadata including `Main-Class`, `Class-Path`, and custom attributes.
Question 4: When compiling with modules, which flag adds a module to the set of root modules without editing module-info.java?
- --add-modules (Correct answer)
- --module-path
- --patch-module
- --upgrade-module-path
Correct answer: --add-modules
`--add-modules` lets you include additional modules in the module graph without modifying module descriptors.
Question 5: What is the default access level for a package inside a named module that does NOT use an `exports` directive?
- The package is inaccessible to all other modules (Correct answer)
- The package is accessible to all modules on the module path
- The package is accessible only to the unnamed module
- The package is accessible only within the same layer
Correct answer: The package is inaccessible to all other modules
In the module system, packages that are not explicitly exported are encapsulated and inaccessible to code in other modules.
Question 6: Which command creates a `.jmod` file from a set of compiled classes and resources?
- jmod create --class-path out mymodule.jmod (Correct answer)
- jar --create --file mymodule.jmod
- jlink --create mymodule.jmod
- javac --module-output mymodule.jmod
Correct answer: jmod create --class-path out mymodule.jmod
`jmod create` packages compiled classes, native libraries, and configuration files into a `.jmod` file used by `jlink`.
Question 7: What does `--patch-module <module>=<path>` allow you to do at runtime?
- Inject additional classes into a module without recompiling it (Correct answer)
- Replace the entire module with a new JAR
- Add exports to a module dynamically
- Increase the memory allocated to a module
Correct answer: Inject additional classes into a module without recompiling it
`--patch-module` overlays classes from a path into a named module, commonly used for testing or hot-patching.
Which tool introduced in Java 9+ creates a custom runtime image containing only the modules your application needs?