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.
- 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.javafor a library namedcom.example.lib. A testing framework module,com.test.framework, must be able to use reflection on all members of the classes in the packagecom.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.frameworkgives only that module reflective access at run time, including private members. It does not export the package, so no module can compile against it. - 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 thetag 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. - 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 Threadrequires implementing a specific sub-interface ofRunnable.Show answer & explanation
Correct answer: B
Virtual threads run standard
java.lang.Runnabletasks. There is no special interface required. You can create them usingThread.ofVirtual().start(runnable). - 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 timet1and end timet2(bothInstant, witht2later thant1). 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.
- 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:
- Envelopes under 100g cost $2.
- Envelopes 100g or more cost $4.
- 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.
- 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
Streampipeline to process a list ofOrderobjects. 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
groupingBytakes a classifier function (Order::getStatus) and a downstream collector.Collectors.counting()is the correct downstream collector to count elements in each group. - 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.Executorsclass 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 nonewVirtualThreadPool()method. - 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.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 & explanation
Correct answer: B
provides withregisters a service provider forServiceLoader. The service interface comes afterprovides, and the implementation class comes afterwith.
Ready for the real thing?
The full 1Z0-830 simulator has every exam-style question, timed mode, and instant scoring.