SaveMyCert
Log in
5 of 5 free questions left today·for 30 a day
1Z0-831 practice

Free 1Z0-831 practice questions

Drill exam-realistic Oracle Certified Professional: Java SE 25 Developer questions by domain, with an explanation on every option — not just the right one. 5 fully worked examples are further down this page, answers included.

Question bank
953
across 10 domains
Free, no account
5/day
a free account allows 30 a day
Real exam
50 Qs
120 min · pass 68%
Explanations
Every option
right and wrong

Build a practice session

5 free questions left today.

Domains

How many?

Mode

Ready when you are

10 fresh questions drawn across all domains, in Learn mode.

Focused review

Every question you answer incorrectly, and every question you flag while practising, is saved here automatically. Finish a session and you can come back to re-drill just those.

5 sample 1Z0-831 questions, fully explained

Real questions from the 1Z0-831 bank, with the answer key and the reasoning behind every option. Read them, then go back up the page and try the rest.

Question 1Handling Date, Time, Text, Numeric and Boolean Values

A method declares two local variables:byte a = 10; byte b = 20;Which statement, added after them, compiles?

Choose one.

  • a
    byte c = (byte) (a + b); Correct

    The parentheses make the cast apply to the whole int sum, so the result is narrowed explicitly and the assignment compiles (it prints 30).

  • b
    byte c = (byte) a + b;

    The cast applies to a alone, then a + b is promoted to int again, so assigning the int sum to a byte fails with 'possible lossy conversion from int to byte'.

  • c
    byte c = a + (byte) b;

    Casting b to byte changes nothing: byte + byte is still promoted to int, and an int expression that is not a constant cannot be assigned to a byte.

  • d
    byte c = (byte) a + (byte) b;

    Casting each operand still leaves the addition itself promoted to int, so the sum is an int and the assignment fails to compile.

The concept

Binary numeric promotion turns byte, short and char operands into int before any arithmetic operator runs.

Why that’s the answer

a + b has type int even though both operands are bytes, and b and a are not constants, so the sum needs an explicit cast. A cast binds tighter than +, so it only narrows the whole sum when the sum is in parentheses. Every other form casts an operand, which is then promoted back to int by the addition.

How to reason it out
  1. Note that b and a are bytes but not final constants.
  2. Apply promotion: byte + byte produces an int.
  3. Check what each cast actually covers; a cast binds tighter than +.
  4. Only a cast around the whole sum turns the int back into a byte.

Exam tip: byte + byte is an int; cast the whole expression, not the operands.

Java Primitives, Wrapper Classes, Operators and Casting (1Z0-831) — the lesson that teaches this.

Question 2Implementing Program Flow Control Using Decision and Looping Constructs

Given:public class Main { public static void main(String[] args) { int a = 5, b = 10; if (a > 3) if (b < 5) System.out.print("X"); else System.out.print("Y"); System.out.print("Z"); } }What is the result?

Choose one.

  • a
    Z

    This is what you get if the else is read as belonging to the outer if, as the indentation suggests. Java ignores indentation: the else pairs with the inner if.

  • b
    YZ Correct

    The else binds to the nearest unmatched if, the inner if (b < 5). a > 3 is true and b < 5 is false, so the inner else prints Y, then Z is printed.

  • c
    XZ

    X prints only when b < 5, and b is 10, so the inner condition is false.

  • d
    Compilation fails

    Nested if statements without braces are legal; the else simply attaches to the closest if that has no else yet.

The concept

Without braces, an else always pairs with the closest preceding if that does not already have an else (the dangling-else rule). Indentation has no meaning to the compiler.

Why that’s the answer

The code is laid out to suggest the else belongs to if (a > 3). The compiler pairs it with if (b < 5) instead. a > 3 is true, so the inner if runs; b < 5 is false, so its else prints Y. The final print is outside both ifs and prints Z, giving YZ. Reading the else as the outer one's gives Z, which is the trap.

