1Z0-830 Sample Questions

1Z0-830 Sample Questions & Answers

Checks your knowledge of object lifecycle, inheritance and polymorphism, the single biggest weight, plus streams and lambdas, arrays, collections, exceptions, the module system, concurrency, localization, program flow, and handling primitive, text and date-time values.

Launch the full 1Z0-830 simulator →

Showing 8 of 17 free samples.

  1. Question 1Intermediate

    Packaging and Deploying Java Code · Define modules and expose module content, including that by reflection, and declare module dependencies

    You are implementing a module descriptor module-info.java for a library named com.example.lib. You need to ensure that the package com.example.lib.internal is accessible via reflection to a specific testing framework module com.test.framework, but not accessible to other modules at compile time or runtime.

    Which directive should you use?

    Show answer & explanation

    Correct answer: D

    The opens directive allows deep reflection (access to private members) on the package's types but does not make the package's types available for compile-time or static linkage. The qualified export (to com.test.framework) restricts this reflective access only to the specified module.

  2. Question 2Intermediate

    Handling Date, Time, Text, Numeric and Boolean Values · Manipulate text, including text blocks, using String and StringBuilder classes

    Consider the following Text Block usage in Java 21:

    String html = """
    
    Hello, World
    
    """;
    

    If the opening """ is on line 1, and the closing """ is indented to align with the start of , how many spaces of indentation are removed from the tag line?

    Show answer & explanation

    Correct answer: C

    The compiler determines the 'common whitespace prefix' to strip based on the position of the closing delimiter and the non-empty lines. If the closing delimiter is aligned with , that level of indentation defines the baseline. Any indentation beyond that baseline (like the extra spaces for and ) is preserved.

  3. Question 3Beginner

    Managing Concurrent Code Execution · Create both platform and virtual threads

    True or False: In Java 21, creating a Virtual Thread requires implementing a specific sub-interface of Runnable.

    Show answer & explanation

    Correct answer: B

    Virtual threads run standard java.lang.Runnable tasks. There is no special interface required. You can create them using Thread.ofVirtual().start(runnable).

  4. Question 4Intermediate

    Handling Date, Time, Text, Numeric and Boolean Values · Manipulate date, time, duration, period, instant and time-zone objects

    You need to perform a calculation using java.time.Duration. You have a start time t1 and end time t2 (both Instant). You want to calculate the number of whole days between them.

    Which code snippet correctly achieves this?

    Show answer & explanation

    Correct answer: D

    Duration.between(t1, t2) creates a Duration object representing the time elapsed. The toDays() method converts this duration to the number of whole 24-hour periods (days).

  5. Question 5Advanced

    Controlling Program Flow · Create program flow control constructs including switch statements and expressions

    Case Study: Logistics System

    A logistics company is migrating its tracking system to Java 21. The system processes packages using a sealed hierarchy:

    sealed interface Package permits Box, Envelope {}
    record Box(int weight, int h, int w, int d) implements Package {}
    record Envelope(int weight) implements Package {}
    

    The shipping cost calculation requires specific logic:

    1. Envelopes under 100g cost $2.
    2. Envelopes 100g or more cost $4.
    3. Boxes are calculated as weight * 0.5, but if the volume (h*w*d) exceeds 10,000, there is a $5 surcharge.

    You need to implement this using a single switch expression with record patterns.

    Which code snippet correctly implements this logic?

    Show answer & explanation

    Correct answer: A

    This snippet correctly uses record patterns with guards (when). It handles both Envelope cases (specific first, then general). It handles the Box surcharge case first using the guard to check volume, then the standard Box case. The use of var _ (unnamed variables) is valid in Java 21 for components we don't need in the guard/expression.

  6. Question 6Intermediate

    Working with Streams and Lambda Expressions · Perform decomposition, concatenation, and reduction, and grouping and partitioning

    You are creating a Stream pipeline to process a list of Order objects. Each order has a status. You want to group the orders by status and count them. Which collector should you use?

    Show answer & explanation

    Correct answer: D

    groupingBy takes a classifier function (Order::getStatus) and a downstream collector. Collectors.counting() is the correct downstream collector to count elements in each group.

  7. Question 7Beginner

    Managing Concurrent Code Execution · Create both platform and virtual threads... use different Executor services

    Which of the following classes in the java.util.concurrent package creates a virtual thread executor?

    Show answer & explanation

    Correct answer: C

    This method creates an ExecutorService that creates a new virtual thread for each task submitted to it.

  8. Question 8Intermediate

    Packaging and Deploying Java Code · Define modules... define services, providers, and consumers

    You are designing a module com.app.security that provides an implementation of a service com.app.api.Cipher. The implementation class is com.app.security.AesCipher.

    Which directive in module-info.java correctly declares this provision?

    Show answer & explanation

    Correct answer: B

    The provides directive specifies the service interface (com.app.api.Cipher) and the with clause specifies the implementation class (com.app.security.AesCipher).

Ready for the real thing?

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