oracle 1z0-829 practice test

Exam Title: Java SE 17 Developer

Last update: Nov 27 ,2025
Question 1

Given:

and the code fragment:

  • A. 300.00 CellPhone,ToyCar,Motor,Fan
  • B. 100.00 CellPhone,ToyCar,Motor,Fan
  • C. 100.00 CellPhone,ToyCar
  • D. 300.00 CellPhone.ToyCar
Answer:

A


Explanation:
The code fragment is using the Stream API to perform a reduction operation on a list of
ElectricProduct objects. The reduction operation consists of three parts: an identity value, an
accumulator function, and a combiner function. The identity value is the initial value of the result,
which is 0.0 in this case. The accumulator function is a BiFunction that takes two arguments: the
current result and the current element of the stream, and returns a new result. In this case, the
accumulator function is (a,b) -> a + b.getPrice (), which means that it adds the price of each element
to the current result. The combiner function is a BinaryOperator that takes two partial results and
combines them into one. In this case, the combiner function is (a,b) -> a + b, which means that it
adds the two partial results together.
The code fragment then applies a filter operation on the stream, which returns a new stream that
contains only the elements that match the given predicate. The predicate is p -> p.getPrice () > 10,
which means that it selects only the elements that have a price greater than 10. The code fragment
then applies a map operation on the filtered stream, which returns a new stream that contains the
results of applying the given function to each element. The function is p -> p.getName (), which
means that it returns the name of each element.
The code fragment then calls the collect method on the mapped stream, which performs a mutable
reduction operation on the elements of the stream using a Collector. The Collector is
Collectors.joining (“,”), which means that it concatenates the elements of the stream into a single
String, separated by commas.
The code fragment then prints out the result of the reduction operation and the result of the collect
operation, separated by a new line. The result of the reduction operation is 300.00, which is the sum
of the prices of all ElectricProduct objects that have a price greater than 10. The result of the collect
operation is CellPhone,ToyCar,Motor,Fan, which is the concatenation of the names of all
ElectricProduct objects that have a price greater than 10.
Therefore, the output of the code fragment is:
300.00 CellPhone,ToyCar,Motor,Fan
Reference:
Stream (Java SE 17 & JDK 17) - Oracle
,
Collectors (Java SE 17 & JDK 17) - Oracle

vote your answer:
A
B
C
D
A 0 B 0 C 0 D 0
Comments
Question 2

Given the code fragment:

Which action sorts the book list?

  • A. At Line n2, replace books,sort() with books.stream().sort(0.
  • B. At line n1, convert books type to mutable ArrayList type.
  • C. At Line n1, convert type to mutable array type.
  • D. At Line n2, replace compareTo () with compare ().
Answer:

D


Explanation:
The code fragment is trying to sort a list of books using the Collections.sort() method. The correct
answer is D, because the compareTo() method is not the correct way to compare two objects in a
Comparator.
The compare() method is the correct way to compare two objects in a Comparator and
return an int value that indicates their order1
.
The compareTo() method is used to implement the
Comparable interface, which defines the natural order of objects of a class2
.
The other options are
incorrect because they either do not change the type of the list, which is already mutable, or they do
not use the correct syntax for sorting a stream, which requires a terminal operation such as
collect()3
. Reference:
Comparator (Java SE 17 & JDK 17)
,
Comparable (Java SE 17 & JDK 17)
,
Stream
(Java SE 17 & JDK 17)

vote your answer:
A
B
C
D
A 0 B 0 C 0 D 0
Comments
Question 3

Given the code fragment:

What is the result?

  • A. 0 B 2 C -2
  • B. 2
  • C. 1
  • D. 1 -4
Answer:

B


Explanation:
The code fragment uses the Collections.binarySearch method to search for the string “e3” in the list.
The first search returns the index of the element, which is 2. The second search returns the index of
the element, which is 0. The third search returns the index of the element, which is -4. The final
result is 2. Reference:
Collections (Java SE 17 & JDK 17) - Oracle

vote your answer:
A
B
C
D
A 0 B 0 C 0 D 0
Comments
Question 4

Given:

What is the result?

  • A. Mb MC
  • C. Mb
  • E. mA
Answer:

E


Explanation:
The code snippet is an example of Java SE 17 code. The code is checking if the object is an instance of
class C and if it is, it will print “mC”. If it is not an instance of class C, it will print “mA”. In this case,
the object is not an instance of class C, so the output will be “mA”. Reference:
Pattern Matching for
instanceof - Oracle Help Center

vote your answer:
A
C
E
A 0 C 0 E 0
Comments
Question 5

Given the directory structure:

Given the definition of the Doc class:

Which two are valid definition of the wordDoc class?

  • A. Package p1; Public non-sealed class wordDoc extends Doc ()
  • B. Package p1; Public class wordDoc extends Doc ()
  • C. Package p1, p2; Public non-sealed class WordDoc extends Doc ()
  • D. Package p1, p2; Public sealed class WordDoc extends Doc ()
  • E. Package p1, non-sealed abstract class WordDoc extends Doc ()
  • F. Package p1; Public final class WordDoc extends Doc ()
Answer:

AF


Explanation:
The correct answer is A and F because the wordDoc class must be a non-sealed class or a final class to
extend the sealed Doc class. Option B is incorrect because the wordDoc class must be non-sealed or
final. Option C is incorrect because the wordDoc class cannot be in a different package than the Doc
class. Option D is incorrect because the wordDoc class cannot be a sealed class. Option E is incorrect
because the wordDoc class cannot be an abstract class. Reference:
Oracle Certified Professional: Java
SE 17 Developer
,
3 Sealed Classes - Oracle Help Center

vote your answer:
A
B
C
D
E
F
A 0 B 0 C 0 D 0 E 0 F 0
Comments
Question 6

Given:

What is the result

  • A. Marketing Finance Technical
  • B. Marketing Undefined
  • C. UnDefined
  • D. Marketing
Answer:

C


Explanation:
The code fragment is using the switch statement with the new Java 17 syntax. The switch statement
checks the value of the variable desig and executes the corresponding case statement. In this case,
the value of desig is “CTO”, which does not match any of the case labels. Therefore, the default case
statement is executed, which prints “Undefined”. The other case statements are not executed,
because there is no fall through in the new syntax. Therefore, the output of the code fragment is:
Undefined

vote your answer:
A
B
C
D
A 0 B 0 C 0 D 0
Comments
Question 7

Given:

What is the result?

  • A. 1 RAINY
  • B. Compilation fails
  • C. 1 Snowy
  • D. 0 CLOUDY
  • E. 0 Snowy
Answer:

E


Explanation:
The code is defining an enum class called Forecast with three values: SUNNY, CLOUDY, and RAINY. The
toString() method is overridden to always return “SNOWY”. In the main method, the ordinal value of
SUNNY is printed, which is 0, followed by the value of CLOUDY converted to uppercase, which is
“CLOUDY”. However, since the toString() method of Forecast returns “SNOWY” regardless of the
actual value, the output will be “0 SNOWY”. Reference:
Enum (Java SE 17 & JDK 17)
,
Enum.EnumDesc
(Java SE 17 & JDK 17)

vote your answer:
A
B
C
D
E
A 0 B 0 C 0 D 0 E 0
Comments
Question 8

Given the product class:

And the shop class:

What is the result?

  • A. Cookie 2.99 2.99
  • B. Cookie 3.99 2.99
  • C. Cookie 0.0 0.0
  • D. An exception is produced at runtime
  • E. Compilation fails
  • F. Cookie 0.0 2.99
Answer:

E


Explanation:
The code fragment will fail to compile because the readObject method in the Product class is missing
the @Override annotation. The readObject method is a special method that is used to customize the
deserialization process of an object. It must be declared as private, have no return type, and take a
single parameter of type ObjectInputStream. It must also be annotated with @Override to indicate
that it overrides the default behavior of the ObjectInputStream class. Without the @Override
annotation, the compiler will treat the readObject method as a normal method and not as a
deserialization hook. Therefore, the code fragment will produce a compilation
error. Reference:
Object Serialization - Oracle
, [ObjectInputStream (Java SE 17 & JDK 17) - Oracle]

vote your answer:
A
B
C
D
E
F
A 0 B 0 C 0 D 0 E 0 F 0
Comments
Question 9

Given:

What is the result?

  • A. Software Game Chess 0
  • B. Software Game Software Game Chese 2
  • C. Software game write error
  • D. Software Game Software Game chess 0
  • E. Software Game Chess 2
  • F. Software Game read error
Answer:

B


Explanation:
The answer is B because the code uses the writeObject and readObject methods of
the ObjectOutputStream and ObjectInputStream classes to serialize and deserialize the Game object.
These methods use the default serialization mechanism, which writes and reads the state of the
object’s fields, including the inherited ones. Therefore, the title field of the Software class is also
serialized and deserialized along with the players field of the Game class. The toString method of
the Game class calls the toString method of the Software class using super.toString(), which returns
the value of the title field. Hence, when the deserialized object is printed, it shows “Software Game
Software Game Chess 2”. Reference:
Oracle Certified Professional: Java SE 17 Developer
Java SE 17 Developer
OCP Oracle Certified Professional Java SE 17 Developer Study Guide
Serialization and Deserialization in Java with Example

vote your answer:
A
B
C
D
E
F
A 0 B 0 C 0 D 0 E 0 F 0
Comments
Question 10

Given the code fragments:

Which action prints Wagon : 200?

  • A. At line n1, implement the java.io, Serializable interface.
  • B. At line n3, replace readObject (0 with readLine().
  • C. At Line n3, replace Car with LuxurayCar.
  • D. At Line n1, implement the java.io.AutoCloseable interface
  • E. At line n2, in the main method signature, add throws IOException, ClassCastException.
  • F. At line n2, in the main method signature, add throws IoException, ClassNotFoundException.
Answer:

F


Explanation:
The code fragment is trying to read an object from a file using the ObjectInputStream class. This class
throws an IOException and a ClassNotFoundException. To handle these exceptions, the main method
signature should declare that it throws these exceptions. Otherwise, the code will not compile. If the
main method throws these exceptions, the code will print Wagon : 200, which is the result of calling
the
toString
method
of
the
LuxuryCar
object
that
was
written
to
the
file. Reference:
ObjectInputStream (Java SE 17 & JDK 17) - Oracle
,
ObjectOutputStream (Java SE 17 &
JDK 17) - Oracle

vote your answer:
A
B
C
D
E
F
A 0 B 0 C 0 D 0 E 0 F 0
Comments
Page 1 out of 4
Viewing questions 1-10 out of 50
Go To
page 2