How to reason it out
  1. Ignore indentation and match each else to the nearest if without an else.
  2. Evaluate the outer condition a > 3: true, so the inner if statement runs.
  3. Evaluate b < 5: false, so the inner else prints Y.
  4. The last print is unconditional and prints Z.

Exam tip: An else belongs to the nearest unmatched if; use braces when you mean otherwise.

Java Flow Control: if/else, switch and Loops (1Z0-831) — the lesson that teaches this.

Question 3Applying Object-Oriented Principles in Java Programs

Given:class Box { int size; Box(int size) { this.size = size; } } public class Main { public static void main(String[] args) { Box b = new Box(); System.out.println(b.size); } }What is the result?

Choose one.

  • a
    0

    0 would be the default value of size, but no Box object can be created this way, so nothing runs.

  • b
    An exception is thrown at runtime

    The problem is found by the compiler; the program never starts, so no runtime exception can occur.

  • c
    The program prints nothing

    A program that fails to compile does not run at all; this would need main to run and skip the print.

  • d
    Compilation fails Correct

    Box declares a constructor taking an int, so the compiler adds no no-argument constructor and new Box() has nothing to call.

The concept

The compiler adds a default no-argument constructor only when a class declares no constructors at all.

Why that’s the answer

Box declares Box(int size). Because at least one constructor is written, the compiler does not generate the default no-argument constructor. The call new Box() therefore matches no constructor and javac reports "constructor Box in class Box cannot be applied to given types; required: int". The 0 distractor assumes a default constructor still exists alongside the written one.

How to reason it out
  1. Count the constructors Box declares: one, taking an int.
  2. Recall that a default constructor is generated only when none are declared.
  3. Match new Box() against the declared constructors: no match.
  4. A failed constructor match is a compile-time error.

Exam tip: Write any constructor and the free no-argument one disappears; add Box() yourself if callers need it.

Java Classes, Records, Constructors and Initializers (1Z0-831) — the lesson that teaches this.

Question 4Implementing Exception Handling in Java Applications

Given:public class Main { static void load(String id) { if (id.isBlank()) { throw new Exception("no id"); } System.out.println("loaded " + id); } public static void main(String[] args) { load("42"); } }What is the result?

Choose one.

  • a
    loaded 42

    The program never runs. javac rejects load() first, because it throws a checked exception it neither catches nor declares.

  • b
    Compilation fails Correct

    new Exception(...) is a checked exception. load() has no catch for it and no throws clause, so javac reports: unreported exception Exception; must be caught or declared to be thrown.

  • c
    An Exception is thrown at runtime

    The throw would only run for a blank id, and it never gets the chance: the checked-exception rule is enforced at compile time, not at runtime.

  • d
    Nothing is printed

    Silence would need the program to compile and skip the print. It does not compile at all.

The concept

A checked exception (Exception and its subclasses other than RuntimeException) must be caught or declared wherever it can be thrown.

Why that’s the answer

The compiler checks every throw statement and call for checked exceptions. Exception itself is checked, so the throw inside load() needs either a surrounding catch or a throws Exception clause on load(). Neither exists, so compilation fails, even though the branch would not run for the id 42. The runtime-exception answer assumes Java checks this only when the throw executes; it does not.

How to reason it out
  1. Classify the thrown type: Exception is checked.
  2. Look for a catch in load() that handles it: none.
  3. Look for a throws clause on load(): none.
  4. Conclude that javac rejects the method, whatever the argument.

Exam tip: Checked exceptions are a compile-time rule: catch them or declare them, even on branches that never run.

Java Exception Handling: try/catch/finally, try-with-resources and Custom Exceptions (1Z0-831) — the lesson that teaches this.

Question 5Using Arrays and Collections to Store and Retrieve Data

Given:public class Main { public static void main(String[] args) { int[] counts = new int[3]; String[] names = new String[2]; boolean[] flags = new boolean[1]; System.out.println(counts[2] + " " + names[1] + " " + flags[0] + " " + counts.length); } }What is the result?

