[Mar 14, 2024] Free Oracle 1Z0-829 Exam Questions and Answer
Verified 1Z0-829 dumps Q&As Latest 1Z0-829 Download
Oracle 1Z0-829 certification exam is designed to test the skills and knowledge of developers who work with the Java SE 17 platform. Java SE 17 Developer certification is targeted towards experienced Java developers who are looking to demonstrate their skills and knowledge in the latest version of Java. Passing 1Z0-829 exam validates the developer's ability to work with Java SE 17 and is a valuable addition to their resume.
NEW QUESTION # 13
Given the code fragments:
Which action prints Wagon : 200?
- A. At line n2, in the main method signature, add throws IoException, ClassNotFoundException.
- B. At Line n3, replace Car with LuxurayCar.
- C. At Line n1, implement the java.io.AutoCloseable interface
- D. At line n3, replace readObject (0 with readLine().
- E. At line n2, in the main method signature, add throws IOException, ClassCastException.
- F. At line n1, implement the java.io, Serializable interface.
Answer: A
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
NEW QUESTION # 14
Assuming that the data, txt file exists and has the following content:
Text1
Text2
Text3
Given the code fragment:
What is the result?
- A. text1-text2-text3
text3 - B. text1-text2-text3
text1
text2
text3 - C. text1-
text2-
text3-
text3 - D. text1-text2-text3
A java.lang.indexoutofBoundsException is thrown.
Answer: A
Explanation:
Explanation
The answer is D because the code fragment reads the file "data.txt" and collects all the lines in the file into a single string, separated by hyphens. Then, it prints the resulting string. Next, it attempts to read the fourth line in the file (index 3) and print it. However, since the file only has three lines, an IndexOutOfBoundsException is thrown. References:
Oracle Certified Professional: Java SE 17 Developer
Java SE 17 Developer
OCP Oracle Certified Professional Java SE 17 Developer Study Guide
Read contents of a file using Files class in Java
NEW QUESTION # 15
Given the code fragment:
What is the result?
- A. 5000$60M6D
- B. $SIM6D
- C. PT5SPTIMP6D
- D. PT5000PT60MP6D
Answer: D
Explanation:
The code fragment is creating a Duration object with a value of 5000 milliseconds, then printing it. Then, it is creating another Duration object with a value of 60 seconds, then printing it. Finally, it is creating a Period object with a value of 6 days, then printing it. The output will be "PT5000PT60MP6D". Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html, https://docs.oracle.com/javase/8/docs/api/java/time/Period.html
NEW QUESTION # 16
Given the code fragment:
Which code line n1, obtains the java.io.Console object?
- A.

- B.

- C.

- D.

- E.

Answer: 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
NEW QUESTION # 17
Given the code fragment:
Which code line n1, obtains the java.io.Console object?
- A.

- B.

- C.

- D.

- E.

Answer: D
Explanation:
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. References:
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
NEW QUESTION # 18
Given the directory structure:
Given the definition of the Doc class:
Which two are valid definition of the wordDoc class?
- A. Package p1;
Public class wordDoc extends Doc () - B. Package p1;
Public non-sealed class wordDoc extends Doc () - C. Package p1, p2;
Public non-sealed class WordDoc extends Doc () - D. Package p1,
non-sealed abstract class WordDoc extends Doc () - E. Package p1;
Public final class WordDoc extends Doc () - F. Package p1, p2;
Public sealed class WordDoc extends Doc ()
Answer: B,E
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
NEW QUESTION # 19
Given:
What is the result?
- A. User name (EN - US)
- B. User name (EN)
- C. UserName
- D. User name (US)
- E. The program throws a MissingResourceException.
Answer: E
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)
NEW QUESTION # 20
Given the code fragments:
Which is true?
- A. The program prints an exception
- B. The program prints t1 : 1: t2 : 1: t1 : 1 : t2 : 1 : indefinitely
- C. The program prints t1 : 1: t2 : 1: t1 : t2 : 2 : in random order.
- D. The program prints t1 : 1 : t2: 1 : t1 : 2 : t2: 2:
Answer: D
Explanation:
The code creates two threads, t1 and t2, and starts them. The threads will print their names and the value of the Atomic Integer object, x, which is initially set to 1. The threads will then increment the value of x and print their names and the new value of x. Since the threads are started at the same time, the output will be in random order. However, the final output will always be t1 : 1 : t2: 1 : t1 : 2 : t2: 2: Reference: AtomicInteger (Java SE 17 & JDK 17) - Oracle
NEW QUESTION # 21
Given the course table:
Given the code fragment:
- A. false
- B. 0
- C. true
- D. 1
Answer: C
Explanation:
The code fragment will execute the update statement and set the course fee of the course with ID 1021 to 5000. The executeUpdate method returns an int value that indicates the number of rows affected by the SQL statement. In this case, only one row will be updated, so the result variable will be 1. The if statement will check if the result is greater than 0, which is true, and print "Updated successfully". Therefore, the output of the code fragment is true. Reference: https://education.oracle.com/products/trackp_OCPJSE17, https://mylearn.oracle.com/ou/learning-path/java-se-17-developer/99487, https://docs.oracle.com/en/java/javase/17/docs/api/java.sql/java/sql/Statement.html#executeUpdate(java.lang.String)
NEW QUESTION # 22
Given the code fragment:
Which code fragment returns different values?
- A. int sum = listOfNumbers. parallelStream () reduce ({m, n) -> m +n) orElse (5) +5;
- B. int sum = listOfNumbers. parallelStream () reduce (5, Integer:: sum) ;
- C. int sum = listOfNumbers. Stream () reduce (5, (a, b) -> a + b) ;
- D. int sum = listOfNumbers. Stream () reduce (0, Integer:: sum) + 5
- E. int sum = listOfNumbers. Stream () reduce ( Integer:: sum) ; +5;
Answer: E
Explanation:
Explanation
The answer is C because the code fragment uses a different syntax and logic for the reduce operation than the other options. The reduce method in option C takes a single parameter, which is a BinaryOperator that combines two elements of the stream into one. The method returns an Optional, which may or may not contain a value depending on whether the stream is empty or not. The code fragment then adds 5 to the result of the reduce method, regardless of whether it is present or not. This may cause an exception if the Optional is empty, or produce a different value than the other options if the Optional is not empty.
The other options use a different syntax and logic for the reduce operation. They all take two parameters, which are an identity value and a BinaryOperator that combines an element of the stream with an accumulator.
The method returns the final accumulator value, which is equal to the identity value if the stream is empty, or the result of applying the BinaryOperator to all elements of the stream otherwise. The code fragments then add
5 to the result of the reduce method, which will always produce a valid value.
For example, suppose listOfNumbers contains [1, 2, 3]. Then, option A will perform the following steps:
Initialize accumulator to identity value 5
Apply BinaryOperator Integer::sum to accumulator and first element: 5 + 1 = 6 Update accumulator to 6 Apply BinaryOperator Integer::sum to accumulator and second element: 6 + 2 = 8 Update accumulator to 8 Apply BinaryOperator Integer::sum to accumulator and third element: 8 + 3 = 11 Update accumulator to 11 Return final accumulator value 11 Add 5 to final accumulator value: 11 + 5 = 16 Option B will perform the same steps as option A, except using a lambda expression instead of a method reference for the BinaryOperator. Option D will perform the same steps as option A, except using parallelStream instead of stream, which may change the order of applying the BinaryOperator but not the final result. Option E will perform the same steps as option A, except using identity value 0 instead of 5.
Option C, however, will perform the following steps:
Apply BinaryOperator Integer::sum to first and second element: 1 + 2 = 3 Apply BinaryOperator Integer::sum to previous result and third element: 3 + 3 = 6 Return Optional containing final result value 6 Add 5 to Optional value: Optional.of(6) + 5 = Optional.of(11) As you can see, option C produces a different value than the other options, and also uses a different syntax and logic for the reduce operation. References Oracle Certified Professional: Java SE 17 Developer Java SE 17 Developer OCP Oracle Certified Professional Java SE 17 Developer Study Guide Guide to Stream.reduce()
NEW QUESTION # 23
Given the code fragment:
What is the result?
- A. 5000$60M6D
- B. $SIM6D
- C. PT5SPTIMP6D
- D. PT5000PT60MP6D
Answer: D
Explanation:
Explanation
The code fragment is creating a Duration object with a value of 5000 milliseconds, then printing it. Then, it is creating another Duration object with a value of 60 seconds, then printing it. Finally, it is creating a Period object with a value of 6 days, then printing it. The output will be "PT5000PT60MP6D". References:
https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html,
https://docs.oracle.com/javase/8/docs/api/java/time/Period.html
NEW QUESTION # 24
Given:
What is the result?
- A. Software Game Chess 2
- B. Software Game read error
- C. Software game write error
- D. Software Game Chess 0
- E. Software Game Software Game chess 0
- F. Software Game Software Game Chese 2
Answer: F
Explanation:
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".
References:
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
NEW QUESTION # 25
Given:
Which two should the module-info file include for it to represent the service provider interface?
- A. Exports com.transport.vehicle;
- B. Provides.com.transport.vehicle.cars.Car impl,CarImp1 to com.transport.vehicle.cars. Cars
- C. Requires cm.transport.vehicle,cars:
- D. exports com.transport.vehicle.cars.Car;
- E. Provides.com.transport.vehicle.cars.Car with com.transport.vehicle.cars. impt, CatImpI;
- F. Requires cm.transport.vehicle,cars:
- G. Exports com.transport.vehicle.cars;
Answer: D,E
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
NEW QUESTION # 26
Given the code fragment:
What is the result?
- A. Logged out at: 2021-0112T21:58:19.880z
- B. A compilation error occurs at Line n1.
- C. Logged out at: 2021-01-12T21:58:00z
- D. Can't logout
Answer: C
Explanation:
The code fragment is using the Java SE 17 API to get the current time and then truncating it to minutes. The result will be the current time truncated to minutes, which is why option B is correct. Reference:
https://education.oracle.com/products/trackp_OCPJSE17
https://mylearn.oracle.com/ou/learning-path/java-se-17-developer/99487
https://docs.oracle.com/javase/17/docs/api/java.base/java/time/Instant.html#truncatedTo(java.time.temporal.TemporalUnit)
NEW QUESTION # 27
Given the code fragment:
What is the result?
- A. 0
- B. 1
- C. 2
- D. 3
- E. 4
- F. 5
Answer: D
Explanation:
The code fragment is creating a string variable "a" with the value "Hello! Java". Then, it is printing the index of "Java" in "a". Next, it is replacing "Hello!" with "Welcome!" in "a". Then, it is printing the index of "Java" in "a". Finally, it is creating a new StringBuilder object "b" with the value of "a" and printing the index of "Java" in "b". The output will be 8109 because the index of "Java" in "a" is 8, the index of "Java" in "a" after replacing "Hello!" with "Welcome!" is 10, and the index of "Java" in "b" is 9. Reference: Oracle Java SE 17 Developer source and documents: [String (Java SE 17 & JDK 17)], [StringBuilder (Java SE 17 & JDK 17)]
NEW QUESTION # 28
Given the code fragment:
- A. True:false:true:true
- B. True:true:false:false
- C. True:false:true:false
- D. True:false:false:false
Answer: C
Explanation:
Explanation
The code fragment compares four pairs of strings using the equals() and intern() methods. The equals() method compares the content of two strings, while the intern() method returns a canonical representation of a string, which means that it returns a reference to an existing string with the same content in the string pool. The string pool is a memory area where strings are stored and reused to save space and improve performance. The results of the comparisons are as follows:
s1.equals(s2): This returns true because both s1 and s2 have the same content, "Hello Java 17".
s1 == s2: This returns false because s1 and s2 are different objects with different references, even though they have the same content. The == operator compares the references of two objects, not their content.
s1.intern() == s2.intern(): This returns true because both s1.intern() and s2.intern() return a reference to the same string object in the string pool, which has the content "Hello Java 17". The intern() method ensures that there is only one copy of each distinct string value in the string pool.
"Hello Java 17" == s2: This returns false because "Hello Java 17" is a string literal, which is automatically interned and stored in the string pool, while s2 is a string object created with the new operator, which is not interned by default and stored in the heap. Therefore, they have different references and are not equal using the == operator.
References: String (Java SE 17 & JDK 17) - Oracle
NEW QUESTION # 29
Given:
What is the result?
- A. Software Game Chess 2
- B. Software Game read error
- C. Software game write error
- D. Software Game Chess 0
- E. Software Game Software Game chess 0
- F. Software Game Software Game Chese 2
Answer: F
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
NEW QUESTION # 30
Given the course table:
Given the code fragment:
- A. false
- B. 0
- C. true
- D. 1
Answer: C
Explanation:
Explanation
The code fragment will execute the update statement and set the course fee of the course with ID 1021 to
5000. The executeUpdate method returns an int value that indicates the number of rows affected by the SQL statement. In this case, only one row will be updated, so the result variable will be 1. The if statement will check if the result is greater than 0, which is true, and print "Updated successfully". Therefore, the output of the code fragment is true. References: https://education.oracle.com/products/trackp_OCPJSE17,
https://mylearn.oracle.com/ou/learning-path/java-se-17-developer/99487,
https://docs.oracle.com/en/java/javase/17/docs/api/java.sql/java/sql/Statement.html#executeUpdate(java.lang.Str
NEW QUESTION # 31
Given the code fragment:
Which action sorts the book list?
- A. At line n1, convert books type to mutable ArrayList type.
- B. At Line n2, replace compareTo () with compare ().
- C. At Line n2, replace books,sort() with books.stream().sort(0.
- D. At Line n1, convert type to mutable array type.
Answer: B
Explanation:
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. References: Comparator (Java SE 17 & JDK 17), Comparable (Java SE 17 & JDK 17), Stream (Java SE 17 & JDK 17)
NEW QUESTION # 32
Which statement is true?
- A. thread in waiting state consumes CPU cycles.
- B. After the timed wait expires, the waited thread moves to the terminated state.
- C. IllegalStateException is thrown if a thread in waiting state is moved back to runnable.
- D. A thread in waiting state must handle InterrupedException.
Answer: D
Explanation:
A thread in waiting state is waiting for another thread to perform a particular action, such as calling notify() or notifyAll() on a shared object, or terminating a joined thread. A thread in waiting state can be interrupted by another thread, which will cause the waiting thread to throw an InterruptedException and return to the runnable state. Therefore, a thread in waiting state must handle InterruptedException, either by catching it or declaring it in the throws clause. Reference: Thread.State (Java SE 17 & JDK 17), [Thread (Java SE 17 & JDK 17)]
NEW QUESTION # 33
Given the code fragment:
What is the result?
- A. false 1
false 2 - B. false 1
ture 2 - C. falase 0
true 1 - D. true 1
false 2
Answer: C
Explanation:
The code fragment is comparing the values of a, b, and c using the < and > operators. The first comparison, d, is checking if a is less than b and greater than c. Since a is equal to 2, b is equal to -2, and c is equal to -4, this comparison will evaluate to true. The second comparison, e, is checking if a is greater than b and a is greater than c. Since a is equal to 2, b is equal to -2, and c is equal to -4, this comparison will evaluate to false. Therefore, the result will be true 1 false 2. Reference: Operators (The Java™ Tutorials > Learning the Java Language - Oracle
NEW QUESTION # 34
......
Use Real Dumps - 100% Free 1Z0-829 Exam Dumps: https://examcollection.vcetorrent.com/1Z0-829-valid-vce-torrent.html