Free 1Z0-829 sample questions

Real questions from the Java SE 17 Developer (OCP) practice bank, with the correct answer and an explanation for each one. No junk, no filler.

Try them in the simulator Same questions, with study, timed and flashcard modes.

Showing 10 of 20 free sample questions.

Question 1Choose one

A developer is building a system that processes different geometric shapes. The following `sealed` interface is defined: ```java sealed interface Shape permits Circle, Rectangle {} final class Circle implements Shape { /* ... */ } final class Rectangle implements Shape { /* ... */ } ``` Later, another developer in a different package tries to define a new shape: ```java // in another package public final class Triangle implements Shape { /* ... */ } ``` What is the result of this attempt?

Question 2Choose one

**Case Study** A financial services company is designing a system to model various types of accounts. The system must support `CheckingAccount`, `SavingsAccount`, and `InvestmentAccount`. A key architectural requirement is that the set of account types is fixed and cannot be extended by other development teams or third-party libraries. This ensures that all account processing logic can be handled exhaustively and safely within the core application. The architect wants to create a common supertype called `Account` that all specific account types will implement. The solution must enforce the closed hierarchy at compile time and should use modern Java features for conciseness and type safety. Which code snippet best models this domain according to the requirements? classDiagram direction LR class Account { > +getAccountNumber() +getBalance() } class CheckingAccount class SavingsAccount class InvestmentAccount Account <|.. CheckingAccount : implements Account <|.. SavingsAccount : implements Account <|.. InvestmentAccount : implements

Question 3Choose one

A financial data processing application uses a sealed interface `Transaction` with three implementing records: `Deposit`, `Withdrawal`, and `Transfer`. A method is designed to process a list of these transactions and calculate a risk score. Examine the following code: ```java sealed interface Transaction permits Deposit, Withdrawal, Transfer {} record Deposit(double amount) implements Transaction {} record Withdrawal(double amount) implements Transaction {} record Transfer(double amount, String recipient) implements Transaction {} public class TransactionProcessor { public int calculateRisk(Transaction tx) { return switch (tx) { case Deposit d -> { if (d.amount() > 10000) yield 2; yield 1; } case Withdrawal w -> { if (w.amount() > 5000) yield 3; yield 1; } // Missing Transfer case }; } } ``` What is the result of compiling the `TransactionProcessor` class?

Question 4Choose one

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?

Question 5Choose one

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? ```java 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"; }; } } ```

Question 6Choose one

**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

Question 7Choose one

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? ```java 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 -> "Login from " + le.ipAddress(); case LogoutEvent le -> "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

Question 8Choose one

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?

Question 9Choose 2

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)

Question 10Choose one

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?

10 more free samples are waiting

Create a free account to unlock the whole 1Z0-829 sample bank, or get full access to all 225 practice questions in the simulator.

Create account