Choose one.

  • a
    0 false 2

    A String element defaults to null, not to the empty string, and length is the element count 3, not the last index 2.

  • b
    0 null false 2

    counts was created with new int[3], so its length is 3; 2 is the last valid index, not the length.

  • c
    Compilation fails

    Only local variables must be assigned before use; array elements get default values, so reading counts[2] compiles.

  • d
    0 null false 3 Correct

    Array elements are always initialised: 0 for int, null for references, false for boolean; length is the size given to new, 3.

The concept

Creating an array with new allocates every element and sets it to the type's default value: 0, 0.0, false, '\u0000' or null.

Why that’s the answer

new int[3] creates three int elements set to 0, new String[2] two references set to null, and new boolean[1] one false. Unlike local variables, array elements never need explicit initialisation, so the code compiles. String concatenation turns the null reference into the text null, and length reports the number of elements, 3.

How to reason it out
  1. Note that each array is created with new and a size.
  2. Apply the default value for each element type.
  3. Remember that null concatenates as the text null.
  4. Read length as the size, not the last index.

Exam tip: Array elements default to 0, false or null; length is the element count.

Java Arrays and Collections: List, Set, Map, Deque and Sequenced Collections (1Z0-831) — the lesson that teaches this.

The 1Z0-831 question bank, by domain

The bank is built to the exam's own weighting, so the practice you get reflects the marks that are actually on offer — not whichever domain was easiest to write questions for.

Published 1Z0-831 practice questions per exam domain
DomainExam weightTopicsQuestions
Handling Date, Time, Text, Numeric and Boolean Values11%3105
Implementing Program Flow Control Using Decision and Looping Constructs8%175
Applying Object-Oriented Principles in Java Programs18%7175
Implementing Exception Handling in Java Applications8%175
Using Arrays and Collections to Store and Retrieve Data8%175
Processing Data Using Streams and Lambda Expressions9%286
Packaging and Deploying Java Code9%286
Implementing Multithreading for Concurrent Code Execution11%3105
Performing Input and Output Operations Using the Java I/O API11%3105
Developing Applications with Localization Support7%166
Total100%24953

Practise 1Z0-831 one domain at a time

How 1Z0-831 questions are worded

Most 1Z0-831 questions are not asking whether you can recall a definition. They describe a situation and ask which option satisfies it — so the skill being tested is reading the requirement precisely and eliminating options that fail it.

Single-response vs multiple-response

A single-response question has exactly one right answer. A multiple-response question tells you how many to pick ("Choose TWO") and there is no partial credit — getting one of the two right scores nothing. Read that instruction before you read the options.

Read the last line first

The final sentence is the actual question; everything before it is scenario. Read it first, then read the scenario knowing what you are looking for. It stops you from building an answer in your head that the question never asked for.

Hunt for the qualifier

Most scenarios turn on one word — MOST cost-effective, LEAST operational overhead, with the LEAST latency, without changing application code. Two options are frequently both technically correct, and the qualifier is the only thing separating them.

Eliminate, then choose

Distractors are almost always real Oracle services doing a real job — just not this job. Rule out the ones that break a stated constraint before you compare what's left. On a question you truly don't know, eliminating two options turns a guess into a coin flip.

Practise 1Z0-831 from your browser

The SaveMyCert Chrome extension opens a daily drill of 5 1Z0-831 questions in the side panel, with the full explanation behind every answer. No account needed.

Get the Chrome extension (opens in a new tab)

Beyond 1Z0-831 practice

1Z0-831 practice questions: your questions

Yes. You can answer 5 questions a day with no account at all, and a free account raises that to 30 a day across the full 953-question 1Z0-831 bank, with an explanation on every option. Pro removes the daily cap entirely.

Source

Exam structure, domain weights and scoring on this page come from the official 1Z0-831 exam guide.