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
You are designing a module
com.app.securitythat provides an implementation of a servicecom.app.api.Cipher. The implementation class iscom.app.security.AesCipher.Which directive in
module-info.javacorrectly declares this provision?Show answer details
Correct answer: A
The
providesdirective specifies the service interface (com.app.api.Cipher) and thewithclause specifies the implementation class (com.app.security.AesCipher). - 2
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: A
If the compiler can verify that a sealed hierarchy is exhaustively covered by the case labels (i.e., all permitted subtypes are handled), a
defaultcase is not required. - 3
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: A
FileVisitOption.FOLLOW_LINKSis the enum constant used to request that symbolic links be followed during file traversal. - 4
Which statement about
try-with-resourcesis TRUE regarding the order of closing resources?Show answer details
Correct answer: A
Resources declared in the
tryclause are closed in the reverse order of their creation/declaration. This ensures that if Resource B depends on Resource A, B is closed before A. - 5
When using
Math.round(double a), what is the return type?Show answer details
Correct answer: A
Math.round(double)returns along.Math.round(float)returns anint. - 6
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: A
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. - 7
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: B
Switch expressions must be exhaustive. Since
Transactionis a sealed interface permittingCreditCard,BankTransfer, andDigitalWallet, all subtypes must be covered. The provided code handlesCreditCard(both high value and standard) andBankTransfer, but it fails to handleDigitalWallet, causing a compilation error. - 8
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: B
In Java 21, using
synchronizedblocks or methods inside a virtual thread can cause the virtual thread to be 'pinned' to its carrier thread if it performs a blocking operation (like I/O) while holding the monitor. This prevents the carrier thread from executing other virtual threads.ReentrantLockdoes not suffer from this pinning behavior and allows the virtual thread to unmount properly during blocking wait states.
