1Z0-830 Java SE 21 Developer Professional Practice Questions
Prepare for 1Z0-830 with more than an answer.
- Exam fee
- $245 USD
- Level
- Professional
- Valid for
- Does not expire
Domains covered on the exam 10
- Handling Date, Time, Text, Numeric and Boolean Values12%
- Controlling Program Flow10%
- Using Object-Oriented Concepts in Java25%
- Handling Exceptions8%
- Working with Arrays and Collections10%
- Working with Streams and Lambda Expressions15%
- Packaging and Deploying Java Code8%
- Managing Concurrent Code Execution12%
- Using Java I/O API8%
- Implementing Localization7%
- 1
What happens if a
switchpattern matching block covers all possible subtypes of a sealed interface but does not include adefaultcase?Show answer details
Correct answer: C
When the cases cover every permitted subtype of the sealed interface, the switch is exhaustive. No default is needed. A null selector would throw NullPointerException, not MatchException.
- 2
You are using
java.nio.file.Files.walk(Path start, int maxDepth, FileVisitOption... options)to traverse a directory structure. You want to ensure the traversal follows symbolic links.Which option should you pass?
Show answer details
Correct answer: C
FileVisitOption.FOLLOW_LINKSmakesFiles.walkfollow symbolic links. By default, it does not follow them.LinkOption.NOFOLLOW_LINKSis a different type, soFiles.walkdoes not accept it. - 3
Which statement about
try-with-resourcesis TRUE regarding the order of closing resources?Show answer details
Correct answer: A
Resources are closed in the reverse order of their declaration. A resource opened later may depend on one opened earlier, so the later one is closed first.
- 4
When using
Math.round(double a), what is the return type?Show answer details
Correct answer: C
Math.round(double)returns along.Math.round(float)returns anint. - 5
You have a list of integers and want to use a parallel stream to compute the sum of squares.
int sum = numbers.parallelStream() .mapToInt(i -> i * i) .reduce(0, (a, b) -> a + b);Is this operation thread-safe and correct?
Show answer details
Correct answer: B
The reduction operation
(a, b) -> a + bis associative and does not depend on shared mutable state, making it safe for parallel execution. The identity0is correct for addition. - 6
A financial application uses a sealed interface
Transactionto represent various payment methods. The interface permits three record classes:CreditCard,BankTransfer, andDigitalWallet. You are writing a method to process these transactions using a switch expression with pattern matching.public sealed interface Transaction permits CreditCard, BankTransfer, DigitalWallet {} public record CreditCard(String pan, double amount) implements Transaction {} public record BankTransfer(String iban, double amount) implements Transaction {} public record DigitalWallet(String id, double amount) implements Transaction {} // In a service class: public String process(Transaction t) { return switch(t) { case CreditCard c when c.amount() > 1000 -> "High Value CC"; case CreditCard c -> "Standard CC"; case BankTransfer b -> "Bank Transfer"; // Missing case }; }Which statement is true regarding the compilation of this code?
Show answer details
Correct answer: D
A switch expression over a sealed interface must cover every permitted subtype or have a default. No case handles DigitalWallet, so the compiler rejects the switch. The when guard is a standard Java 21 feature.
- 7
You are developing a high-throughput web server using Java 21's Virtual Threads. You need to protect a shared resource using a locking mechanism. However, you want to avoid 'pinning' the virtual thread to the carrier thread, which can degrade performance during blocking operations.
Which locking approach should you prefer?
Show answer details
Correct answer: A
In Java 21, a virtual thread in a
synchronizedblock is pinned to its carrier. If it blocks there, the carrier blocks too. WithReentrantLock, the virtual thread unmounts while it waits, and the carrier runs other virtual threads. - 8
Review the following code snippet that uses the new Sequenced Collections API introduced in Java 21:
import java.util.*; public class SequenceTest { public static void main(String[] args) { SequencedCollection sc = new ArrayList (); sc.addFirst("Alpha"); sc.addLast("Omega"); sc.addFirst("Beta"); System.out.println(sc.getFirst() + "-" + sc.getLast()); System.out.println(sc.reversed()); } }What is the output of this program?
Show answer details
Correct answer: D
ArrayList is a List, and List is a SequencedCollection in Java 21. The calls build [Beta, Alpha, Omega]. So getFirst is Beta and getLast is Omega. reversed() returns a reverse-order view, which prints [Omega, Alpha, Beta].
