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
You are implementing a module descriptor
module-info.javafor a library namedcom.example.lib. You need to ensure that the packagecom.example.lib.internalis accessible via reflection to a specific testing framework modulecom.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
opensdirective 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. - 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 thetag 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 forand) is preserved. - Question 3Beginner
Managing Concurrent Code Execution · Create both platform and virtual threads
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
You need to perform a calculation using
java.time.Duration. You have a start timet1and end timet2(bothInstant). 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. ThetoDays()method converts this duration to the number of whole 24-hour periods (days). - 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:
- 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
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 ofvar _(unnamed variables) is valid in Java 21 for components we don't need in the guard/expression. - Question 6Intermediate
Working with Streams and Lambda Expressions · Perform decomposition, concatenation, and reduction, and grouping and partitioning
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 different Executor services
Which of the following classes in the
java.util.concurrentpackage creates a virtual thread executor?Show answer & explanation
Correct answer: C
This method creates an
ExecutorServicethat creates a new virtual thread for each task submitted to it. - Question 8Intermediate
Packaging and Deploying Java Code · Define modules... 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
The
providesdirective specifies the service interface (com.app.api.Cipher) and thewithclause 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.