1Z0-829 Sample Questions

1Z0-829 Sample Questions & Answers

Explores object-oriented design with classes and records, by far the largest share, plus primitives, text and date-time values, program flow, exceptions, concurrency, I/O, JDBC, the module system, arrays, collections, streams and lambda expressions.

Launch the full 1Z0-829 simulator →

Showing 10 of 20 free samples.

  1. Question 1Advanced

    Utilizing Java Object-Oriented Approach · Java Inheritance

    A developer is designing a system to model hierarchical configurations. A ConfigNode can contain other ConfigNode objects. The design must ensure that only specific, predefined types of nodes (FileNode, DirectoryNode, PropertyNode) can extend ConfigNode. Additionally, DirectoryNode itself must be extensible, but only by RootDirectoryNode. Which class and interface structure best achieves these requirements?

    Show answer & explanation

    Correct answer: B

    This solution correctly uses sealed classes to enforce the inheritance constraints. ConfigNode is sealed and explicitly permits only FileNode, DirectoryNode, and PropertyNode. FileNode and PropertyNode are final, preventing further extension as required. DirectoryNode is declared non-sealed, which breaks the sealing and allows any class, including RootDirectoryNode, to extend it. This perfectly matches all design requirements.

  2. Question 2Intermediate

    Utilizing Java Object-Oriented Approach · Java Inheritance

    A developer is modeling a system for handling financial transactions using a sealed interface. The goal is to ensure that all possible transaction types are handled in a switch expression without requiring a default case. Given the following sealed hierarchy, what is the problem with the processTransaction method?

    sealed interface Transaction permits Deposit, Withdrawal, FxTrade {}
    final record Deposit(double amount) implements Transaction {}
    final record Withdrawal(double amount) implements Transaction {}
    // FxTrade is a non-sealed class to allow for future extension
    non-sealed class FxTrade implements Transaction {}
    class SpotTrade extends FxTrade {}
    
    public class TransactionProcessor {
    public static String processTransaction(Transaction tx) {
    return switch (tx) {
    case Deposit d -> "Processing Deposit";
    case Withdrawal w -> "Processing Withdrawal";
    case FxTrade f -> "Processing FX Trade";
    };
    }
    }
    
    Show answer & explanation

    Correct answer: B

    This is the correct answer. Because FxTrade is declared as non-sealed, other classes (like SpotTrade or any other class in any package) can extend it. Therefore, the compiler cannot guarantee that all possible subtypes of Transaction are covered by the case labels. To fix this, the switch expression must include a default case to handle any unknown subtypes of FxTrade.

  3. Question 3Advanced

    Utilizing Java Object-Oriented Approach · Java Inheritance

    Case Study

    A development team at a logistics company is modeling various types of shipping containers. The requirements are as follows:

    1. There are three primary types of containers: Standard, Refrigerated, and OpenTop.
    2. All container types must have a capacity and a containerId.
    3. Refrigerated containers must also have a temperature setting.
    4. The system must be able to handle these specific container types exhaustively in switch expressions for processing logic.
    5. In the future, a subcontractor may need to introduce a new HeavyDuty container type that extends the Standard container's functionality. This new type should NOT break the exhaustiveness of existing switch statements.

    Which class hierarchy design best fulfills all these requirements using modern Java features?

    classDiagram direction LR class ShipmentProcessor { +process(Container c) } class Container { > +double capacity +String containerId } class Standard { +double capacity +String containerId } class Refrigerated { +double capacity +String containerId +double temperature } class OpenTop { +double capacity +String containerId } class HeavyDuty { +double maxLoad } Container <|.. Standard Container <|.. Refrigerated Container <|.. OpenTop Standard <|-- HeavyDuty ShipmentProcessor ..> Container : processes

    Show answer & explanation

    Correct answer: C

    This design correctly meets all requirements. sealed interface Container ensures that switch expressions can be exhaustive for the three primary types. Using records for Refrigerated and OpenTop is ideal for these immutable data carriers. Crucially, making Standard a non-sealed class explicitly allows it to be extended by other classes, such as HeavyDuty, fulfilling the extensibility requirement. Because HeavyDuty is not a direct permitted subtype of Container, existing switch statements over Container remain exhaustive and do not need to be updated, preventing code breakage.

  4. Question 4Intermediate

    Utilizing Java Object-Oriented Approach · Java Inheritance

    A developer is implementing a sealed interface to model different types of application events. A switch expression is used to process these events. What is the result of compiling and running the following code?

    sealed interface AppEvent permits LoginEvent, LogoutEvent, ErrorEvent {
    String getUserId();
    }
    
    final record LoginEvent(String userId, String ipAddress) implements AppEvent {}
    final record LogoutEvent(String userId, String reason) implements AppEvent {}
    final record ErrorEvent(String userId, String errorMsg) implements AppEvent {}
    
    public class EventProcessor {
    public String process(AppEvent event) {
    return switch (event) {
    case LoginEvent le -&gt; "Login from " + le.ipAddress();
    case LogoutEvent le -&gt; "Logout because " + le.reason();
    // Missing case for ErrorEvent
    };
    }
    }
    
    graph TD A[AppEvent] --> B(LoginEvent) A --> C(LogoutEvent) A --> D(ErrorEvent) style A fill:#f9f,stroke:#333,stroke-width:2px
    Show answer & explanation

    Correct answer: B

    One of the key benefits of combining sealed types with switch expressions is compile-time exhaustiveness checking. Because AppEvent is a sealed interface, the compiler knows all possible direct subtypes (LoginEvent, LogoutEvent, ErrorEvent). The switch expression must cover all these permitted subtypes or include a default case. Since the case for ErrorEvent is missing and there is no default branch, the compiler will report an error, preventing potential runtime errors from unhandled types.

  5. Question 5Intermediate

    Handling date, time, text, numeric and boolean values · Manipulate date, time, duration, period, instant and time-zone objects using Date-Time API

    A financial application needs to process transactions from different time zones. A developer writes the following code to handle a transaction timestamp from Tokyo and convert it to the system's default time zone. What is the outcome of executing this code snippet?

    Show answer & explanation

    Correct answer: C

    The code correctly uses the java.time API. LocalDateTime.atZone() is the correct way to combine a local date-time with a time zone, creating a ZonedDateTime. withZoneSameInstant() correctly converts this instant to another time zone. The program will print Tokyo: 10:00 and then the equivalent time in the system's default time zone, reflecting the offset difference.

  6. Question 6IntermediateSelect 2

    Packaging and deploying Java code and use the Java Platform Module System · Define modules and their dependencies, expose module content including for reflection. Define services, producers, and consumers

    A developer is creating a Java module for a billing service. The module com.example.billing needs to use a logging framework provided as a service. It also needs to expose its main API package com.example.billing.api but keep the implementation package com.example.billing.internal hidden. Which module-info.java file correctly defines these requirements? (Select TWO)

    Show answer & explanation

    Correct answers: A, D

    This is a correct definition. exports com.example.billing.api; makes the API package public, and uses com.example.logging.Logger; declares that this module consumes the Logger service, allowing it to discover and use implementations provided by other modules.

    This is also a correct definition. requires static indicates an optional dependency at compile time, which is a valid way to depend on a service provider module. The core requirements of exporting the API package (exports) and consuming the service (uses) are correctly stated.

  7. Question 7Advanced

    Managing concurrent code execution · Develop thread-safe code, using different locking mechanisms and concurrent API

    A developer is implementing a thread-safe counter. To avoid the overhead of explicit locking, they decide to use java.util.concurrent.atomic.AtomicInteger. Which statement accurately describes the primary mechanism that makes AtomicInteger thread-safe without traditional locks?

    Show answer & explanation

    Correct answer: C

    The core of AtomicInteger's lock-free thread safety is the Compare-And-Swap (CAS) instruction provided by the underlying CPU. A CAS operation is an atomic instruction that reads a memory location, compares its content with an expected value, and, only if they match, modifies the memory location's content to a new given value. This allows for non-blocking, optimistic updates, avoiding the performance costs and potential deadlocks of traditional locking.

  8. Question 8Intermediate

    Implementing Localization · Implement localization using locales, resource bundles, parse and format messages, dates, times, and numbers including currency and percentage values

    A developer needs to format monetary values for an e-commerce application that serves customers in Germany and the United States. Given the following code, what is the expected output?

    Show answer & explanation

    Correct answer: B

    NumberFormat.getCurrencyInstance(Locale) creates a formatter that correctly applies the currency symbol, grouping separators (comma vs. period), and decimal separator (period vs. comma) for the specified locale. For en_US, it formats as $12,345.67. For de_DE, it formats as 12.345,67 €, correctly using the period as a grouping separator, comma as a decimal separator, and placing the Euro symbol at the end (a common convention).

  9. Question 9Intermediate

    Working with Streams and Lambda expressions · Use Java object and primitive Streams, including lambda expressions implementing functional interfaces, to supply, filter, map, consume, and sort data

    A developer has a List &gt; and wants to get a List containing all non-empty string values. Which of the following stream pipelines correctly and most efficiently accomplishes this?

    Show answer & explanation

    Correct answer: B

    This is the most idiomatic and efficient solution. Since Java 9, Optional.stream() returns a stream of one element if the optional is present, or an empty stream if it is empty. The flatMap operation effectively unnests these streams, filtering out the empty ones and extracting the values from the present ones into a single Stream , which is then collected into a list.

  10. Question 10Advanced

    Utilizing Java Object-Oriented Approach · Java Inheritance

    Case Study:

    A logistics company is modernizing its package tracking system. The system needs to represent different types of packages, each with specific attributes. The requirements are as follows:

    1. There are three and only three types of packages: Standard, Express, and Fragile.
    2. No other package types should be permissible in the system to ensure strict domain modeling.
    3. A Standard package has a weight.
    4. An Express package has a weight and a priority level (an integer).
    5. A Fragile package has a weight and special handling instructions (a String).
    6. All package types should be immutable data carriers.

    A senior developer proposes using a combination of sealed interfaces and records to model this domain. The goal is to create a type-safe hierarchy that can be effectively processed, for example, in a switch expression for calculating shipping costs.

    Which code implementation best satisfies all the given requirements?

    Show answer & explanation

    Correct answer: B

    This solution perfectly meets all requirements. The sealed interface Package with a permits clause ensures that only Standard, Express, and Fragile can implement it, satisfying requirement #1 and #2. Using record for each package type makes them immutable data carriers with appropriate fields, satisfying requirements #3, #4, #5, and #6. This structure is ideal for modern, type-safe domain modeling and works perfectly with pattern matching in switch expressions.

Ready for the real thing?

The full 1Z0-829 simulator has every exam-style question, timed mode, and instant scoring.