Skip to content

1Z0-830 Java SE 21 Developer Professional Practice Questions

Prepare for 1Z0-830 with more than an answer.

253 questions in the full set17 sample questionsUpdated Jan 25, 2026
Exam fee
$245 USD
Level
Professional
Valid for
Does not expire
Domains covered on the exam 10
  1. Handling Date, Time, Text, Numeric and Boolean Values12%
  2. Controlling Program Flow10%
  3. Using Object-Oriented Concepts in Java25%
  4. Handling Exceptions8%
  5. Working with Arrays and Collections10%
  6. Working with Streams and Lambda Expressions15%
  7. Packaging and Deploying Java Code8%
  8. Managing Concurrent Code Execution12%
  9. Using Java I/O API8%
  10. Implementing Localization7%
  1. 1

    What happens if a switch pattern matching block covers all possible subtypes of a sealed interface but does not include a default case?

    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. 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_LINKS makes Files.walk follow symbolic links. By default, it does not follow them. LinkOption.NOFOLLOW_LINKS is a different type, so Files.walk does not accept it.

  3. 3

    Which statement about try-with-resources is 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. 4

    When using Math.round(double a), what is the return type?

    Show answer details

    Correct answer: C

    Math.round(double) returns a long. Math.round(float) returns an int.

  5. 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 + b is associative and does not depend on shared mutable state, making it safe for parallel execution. The identity 0 is correct for addition.

  6. 6

    A financial application uses a sealed interface Transaction to represent various payment methods. The interface permits three record classes: CreditCard, BankTransfer, and DigitalWallet. 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. 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 synchronized block is pinned to its carrier. If it blocks there, the carrier blocks too. With ReentrantLock, the virtual thread unmounts while it waits, and the carrier runs other virtual threads.

  8. 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].

Create an account to continue.