Questions for the 1Z0-829 were updated on : Dec 01 ,2025
Given:
Which two should the module-info file include for it to represent the service provider interface?
BE
Explanation:
The answer is B and E because the module-info file should include a provides directive and an
exports directive to represent the service provider interface. The provides directive declares that the
module provides an implementation of a service interface, which is com.transport.vehicle.cars.Car in
this case. The with clause specifies the fully qualified name of the service provider class, which is
com.transport.vehicle.cars.impl.CarImpl in this case. The exports directive declares that the module
exports a package, which is com.transport.vehicle.cars in this case, to make it available to other
modules. The package contains the service interface that other modules can use.
Option A is incorrect because requires is not the correct keyword to declare a service provider
interface. Requires declares that the module depends on another module, which is not the case
here.
Option C is incorrect because it has a typo in the module name. It should be
com.transport.vehicle.cars, not cm.transport.vehicle.cars.
Option D is incorrect because it has a typo in the keyword provides. It should be provides, not
Provides. It also has a typo in the service interface name. It should be com.transport.vehicle.cars.Car,
not com.transport.vehicle.cars.Car impl. It also has an unnecessary to clause, which is used to limit
the accessibility of an exported package to specific modules.
Option F is incorrect because it exports the wrong package. It should export
com.transport.vehicle.cars, not com.transport.vehicle.cars.impl. The impl package contains the
service provider class, which should not be exposed to other modules.
Option G is incorrect because it exports the wrong package. It should export
com.transport.vehicle.cars, not com.transport.vehicle. The vehicle package does not contain the
service interface or the service provider class. Reference:
Oracle Certified Professional: Java SE 17 Developer
Java SE 17 Developer
OCP Oracle Certified Professional Java SE 17 Developer Study Guide
Java Modules - Service Interface Module - GeeksforGeeks
Java Service Provider Interface | Baeldung
Which statement is true about modules?
C
Explanation:
A module path is a sequence of directories that contain modules or JAR files. A named module is a
module that has a name and a module descriptor (module-info.class) that declares its dependencies
and exports. An automatic module is a module that does not have a module descriptor, but is
derived from the name and contents of a JAR file. Both named and automatic modules can be placed
on the module path, and they can be resolved by the Java runtime. An unnamed module is a special
module that contains all the classes that are not in any other module, such as those on the class
path. An unnamed module is not on the module path, but it can read all other modules.
Given:
Which statement is true?
B
Explanation:
The answer is B because the code fragment contains a syntax error that prevents it from compiling.
The code fragment tries to catch a StockException in line 10, but the catch block does not have a
parameter of type StockException. The catch block should have a parameter of type StockException,
such as:
catch (StockException e) { // handle the exception }
This is required by the Java syntax for the catch clause, which must have a parameter that is a
subclass of Throwable. Without a parameter, the catch block is invalid and causes a compilation
error.
Option A is incorrect because the program does not throw a StockException, as it does not compile.
Option C is incorrect because the program does not throw an OutofStockException, as it does not
compile.
Option D is incorrect because the program does not throw a ClassCastException, as it does not
compile. Reference:
Oracle Certified Professional: Java SE 17 Developer
Java SE 17 Developer
OCP Oracle Certified Professional Java SE 17 Developer Study Guide
The try-with-resources Statement (The Java™ Tutorials > Essential Classes > Exceptions)
The catch Blocks (The Java™ Tutorials > Essential Classes > Exceptions)
Given:
Which two modifications enable the code to print Open Close?
A)
B)
C)
D)
E)
BE
Explanation:
The code given is a try-with-resources statement that declares a resource of type AutoCloseable. The
resource is an anonymous class that implements the AutoCloseable interface and overrides the
close() method. The code also has a print() method that prints the value of the variable s. The code is
supposed to print “Open Close”, but it does not compile because of two errors.
The first error is at line n1, where the anonymous class is missing a semicolon at the end of its
declaration. This causes a syntax error and prevents the code from compiling. To fix this error, option
B adds a semicolon after the closing curly brace of the anonymous class.
The second error is at line n2, where the print() method is called without an object reference. This
causes a compilation error because the print() method is not static and cannot be invoked without an
object. To fix this error, option E adds an object reference to the print() method by using the variable
t.
Therefore, options B and E are correct and enable the code to print “Open Close”.
Given the code fragment:
What is the result?
D
Explanation:
The answer is E because the code fragment creates a new Pet object with the name “Dog” and
assigns it to the variable p. Then, it assigns p to p1. Next, it changes the name of p1 to “Cat”. Then, it
assigns p1 to p. Finally, it sets p to null and prints the name of p and p1. The output will be “Cat” and
“null” because p is set to null and p1 still points to the Pet object with the name “Cat”.
Given:
Which statement is true while the program prints GC?
B
Which statement is true about migration?
B
Explanation:
The answer is B because a bottom-up migration is a strategy for modularizing an existing application
by moving its dependencies to the module path one by one, starting from the lowest-level libraries
and ending with the application itself. This way, each module can declare its dependencies on other
modules using the module-info.java file, and benefit from the features of the Java Platform Module
System (JPMS), such as reliable configuration, strong encapsulation, and service loading.
Option A is incorrect because a top-down migration is a strategy for modularizing an existing
application by moving it to the module path first, along with its dependencies as automatic modules.
Automatic modules are non-modular JAR files that are treated as modules with some limitations,
such as not having a module descriptor or a fixed name. A top-down migration allows the application
to use the module path without requiring all of its dependencies to be modularized first.
Option C is incorrect because a top-down migration does not require any specific order of migrating
modules, as long as the application is moved first and its dependencies are moved as automatic
modules. A bottom-up migration, on the other hand, requires the required modules to migrate
before the modules that depend on them.
Option D is incorrect because unnamed modules are not automatic modules in any migration
strategy. Unnamed modules are modules that do not have a name or a module descriptor, such as
classes loaded from the class path or dynamically generated classes. Unnamed modules have
unrestricted access to all other modules, but they cannot be accessed by named modules, except
through reflection with reduced security checks. Reference:
Oracle Certified Professional: Java SE 17 Developer
Java SE 17 Developer
OCP Oracle Certified Professional Java SE 17 Developer Study Guide
Migrating to Modules (How and When) - JavaDeploy
Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications
Assume you have an automatic module from the module path display-ascii-0.2. jar. Which name is
given to the automatic module based on the given JAR file?
C
Explanation:
An automatic module name is derived from the name of the JAR file when it does not contain
a module-info.class file. If the JAR file has an “Automatic-Module-Name” attribute in its main
manifest, then its value is the module name. Otherwise, the module name is derived from the JAR
file’s name by removing any version numbers and converting it to lower case. Therefore, for a JAR
named display-ascii-0.2.jar, the automatic module name would be display-ascii, following these
rules.
Given:
What is the result?
B
Explanation:
The answer is B because the code fragment contains a logical error that causes a
MissingResourceException at runtime. The code fragment tries to load a resource bundle with the
base name “Captions.properties” and the locale “en_US”. However, there is no such resource bundle
available in the classpath. The available resource bundles are:
Captions.properties
Captions_en.properties
Captions_US.properties
Captions_en_US.properties
The ResourceBundle class follows a fallback mechanism to find the best matching resource bundle
for a given locale. It first tries to find the resource bundle with the exact locale, then it tries to find
the resource bundle with the same language and script, then it tries to find the resource bundle with
the same language, and finally it tries to find the default resource bundle with no locale. If none of
these resource bundles are found, it throws a MissingResourceException.
In this case, the code fragment is looking for a resource bundle with the base name
“Captions.properties” and the locale “en_US”. The ResourceBundle class will try to find the following
resource bundles in order:
Captions.properties_en_US
Captions.properties_en
Captions.properties
However, none of these resource bundles exist in the classpath. Therefore, the ResourceBundle class
will throw a MissingResourceException.
To fix this error, the code fragment should use the correct base name of the resource bundle family,
which is “Captions” without the “.properties” extension. For example:
ResourceBundle captions = ResourceBundle.getBundle(“Captions”, currentLocale);
This will load the appropriate resource bundle for the current locale, which is
“Captions_en_US.properties” in this case. Reference:
Oracle Certified Professional: Java SE 17 Developer
Java SE 17 Developer
OCP Oracle Certified Professional Java SE 17 Developer Study Guide
ResourceBundle (Java Platform SE 8 )
About the ResourceBundle Class (The Java™ Tutorials > Internationalization)
Given:
What is the result?
D
Explanation:
The code fragment is using the bitwise operators & (AND), | (OR), and ^ (XOR) to perform operations
on the binary representations of the integer values. The & operator returns a 1 in each bit position
where both operands have a 1, the | operator returns a 1 in each bit position where either operand
has a 1, and the ^ operator returns a 1 in each bit position where only one operand has a 1. The
binary representations of the integer values are as follows:
1000 = 1111101000
100 = 1100100
101 = 1100101
The code fragment performs the following operations:
x = x ^ y; // x becomes 1111010101, which is 1001 in decimal
y = x ^ y; // y becomes 1100100, which is 100 in decimal
x = x ^ y; // x becomes 1100101, which is 101 in decimal
The code fragment then prints out the values of x, y, and z, which are 1001, 100, and 1000
respectively. Therefore, option D is correct.
Which two code fragments compile?
A)
B)
C)
D)
E)
B, E
Explanation:
The two code fragments that compile are B and E. These are the only ones that use the correct syntax
for declaring and initializing a var variable. The var keyword is a reserved type name that allows the
compiler to infer the type of the variable based on the initializer expression. However, the var
variable must have an initializer, and the initializer must not be null or a lambda expression.
Therefore, option A is invalid because it does not have an initializer, option C is invalid because it has
a null initializer, and option D is invalid because it has a lambda expression as an initializer. Option B
is valid because it has a String initializer, and option E is valid because it has an int initializer.
https://docs.oracle.com/en/java/javase/17/language/local-variable-type-inference.html
Given the content of the in. tart file:
23456789
and the code fragment:
What is the content of the out .txt file?
D
Explanation:
The answer is D because the code fragment reads the content of the in.txt file and writes it to the
out.txt file. The content of the in.txt file is “23456789”. The code fragment uses a char array buffer of
size 8 to read the content of the in.txt file. The while loop reads the content of the in.txt file and
writes it to the out.txt file until the end of the file is reached. Therefore, the content of the out.txt file
will be “0123456789”.
Given the code fragment:
Which code line n1, obtains the java.io.Console object?
A)
B)
C)
D)
E)
A
Explanation:
The code fragment is trying to obtain the java.io.Console object, which is a class that provides
methods to access the character-based console device, if any, associated with the current Java virtual
machine. The correct way to obtain the Console object is to call the static method Console console()
in the java.lang.System class. This method returns the unique Console object associated with the
current Java virtual machine, if any. Therefore, option A is correct, as it calls System.console() and
assigns it to a Console variable. Reference:
https://docs.oracle.com/javase/17/docs/api/java.base/java/io/Console.html
https://docs.oracle.com/javase/17/docs/api/java.base/java/lang/System.html#console()
https://education.oracle.com/products/trackp_OCPJSE17
https://mylearn.oracle.com/ou/learning-path/java-se-17-developer/99487
Given:
Which two method invocation execute?
DE
Explanation:
The code given is an interface and a class that implements the interface. The interface has three
methods, m1(), m2(), and m3(). The class has one method, m1(). The only two method invocations
that will execute are D and E. D is a call to the m2() method in the class, and E is a call to the m3()
method in the interface. Reference: https://education.oracle.com/products/trackp_OCPJSE17,
,
,
Given the code fragment:
abstract sealed interface SInt permits Story, Art { default String getTitle() { return "Book Title" ;
}
}
Which set of class definitions compiles?
C
Explanation:
The answer is C because the code fragment given is an abstract sealed interface SInt that permits
Story and Art. The correct answer is option C, which is a sealed interface Story that extends SInt and
a non-sealed class Art that implements SInt. This is because a sealed interface can only be extended
by the classes or interfaces that it permits, and a non-sealed class can implement a sealed interface.
Option A is incorrect because interface is misspelled as interace, and Story and Art should be
capitalized as they are the names of the permitted classes or interfaces.
Option B is incorrect because public is misspelled as public, and sInd should be SInt as it is the name
of the sealed interface.
Option D is incorrect because a non-sealed interface cannot extend a sealed interface, as it would
violate the restriction of permitted subtypes.
Option E is incorrect because both Story and Art cannot be non-sealed interfaces, as they would also
violate the restriction of permitted subtypes.
Reference:
Oracle Certified Professional: Java SE 17 Developer
Java SE 17 Developer
OCP Oracle Certified Professional Java SE 17 Developer Study Guide
Sealed Classes and Interfaces in Java 15 | Baeldung
Sealed Class in Java - Javatpoint