






























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!































































Exam Reference: Oracle Certified Professional: Java SE 21 Developer (1Z0-830) — Effective 2026 2026 Exam Focus: The 1Z0-830 exam validates proficiency in Java SE 21 , the latest Long-Term Support (LTS) release. Key topics include:
var list = List.of(1, 2, 3, 4, 5); var result = list.stream() .filter(n - > n % 2 == 0) .map(n - > n * 2) .reduce(0, (a, b) - > a + b); System.out.println(result); } } A) 6 B) 12 C) 20 D) Compilation fails Answer: B Rationale: The stream filters even numbers (2, 4), maps each to double its value (4, 8), then reduces by summing (0 + 4 + 8 = 12). List.of() creates an immutable list, but the stream operations are fine. var correctly infers the type. The answer is
.forEach(System.out::print); list.stream() .forEach(System.out::print); } } A) 123123 B) 123 C) Compilation fails D) An exception is thrown at runtime Answer: A Rationale: Each stream is a new pipeline created from the same list. The code creates two separate streams, each of which is consumed by the forEach terminal operation. Since each stream is independent, both print "123", resulting in "123123". Option B would be the output of a single stream. Option C is incorrect — the code compiles. Option D is incorrect — streams can be reused as long as a new stream is created each time. Question 4 Given the following record definition, which statement is true? java record Point(int x, int y) {} A) Point is a subclass of java.lang.Record B) Point has a default constructor with no parameters C) The fields x and y are private and final D) Point can be extended by another class Answer: C Rationale: Records are implicitly final classes with private final fields for each component. The fields x and y are private and final. Records extend java.lang.Record (A is incorrect — they extend Record, not subclass it). Records have a canonical constructor with all parameters, not a no-arg constructor
(B is incorrect). Records are implicitly final and cannot be extended (D is incorrect). Question 5 Which of the following correctly uses a record pattern in a switch expression? A) java switch (obj) { case Point(int x, int y) - > System.out.println("x: " + x + ", y: " + y); default - > System.out.println("Unknown"); } B) java switch (obj) { case Point p - > System.out.println(p.x() + ", " + p.y()); default - > System.out.println("Unknown"); } C) java if (obj instanceof Point(int x, int y)) { System.out.println("x: " + x + ", y: " + y); } D) Both A and C are valid record pattern usages Answer: D Rationale: Both A and C demonstrate valid record pattern syntax. In A, the record pattern Point(int x, int y) is used in a switch expression, deconstructing the Point record into its components. In C, the same pattern is used in
C) They are only available for I/O-bound tasks D) They are created using the new VirtualThread() constructor Answer: B Rationale: Virtual Threads are lightweight threads that enable high concurrency with minimal overhead. They are designed for I/O-bound tasks but are not limited to them (C is incorrect). They complement, not replace, platform threads (A is incorrect). Virtual Threads are typically created using Thread.startVirtualThread() or Executors.newVirtualThreadPerTaskExecutor (), not directly with new VirtualThread() (D is incorrect). Question 8 Given the following code, what is the result? java public class Main { public static void main(String[] args) { var result = switch (3) { case 1 - > "one"; case 2 - > "two"; case 3 - > "three"; default - > "unknown"; }; System.out.println(result); } } A) one B) two C) three D) Compilation fails Answer: C
Rationale: The switch expression matches 3 to the case 3 branch and returns "three". The arrow syntax (->) is used for switch expressions, which return a value. This is valid Java code. Option A is for 1, B for 2, and D is incorrect — the code compiles. Question 9 Which of the following is a characteristic of Sequenced Collections in Java 21? A) They provide a unified API for collections with a defined encounter order B) They replace all existing collection interfaces C) They are only available for List implementations D) They do not support reverse order operations Answer: A Rationale: Sequenced Collections provide a unified API for collections that have a defined encounter order, including List, Deque, and SortedSet. They do not replace existing collection interfaces (B is incorrect). They apply to multiple collection types, not just List (C is incorrect). They support reverse order operations via reversed() (D is incorrect). Question 10 What is the output of the following code? java public class Main { public static void main(String[] args) { var nums = List.of(1, 2, 3, 4, 5); var result = nums.stream() .filter(n - > n > 3) .findFirst() .orElse(0); System.out.println(result);
requires com.example.app.api; } D) java @Module(name = "com.example.app") public class AppModule { } Answer: A Rationale: The correct module declaration uses the module keyword followed by the module name and a body with exports and requires directives. Option B uses export instead of exports (singular is incorrect). Option C uses requires which is for dependencies, not exposing APIs. Option D shows an incorrect annotation- based approach — modules are declared in module-info.java files, not with annotations. Question 12 Given the following code, what is the result? java public class Main { public static void main(String[] args) { Optional opt = Optional.ofNullable(null); System.out.println(opt.orElse("default")); } } A) null B) default C) An exception is thrown D) Compilation fails Answer: B
Rationale: Optional.ofNullable(null) creates an empty Optional. orElse("default") returns the default value when the Optional is empty. Option A (null) would be the result of orElse(null) or get() on an empty Optional. Option C would occur if orElseThrow() was used. Option D is incorrect — the code compiles. Question 13 Which of the following is true about Pattern Matching for switch in Java 21? A) It only works with primitive types B) It allows switch to match on type patterns and null values C) It requires the default case to be always present D) It is only available for enum types Answer: B Rationale: Pattern Matching for switch allows matching on type patterns and handling null values explicitly. It works with reference types, not just primitives (A is incorrect). The default case is not always required — it depends on exhaustiveness (C is incorrect). It works beyond enum types (D is incorrect). Question 14 What is the output of the following code? java public class Main { public static void main(String[] args) { var numbers = new ArrayList(); numbers.add(1); numbers.add(2); numbers.add(3); numbers.remove(1); System.out.println(numbers);
public void process() throws Exception { // method body } D) Both A and C Answer: D Rationale: Both A and C correctly declare methods that throw checked exceptions using the throws keyword. A declares IOException and C declares the broader Exception. Option B uses throw (used for throwing an exception, not declaring one) and is syntactically incorrect. Both A and C are valid, making D the correct answer. Question 16 Given the following code, what is the result? java public class Main { public static void main(String[] args) { var list = new ArrayList<>(List.of(1, 2, 3)); var result = list.stream() .map(n - > n * 2) .collect(Collectors.toList()); System.out.println(result); } } A) [1, 2, 3] B) [2, 4, 6] C) [1, 2, 3, 1, 2, 3] D) Compilation fails Answer: B
Rationale: The stream maps each element to double its value: 1→2, 2→4, 3→6. The result is [2, 4, 6]. The original list is mutable (ArrayList), but the stream operations do not modify it. Option A is the original list. Option C would be the result of concatenating two lists. Option D is incorrect — the code compiles (requires import java.util.stream.Collectors). Question 17 Which of the following is a key characteristic of Records in Java? A) Records are mutable by default B) Records provide a compact syntax for data carrier classes C) Records can extend other classes D) Records do not have accessor methods Answer: B Rationale: Records provide a compact syntax for creating data carrier classes with automatically generated constructor, accessors, equals(), hashCode(), and toString(). Records are immutable by default (A is incorrect). Records are implicitly final and cannot extend other classes (C is incorrect). Records have accessor methods named after their components (D is incorrect). Question 18 What is the output of the following code? java public class Main { public static void main(String[] args) { try { throw new RuntimeException("Error"); } catch (RuntimeException e) { System.out.println("Caught: " + e.getMessage()); } finally { System.out.println("Finally");
public static void main(String[] args) { var result = Stream.of("a", "b", "c") .reduce("", (a, b) - > a + b); System.out.println(result); } } A) abc B) a b c C) [a, b, c] D) Compilation fails Answer: A Rationale: reduce("", (a, b) - > a + b) concatenates the stream elements. Starting with an empty string, it adds "a", then "b", then "c", resulting in "abc". Option B would be the result of Collectors.joining(" "). Option C would be the result of toString() on a list. Option D is incorrect — the code compiles. Question 21 Which of the following is true about Virtual Threads and the Executors.newVirtualThreadPerTaskExecutor() method? A) It creates a fixed-size thread pool B) It creates a new virtual thread for each task C) It is only available in Java 17 D) It creates platform threads Answer: B Rationale: Executors.newVirtualThreadPerTaskExecutor() creates an executor that starts a new virtual thread for each submitted task. Virtual Threads are introduced in Java 21, not Java 17 (C is incorrect). Virtual Threads are lightweight and do not use a fixed pool (A is incorrect). They are virtual, not platform threads (D is incorrect).
Question 22 What is the output of the following code? java public class Main { public static void main(String[] args) { var s = "Hello"; var result = s.transform(String::toUpperCase) .transform(str - > str + " World"); System.out.println(result); } } A) HELLO WORLD B) Hello World C) HELLO D) Compilation fails Answer: A Rationale: String.transform() applies a function to the string. First, String::toUpperCase converts "Hello" to "HELLO". Then, the lambda appends " World", resulting in "HELLO WORLD". Option B would be the result without the toUpperCase transformation. Option C would be the result of only the first transformation. Option D is incorrect — the code compiles. Question 23 Which of the following correctly declares a generic method? A) java public T process(T value) { return value;
var list = List.of(1, 2, 3, 4, 5); var result = list.stream() .skip(2) .limit(2) .collect(Collectors.toList()); System.out.println(result); } } A) [1, 2] B) [3, 4] C) [4, 5] D) [1, 2, 3] Answer: B Rationale: skip(2) skips the first two elements (1, 2), leaving [3, 4, 5]. limit(2) takes the first two elements from the remaining stream, resulting in [3, 4]. Option A would be the result of limit(2) without skip. Option C would be the result of skip(3). Option D would be the result of limit(3). Question 25 Which of the following is a characteristic of Sealed Classes in Java? A) They allow any class to extend them B) They restrict which classes can extend or implement them C) They are only available for interfaces D) They are the same as final classes Answer: B Rationale: Sealed classes and interfaces restrict which classes can extend or implement them using the permits clause. They do not allow any class to extend them (A is incorrect). They apply to both classes and interfaces (C is incorrect). Unlike final classes, sealed classes allow a controlled set of subclasses (D is incorrect).
Question 26 What is the output of the following code? java public class Main { public static void main(String[] args) { var numbers = new int[]{1, 2, 3, 4, 5}; var sum = 0; for (var n : numbers) { sum += n; } System.out.println(sum); } } A) 10 B) 15 C) 20 D) Compilation fails Answer: B Rationale: The enhanced for-loop iterates over the array and sums all elements: 1