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, define services, providers, and consumers.

    You are implementing a module descriptor module-info.java for a library named com.example.lib. A testing framework module, com.test.framework, must be able to use reflection on all members of the classes in the package com.example.lib.internal, including private ones. No module, including the framework, may compile against that package.

    Which directive should you use?

    Show answer & explanation

    Correct answer: B

    opens ... to com.test.framework gives only that module reflective access at run time, including private members. It does not export the package, so no module can compile against it.

  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
    
    """;
    

    The closing """ is on its own line, 4 spaces to the left of . How many spaces of indentation are removed from the tag line?

    Show answer & explanation

    Correct answer: A

    The compiler removes the smallest indentation among the content lines and the closing delimiter line. The closing delimiter is the least indented here. So its indentation is removed from every line, and keeps 4 spaces.

  3. Question 3Beginner

    Managing Concurrent Code Execution · Create both platform and virtual threads. Use both Runnable and Callable objects, manage the thread lifecycle, and use different Executor services and concurrent API to run tasks.

    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 including daylight saving time using Date-Time API.

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

    Which code snippet correctly achieves this?

    Show answer & explanation

    Correct answer: C

    Duration.between(t1, t2) holds the exact time from t1 to t2. toDays() returns the number of whole 24-hour days in it. Swapped arguments give a negative value, and Period works only with dates.

  5. Question 5Advanced

    Controlling Program Flow · Create program flow control constructs including if/else, switch statements and expressions, loops, and break and continue statements.

    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

    Each guarded record pattern comes before the unguarded case for the same record, so the guard is checked first. Envelope and Box cases together cover the sealed type, so no default is needed.

  6. Question 6Intermediate

    Working with Streams and Lambda expressions · Perform decomposition, concatenation, and reduction, and grouping and partitioning on sequential and parallel streams.

    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 both Runnable and Callable objects, manage the thread lifecycle, and use different Executor services and concurrent API to run tasks.

    Which method of the java.util.concurrent.Executors class creates an executor that runs each task on a virtual thread?

    Show answer & explanation

    Correct answer: B

    Executors.newVirtualThreadPerTaskExecutor() returns an ExecutorService that starts a new virtual thread for each task. The cached and work-stealing pools use platform threads. There is no newVirtualThreadPool() method.

  8. Question 8Intermediate

    Packaging and Deploying Java Code · Define modules and expose module content, including that by reflection, and declare module dependencies, 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

    provides with registers a service provider for ServiceLoader. The service interface comes after provides, and the implementation class comes after with.

Ready for the real thing?

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