Limited-Time Offer: Enjoy 50% Savings! Ends in 00h 00m 00s Coupon code: 50OFF
Skip to content

Free Oracle Java SE 17 Developer 1Z0-829 Exam Questions

Page: 1 / 9 Total 50 questions

Want more questions? Get Premium Access.

Question 1

Given:

What is the result

Correct Answer: C. UnDefined
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


Question 2

Given the course table:

Given the code fragment:

Correct Answer: C. true
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)


Question 3

Which statement is true about migration?

Correct Answer: B. Every module is moved to the module path in a bottom-up migration.
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


Question 4

Given:

Which two modifications enable the code to print Open Close?

A)

B)

C)

D)

E)

Correct Answer: B. Option B; E. Option E
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''.


Question 5

Given:

What is the result?

Correct Answer: B. Software Game Software Game Chese 2
Explanation:

The answer is B because the code uses thewriteObjectandreadObjectmethods of theObjectOutputStreamandObjectInputStreamclasses to serialize and deserialize theGameobject. These methods use the default serialization mechanism, which writes and reads the state of the object's fields, including the inherited ones. Therefore, thetitlefield of theSoftwareclass is also serialized and deserialized along with theplayersfield of theGameclass. ThetoStringmethod of theGameclass calls thetoStringmethod of theSoftwareclass usingsuper.toString(), which returns the value of thetitlefield. 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


Question 6

Given:

and the code fragment:

Correct Answer: A. 300.00 CellPhone,ToyCar,Motor,Fan
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