IT Certifications · 1Z0-831

Oracle Java SE 25 Developer Professional Exam Practice Test

The Oracle Java SE 25 Developer Professional Exam practice page centers on interpreting Java code and predicting its behavior. The available questions sample packages, arrays, integer arithmetic, loops, exception handling, `HashMap`, interface default methods, `Optional`, and `switch` expressions. These topics call for precise reasoning about types, references, library methods, and control flow.

Exam overview

Exam providerOracle
Exam code1Z0-831
CategoryIT Certifications

About the Oracle Java SE 25 Developer Professional Exam

Java development requires more than recognizing syntax: developers must determine which declarations are accessible, how objects and arrays behave when referenced from multiple variables, and which branch or handler runs. Practice with collection and API questions by checking the contracts of types such as `HashMap` and `Optional`, including how null values affect results. For code-tracing problems, evaluate expressions using Java’s type rules, follow loop updates in order, and distinguish array length from string length. Questions involving interface default methods and `switch` expressions also reward careful attention to compile-time rules and returned values. Building these habits supports debugging, code review, and implementation decisions where a small difference in evaluation order or API behavior changes the result.

Sample Practice Questions

Review a selection from this exam's published US Practice Tests practice bank.

Question 1

Which statement about Java packages is correct?

  1. AA package declaration, when present, must be the first non-comment statement in a compilation unit.
  2. BA package declaration must appear after all import declarations.
  3. CEvery Java source file must declare a package.
  4. DA package declaration can appear inside a class body.
Show answerCorrect answer: A

A package declaration, if included, precedes import declarations and top-level type declarations. A source file may omit a package declaration, and package declarations do not appear inside class bodies.

Question 2

What is the value of `first` after this code runs? `int first = 0; try { int[] numbers = {6, 8}; first = numbers[1]; } catch (ArrayIndexOutOfBoundsException ex) { first = -1; }`

  1. A0
  2. B-1
  3. C6
  4. D8
Show answerCorrect answer: D

Array indexing starts at 0, so `numbers[1]` refers to the second element, 8. No exception is thrown, and the catch block does not execute.

Question 3

Which statement about a `HashMap` is correct?

  1. AIt guarantees that entries are iterated in insertion order.
  2. BIt permits one `null` key and multiple `null` values.
  3. CIt rejects any key whose value is `null`.
  4. DIt sorts entries by their keys.
Show answerCorrect answer: B

A `HashMap` permits a single `null` key and any number of `null` values. It does not guarantee insertion-order iteration or sort its entries.

Question 4

Which statement about an interface's default method is correct?

  1. AIt has a method body in the interface and can be inherited by implementing classes.
  2. BIt must be declared with the `static` modifier.
  3. CIt cannot be overridden by an implementing class.
  4. DIt can be declared only in an abstract class.
Show answerCorrect answer: A

An interface default method has an implementation, introduced with the `default` keyword, and implementing classes can inherit it or provide an override.

Question 5

What is the value of `length` after this code runs? `String[] names = new String[3]; int length = names.length;`

  1. A0
  2. B2
  3. C3
  4. DThe code does not compile because the elements are uninitialized.
Show answerCorrect answer: C

An array's `length` is fixed when it is created. This array has three slots; reference elements are initialized to `null`, which does not prevent reading its length.

Question 6

What is the result of evaluating `Optional.ofNullable(null).isEmpty()`?

  1. A`true`
  2. B`false`
  3. CIt throws `NullPointerException`.
  4. DThe expression does not compile.
Show answerCorrect answer: A

`Optional.ofNullable(null)` produces an empty `Optional`. Its `isEmpty()` method therefore returns `true`.

Question 7

What is printed by this code? `int[] values = {2, 4}; int[] alias = values; alias[0] = 9; System.out.println(values[0]);`

  1. A2
  2. B4
  3. C9
  4. DThe code does not compile
Show answerCorrect answer: C

An array variable holds a reference to an array object. Assigning `values` to `alias` copies that reference, so both variables refer to the same array. Updating an element through `alias` is visible through `values`.

How to use this practice test

Access is free. Each session draws up to 20 random questions from the available bank of 50 and displays results afterward. Use a session to identify code-tracing errors, then revisit the relevant Java rule—such as array references, integer division, exception flow, or `Optional` behavior—before trying another set.

Preparation tips

  • Trace array assignments and mutations separately: note whether a statement changes an array element or only reassigns a reference.
  • Evaluate expressions using Java’s declared types; for integer arithmetic, calculate division before assigning the result to an `int`.
  • For exception questions, follow statements in order and identify whether an exception is thrown before the `catch` block can run.
  • Compare API behavior precisely: check `HashMap` key and value rules, and distinguish `Optional.ofNullable(null)` from `Optional.of(...)`.
  • For interface and `switch` questions, inspect method declarations, branch labels, and whether each expression path produces a compatible result.
Official sourceOfficial exam page ↗