Limited-Time Offer: Enjoy 50% Savings! Coupon code: 50OFF Use it at checkout
Skip to content

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

Last updated: · 11 practice questions with answers and explanations

Page: 1 / 9 Total 50 questions

Want more questions? Get Premium Access.

Question 1

New Single answer

Topic: Handling date, time, text, numeric and boolean values

Skill tested: Use ZonedDateTime and Duration to calculate elapsed time across a daylight-saving transition.

A scheduling service stores a departure as a ZonedDateTime in Europe/Paris and must calculate the instant exactly 24 elapsed hours later. A developer currently adds one calendar day, but a production run crossing the spring daylight-saving transition ends at a different elapsed time than required. The stored value is 2024-03-30T12:00+01:00[Europe/Paris]. The service must preserve the original time zone and represent precisely 24 hours of elapsed time, rather than the same local clock time on the next calendar date. Which implementation meets the requirement?

Correct Answer: D. Add Duration.ofDays(1) to the ZonedDateTime.
Explanation:

Duration represents an amount of elapsed time, and adding Duration.ofDays(1) advances the underlying timeline by exactly 24 hours. Across this transition the result is 2024-03-31T13:00+02:00[Europe/Paris], because the local offset changes. Period.ofDays(1) is calendar-based and preserves local calendar progression, so it does not guarantee 24 elapsed hours. LocalDateTime arithmetic likewise advances by a calendar day, and manually changing the day-of-month while retaining an offset ignores the zone rules.

Question 2

New Single answer

Topic: Controlling Program Flow

Skill tested: Apply switch-expression rules for case labels, yield, and exhaustive result production.

A rules engine maps an integer status code to a descriptive string. The code must handle 200 and 201 identically, return a distinct message for 404, and produce a fallback message for all other integer values. The team wants to use a switch expression and retain a compact arrow-label form. A candidate implementation groups 200 and 201 under one arm, uses a block for 404 to perform a small calculation before returning its result, and includes a default arm. Which implementation compiles and fulfills these requirements?

Correct Answer: A. `String result = switch (code) { case 200, 201 -> "success"; case 404 -> { String message = "missing"; yield message; } default -> "other"; };`
Explanation:

A switch expression can group multiple case constants with commas and use arrow rules. When an arrow rule has a block, `yield` supplies the value of that rule; each possible result path must produce a value. The colon-style labels in B use statement-group syntax and do not provide the required expression results as written. `break` does not return a value from a switch expression, and D's block completes without yielding a value. The default arm makes the expression exhaustive for an int selector.

Question 3

New Multiple answers

Topic: Utilizing Java Object-Oriented Approach

Skill tested: Apply sealed-type restrictions and pattern matching for instanceof with safe subtype-specific access.

A payment library defines a sealed interface `Payment` that permits only `CardPayment` and `CashPayment`. The interface is public, and its permitted implementations are compiled in the same module. A reporting method receives a `Payment` reference and needs to use the card token only when the runtime object is a `CardPayment`; otherwise it should report that no token is available. The codebase targets Java 17 and should avoid an explicit cast that could fail at runtime. Select TWO implementations or statements that satisfy these requirements.

Correct Answer: C. Use `if (payment instanceof CardPayment card) { return card.token(); }` and handle the non-card path separately.; E. Declare `sealed interface Payment permits CardPayment, CashPayment {}` and declare each permitted class as `final`.
Explanation:

Pattern matching for `instanceof` both checks the runtime type and introduces the pattern variable within the true branch, avoiding an unchecked cast. A permitted direct subtype of a sealed type must be declared `final`, `sealed`, or `non-sealed`; making both implementations final is valid and prevents further subclassing. `non-sealed` is an option, not a requirement. D names a nested type that the scenario does not define. A non-null Payment might be a CashPayment, so the cast in E can still throw ClassCastException.

Question 4

New Single answer

Topic: Handling Exceptions

Skill tested: Use try-with-resources and understand resource closure when exceptions occur.

