1Z0-830 sample questions with answers
10 free 1Z0-830 sample questions across the exam's domains, each with its answer and an explanation. No account needed.
1Z0-830 sample questions
Oracle Certified Professional: Java SE 21 Developer (1Z0-830), Oracle.
Question 1
Domain: Handling Date, Time, Text, Numeric and Boolean Values
What does LocalDate.of(2024, 1, 31).plusMonths(1) return?
- 2024-03-02
- 2024-02-28
- 2024-02-29
- A DateTimeException because 31 February is invalid
Show the answer
Answer: C. 2024-02-29
plusMonths adds the months and then, if the day-of-month is invalid for the resulting month, adjusts it to the last valid day; 2024 is a leap year, so the result is 29 February. Rolling over into March is the tempting wrong answer, but LocalDate clamps to the end of the month instead of overflowing.
Checked against: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/time/LocalDate.html#plusMonths(long)
Question 2
Domain: Controlling Program Flow
String s = null; switch (s) { case "a" -> System.out.print("a"); default -> System.out.print("other"); }What happens when this code runs with s set to null?
- other is printed
- Nothing is printed
- A NullPointerException is thrown
- It does not compile because a String switch cannot be null
Show the answer
Answer: C. A NullPointerException is thrown
A switch without a case null label throws NullPointerException when the selector is null; the default label does not match null. To handle null, Java 21 lets you add case null or case null, default. The compile-error option is wrong because null checking is a run-time matter and the code is valid.
Checked against: https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-14.11.3
Question 3
Domain: Using Object-Oriented Concepts in Java
Which member causes a compile-time error when added to the body of record Point(int x, int y)?
- private int cachedHash;
- static final Point ORIGIN = new Point(0, 0);
- public double distance() { return Math.hypot(x, y); }
- record Pair(Point a, Point b) {}
Show the answer
Answer: A. private int cachedHash;
A record's state is fixed by its components, so it cannot declare instance fields; static fields, instance methods and nested types are all allowed. The static field is the tempting wrong answer, but static members do not add per-instance state and are permitted.
Checked against: https://docs.oracle.com/javase/specs/jls/se21/html/jls-8.html#jls-8.10.2
Question 4
Domain: Handling Exceptions
class Res implements AutoCloseable { String n; Res(String n) { this.n = n; System.out.print("open" + n + " "); } public void close() { System.out.print("close" + n + " "); } } try (Res a = new Res("A"); Res b = new Res("B")) { System.out.print("body "); throw new RuntimeException(); } catch (RuntimeException e) { System.out.print("catch "); } finally { System.out.print("finally"); }What is printed?
- openA openB body closeB closeA catch finally
- openA openB body closeA closeB catch finally
- openA openB body catch closeB closeA finally
- openA openB body catch finally closeB closeA
Show the answer
Answer: A. openA openB body closeB closeA catch finally
Resources are closed in the reverse order of their declaration, and they are closed before any catch or finally block of the try-with-resources statement runs. Placing catch before the close calls is the common mistake; the resources are already closed when the handler executes.
Checked against: https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-14.20.3.2
Question 5
Domain: Working with Arrays and Collections
What does Collections.sort produce for a mutable list containing banana, Apple, cherry and apple?
- [Apple, apple, banana, cherry]
- [banana, cherry, Apple, apple]
- [Apple, banana, cherry, apple]
- [apple, Apple, cherry, banana]
Show the answer
Answer: A. [Apple, apple, banana, cherry]
String's natural ordering compares UTF-16 code units, and uppercase letters (A is 65) sort before lowercase ones (a is 97), so Apple comes first and then the lowercase words alphabetically. [Apple, banana, cherry, apple] wrongly places apple last, but a-p-p sorts before b-a-n and c-h-e.
Checked against: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/String.html#compareTo(java.lang.String)
Question 6
Domain: Working with Streams and Lambda Expressions
What does collecting an empty Stream<String> with Collectors.partitioningBy(s -> s.length() > 1) return?
- {}
- {false=[], true=[]}
- {false=[]}
- Optional.empty
Show the answer
Answer: B. {false=[], true=[]}
partitioningBy always returns a map containing both the false and true keys, each mapped to the downstream result, even when no elements exist. {} is the answer for groupingBy, which only creates keys for groups that actually occur.
Checked against: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/Collectors.html#partitioningBy(java.util.function.Predicate)
Question 7
Domain: Packaging and Deploying Java Code
Which command compiles every module under src, where each module has its own subdirectory named after the module, into separate module directories under out?
- javac -d out --module-path src $(find src -name "*.java")
- javac -d out -sourcepath src -m com.acme.api,com.acme.app
- javac --module-source-path src -m com.acme.app
- javac -d out --module-source-path src -m com.acme.api,com.acme.app
Show the answer
Answer: D. javac -d out --module-source-path src -m com.acme.api,com.acme.app
In multi-module mode, --module-source-path locates each module's sources in a subdirectory named after the module, -m selects the modules to compile, and -d is required to receive one output directory per module. Omitting -d is the tempting slip, but javac requires an output directory in multi-module mode.
Checked against: https://docs.oracle.com/en/java/javase/21/docs/specs/man/javac.html
Question 8
Domain: Managing Concurrent Code Execution
What does declaring a field volatile guarantee?
- Compound actions such as count++ on the field become atomic
- Only one thread at a time can execute a method that reads the field
- The field's value is cached per thread for faster access
- A write by one thread is visible to subsequent reads of that field by other threads
Show the answer
Answer: D. A write by one thread is visible to subsequent reads of that field by other threads
volatile establishes a happens-before relationship between a write and later reads of the same variable, preventing stale reads. It does not make count++ atomic, because that is still a separate read and write that another thread can interleave.
Checked against: https://docs.oracle.com/javase/specs/jls/se21/html/jls-8.html#jls-8.3.1.4
Question 9
Domain: Using Java I/O API
What does Path.of("/a/b/../c/./d").normalize() return?
- /a/b/c/d
- /a/c/d
- /c/d
- /a/b/../c/d
Show the answer
Answer: B. /a/c/d
normalize removes . elements and removes each .. together with the non-.. name element before it, so b/.. cancels out. /a/b/c/d is tempting if you think only . is removed; normalize is purely syntactic and does not check the file system.
Checked against: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Path.html#normalize()
Question 10
Domain: Implementing Localization
What does NumberFormat.getInstance(Locale.GERMANY).parse("1.234,5") return?
- 1.2345
- 1.234
- It throws ParseException
- 1234.5
Show the answer
Answer: D. 1234.5
German formatting uses a full stop for grouping and a comma as the decimal separator, so "1.234,5" parses to the number 1234.5. Parsing with Locale.US would stop at the comma and return 1.234.
Checked against: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/text/NumberFormat.html#parse(java.lang.String)
More practice
A 20-question practice sampler is free with an account; Pro adds the full question bank and timed mock exams.
1Z0-830 course and practice exam: Oracle Java SE 21 Developer Professional: the exam guide, with the format, cost, pass mark and domains from the vendor.