A batch importer opens a `BufferedReader` and parses each input line. If parsing fails, the original parsing exception must remain the primary exception, while any failure during reader closure must remain available as a suppressed exception. The reader must be closed whether processing completes normally or exits exceptionally. The code should also avoid a manual `finally` block that risks replacing the parse failure. Which approach best satisfies these requirements?

Correct Answer: C. Open the reader in a try-with-resources statement and let the parsing exception propagate.
Explanation:

A resource declared in try-with-resources is closed when the block exits, including when parsing throws. If both the body and close operation fail, the body exception remains primary and the close exception is recorded as suppressed, preserving the failure that matters most. A manual finally block can allow a close failure to replace the parsing exception unless carefully managed. C explicitly reverses the desired priority, while D hides failures and reports successful completion despite an unsuccessful import.

Question 5

New Single answer

Topic: Working with Arrays and Collections

Skill tested: Choose collection implementations that preserve insertion order and provide constant-time key lookup.

A configuration service stores unique feature names and their associated settings. It must preserve the order in which entries were first added when iterating, replace a setting when the same feature name is added again, and support efficient lookup by feature name. The service does not need sorted keys or concurrent access. Which collection design best meets these requirements without maintaining a separate ordering structure?

Correct Answer: A. Use a `LinkedHashMap`.
Explanation:

LinkedHashMap combines key-based lookup and replacement behavior with predictable insertion-order iteration. Adding a value for an existing key replaces its mapping; it does not create a duplicate key. HashMap does not guarantee iteration order, so sorting would produce key order rather than insertion order. TreeMap also orders by key, not insertion time. An ArrayList preserves sequence but requires a search for lookup and needs extra logic to enforce unique feature names.

Question 6

New Multiple answers

Topic: Working with Streams and Lambda expressions

Skill tested: Build a stream pipeline that groups records and reduces numeric values per group.

A billing report receives a sequential stream of immutable `Charge` records, each containing a `String department` and a `long cents`. It must produce a `Map` containing the total cents for each department, including negative adjustments, and should use standard stream collectors rather than mutable external state. Select TWO stream operations or collector forms that can correctly complete the report.

Correct Answer: A. Use `Collectors.groupingBy(Charge::department, Collectors.summingLong(Charge::cents))` as the terminal collector.; E. Use `Collectors.toMap(Charge::department, Charge::cents, Long::sum)` as the terminal collector.
Explanation:

`groupingBy` with `summingLong` forms one total for each department and supports negative adjustments. `toMap` with a merge function, here `Long::sum`, also combines duplicate department keys correctly. `partitioningBy` always divides values into two Boolean groups, not arbitrary department names. The two-argument `toMap` throws an exception on duplicate keys rather than summing them. A single `mapToLong().sum()` produces one overall total and loses the department grouping.

Question 7

New Single answer

Topic: Packaging and deploying Java code and use the Java Platform Module System

Skill tested: Configure JPMS service providers and consumers with uses and provides directives.

A modular application discovers implementations of a public `com.acme.spi.Codec` service through `ServiceLoader`. The API module contains the service interface, and the application module performs discovery. A separate provider module contains `com.acme.impl.FastCodec`, which has a public no-argument constructor. The provider class need not be directly accessible to ordinary source code in the application. Which module declarations correctly enable discovery?

Correct Answer: A. The application declares `uses com.acme.spi.Codec;`; the provider declares `provides com.acme.spi.Codec with com.acme.impl.FastCodec;` and makes the provider package available to the module system.
Explanation:

A consumer module declares `uses` for the service type, while a provider module declares `provides ... with ...` for its implementation. JPMS can instantiate a provider for ServiceLoader without requiring the provider package to be exported for ordinary source-level access; the provider package must be available to the module system as required by the service-provider declaration. `exports` exposes packages but does not itself register a service, and `opens` is for reflective access rather than service consumption. Assigning `provides` to the API module misplaces the provider declaration.

Question 8

New Multiple answers

Topic: Managing concurrent code execution

Skill tested: Coordinate task completion and cancellation using ExecutorService and Future results.

A document-processing service submits independent `Callable` tasks to a fixed thread pool. The request handler must wait for all submitted tasks, collect their results, and initiate orderly shutdown after submissions are complete. If the handler is interrupted while waiting, it must initiate shutdown and preserve the interrupt status before returning. Select TWO statements that correctly implement or describe this behavior using Java's executor and future APIs.

Correct Answer: B. When interrupted, call `shutdown()` and restore the status with `Thread.currentThread().interrupt()` before returning.; D. Call `Future.get()` for each submitted task to wait for its completion and retrieve its result.
Explanation:

`Future.get()` blocks until the associated task completes, then returns its result or reports task failure. If interrupted, the handler should respond to the interruption rather than silently swallow it; restoring the interrupt flag preserves the signal for higher-level code. The scenario also calls for shutdown on that path. `shutdown()` is the orderly shutdown method, but A alone does not address result collection or interruption handling. `shutdownNow()` only attempts to interrupt active tasks and returns tasks that never commenced; it does not guarantee completion.

Question 9

New Single answer

Topic: Using Java I/O API

Skill tested: Use Files.walk with try-with-resources to traverse a directory tree safely.

A maintenance utility must locate regular files ending in `.log` beneath a configured directory, including nested directories, and process each matching path. The tree may contain many entries, and the utility must not leave directory resources open after processing, including when file processing throws an exception. Symbolic links should not be followed as part of the traversal. Which approach is most appropriate?

Correct Answer: C. Use `Files.walk(root)` in try-with-resources, filter with `Files::isRegularFile` and the filename suffix, then process the results.
Explanation:

`Files.walk` traverses a directory tree and returns a Stream that must be closed; try-with-resources ensures closure even if processing fails. Filtering to regular files avoids processing directories, and omitting FOLLOW_LINKS means symbolic links are not followed during traversal. `Files.list` visits only the immediate directory. `File.listFiles()` does not provide the same managed stream resource behavior and requires custom recursive traversal. D explicitly follows symbolic links and does not filter out directories.

Question 10

New Single answer

Topic: Accessing databases using JDBC

Skill tested: Use prepared statements and JDBC transactions to execute atomic multi-step updates.

An order service must insert an order header and several order-line rows as one atomic operation. The database connection is obtained from a `DataSource`. Values come from an external request, and if any line insert fails, the header and all previously inserted lines must be undone. The service must not build SQL by concatenating request values. Which sequence is most appropriate?

Correct Answer: B. Disable auto-commit, execute the header and line inserts with PreparedStatements, commit only after all succeed, and roll back on failure.
Explanation:

Disabling auto-commit groups the header and line inserts into one transaction. PreparedStatements bind request values separately from SQL text, reducing injection risk and handling values correctly. Committing only after every insert succeeds makes the operation atomic; rolling back on failure undoes all changes in the transaction. With auto-commit enabled, A can leave partial data and a compensating delete may itself fail. C commits partial work row by row, and D both uses unsafe concatenation and commits too early.

Question 11

New Single answer

Topic: Implementing Localization

Skill tested: Format currency using locale-specific NumberFormat without hard-coding presentation conventions.

A retail application stores a price as a numeric amount and displays it to users in their selected locale. The same amount must appear with the appropriate currency symbol, grouping separators, decimal conventions, and currency fraction digits for that locale. The application must not hard-code a currency symbol or infer the locale from the server environment. Which approach is most appropriate?

Correct Answer: C. Create `NumberFormat.getCurrencyInstance(userLocale)` and format the numeric amount.
Explanation:

`NumberFormat.getCurrencyInstance(Locale)` applies locale-sensitive currency presentation, including separators, symbol placement, and currency-specific fraction digits. The amount remains numeric until formatting, avoiding assumptions tied to the server locale. A generic number formatter does not by itself apply currency conventions, and manually appending a code does not reproduce localized presentation. A fixed dollar pattern ignores user locale and currency rules. DateTimeFormatter formats temporal values, not numeric currency amounts.