Sign in
Home/Oracle/Java SE 17 Developer (1Z0-829)/Free questions

Java SE 17 Developer (1Z0-829) — Free Practice Questions

10 free sample questions from a bank of 66, with the correct answers and explanations. No signup required — start practising right now.

1Given the code fragment: and Which is true?
Java SE 17 Developer (1Z0-829) question 1Java SE 17 Developer (1Z0-829) question 1
  • The program prints t1 : 1 : t2 : 1: t1 : 2 : t2 : 2 : in random order.
  • The program prints t1 : 1 : t2 : 1: t1 : 2 : t2 : 2 :
  • The program prints t1 : 1 : t2 : 1: t1 : 1 : t2 : 1 : indefinitely.
  • The program prints an exception.
Answer: A

The short version

Answer A: the program prints t1 : 1 : t2 : 1 : t1 : 2 : t2 : 2 : in random order.

Key concepts

  • Thread scheduling and interleaving
  • Concurrent output ordering is nondeterministic
  • No exception or infinite loop on this fragment

Why A is correct

Settled answer A is corroborated (community 100%). The fragment runs two threads printing the shown sequence, and thread interleaving makes the order random rather than fixed.

Why the others are wrong

  • B: wrong because it claims a fixed deterministic order, ignoring thread scheduling.
  • C: wrong because there is no indefinite 1/1 loop in the fragment.
  • D: wrong because no exception is produced by this code.

1z0-829 exam tip

For 1z0-829, if two threads print without synchronization, choose the random/unpredictable order option.

2Given: What is the result?
Java SE 17 Developer (1Z0-829) question 2
  • Compilation fails.
  • there
  • hello
  • A NumberFormatException is thrown.
Answer: C

The short version

Answer C: hello.

Key concepts

  • Overloaded method resolution: print(int) vs print(long)
  • Binary literal 0b1101_1010 has type int
  • Exact-match overload wins without widening

Why C is correct

Settled answer C is corroborated (community 100%, verified result hello). 0b1101_1010 is an int literal, so new Main().print(...) binds to print(int), which prints hello.

Why the others are wrong

  • A: wrong because the code compiles; overloads are both valid.
  • B: wrong because there prints only from print(long); the int argument does not widen to long.
  • D: wrong because no parsing or number-format operation occurs.

1z0-829 exam tip

For 1z0-829, check literal type first: int literals bind to int overloads even if a long overload exists.

3Given the code fragment: Which set of class definitions compiles?
Java SE 17 Developer (1Z0-829) question 3
  • interface Story extends SInt {} interface Art extends SInt {}
  • public interface Story extends SInt {} public interface Art extends SInt {}
  • sealed interface Story extends SInt {} non-sealed class Art implements SInt {}
  • non-sealed interface Story extends SInt {} non-sealed interface Art extends SInt {}
  • non-sealed interface Story extends SInt {} class Art implements SInt {}
Answer: D

The short version

Answer D: non-sealed interface Story extends SInt plus non-sealed interface Art extends SInt.

Key concepts

  • Sealed vs non-sealed hierarchies
  • Interfaces extending a sealed interface must be marked sealed, non-sealed, or final
  • Access and modifier consistency

Why D is correct

Settled answer D is corroborated (community 100%). Only the pair in D satisfies the sealed-hierarchy modifier rules for compiling against SInt.

Why the others are wrong

  • A: wrong because plain interfaces miss the required sealed-hierarchy modifier.
  • B: wrong because public alone does not satisfy the sealed permits/non-sealed requirement.
  • C: wrong because the sealed/non-sealed combination shown does not match the permitted SInt hierarchy.
  • E: wrong because a plain class Art without final/sealed/non-sealed cannot extend/implement the sealed type.

1z0-829 exam tip

For 1z0-829, any direct subtype of a sealed type must be declared sealed, non-sealed, or final.

4Given the code fragment: What is the result?
Java SE 17 Developer (1Z0-829) question 4
  • ABBCDE // the order of elements is unpredictable
  • ABCDE
  • ABCDE // the order of elements is unpredictable
  • ADEABCB // the order of elements is unpredictable
Answer: C

The short version

Answer C: ABCDE with unpredictable order.

Key concepts

  • Stream.concat + distinct
  • parallel() + forEach is unordered
  • Distinct set is A, B, C, D, E

Why C is correct

Settled answer C is corroborated (community 100%, observed outputs CEDBA/CEDAB). Concat gives A,B,C,B,A,D,E, distinct leaves A,B,C,D,E, and parallel forEach prints them in unpredictable order.

Why the others are wrong

  • A: wrong because there is no duplicate B after distinct; ABBCDE keeps a duplicate.
  • B: wrong because ABCDE in fixed order ignores parallel unordered forEach.
  • D: wrong because ADEABCB keeps duplicates and a fixed order.

1z0-829 exam tip

For 1z0-829, parallel().forEach means order is unpredictable; distinct() removes the duplicate B here.

5Which statement is true about modules?
  • Only unnamed modules are on the module path.
  • Automatic and named modules are on the module path.
  • Only automatic modules are on the module path.
  • Only named modules are on the module path.
  • Automatic and unnamed modules are on the module path.
Answer: B

The short version

Answer B: Automatic and named modules are on the module path.

Key concepts

  • Module path vs classpath
  • Named modules vs automatic modules vs unnamed modules
  • Unnamed modules live on the classpath

Why B is correct

Settled answer B is corroborated (community 100%). Named and automatic modules are resolved from the module path; unnamed modules come from the classpath.

Why the others are wrong

  • A: wrong because unnamed modules are on the classpath, not the module path.
  • C: wrong because it omits named modules, which are also on the module path.
  • D: wrong because it omits automatic modules, which are also on the module path.
  • E: wrong because unnamed modules are not on the module path.

1z0-829 exam tip

For 1z0-829, memorize: module path = named + automatic; classpath = unnamed.

6Given the code fragment: Which code at line n1, obtains the java.io.Console object?
Java SE 17 Developer (1Z0-829) question 6
  • Console console = Console.getInstance();
  • Console console = System.console();
  • Console console = new Console(System.in);
  • Console console = new Console(new InputStreamReader(System.in));
  • Console console = System.console(System.in);
Answer: B

The short version

Answer B: Console console = System.console();

Key concepts

  • java.io.Console has no public constructor
  • System.console() factory method
  • Console may be null in IDEs but the API call is this one

Why B is correct

Settled answer B is corroborated (community 100%). System.console() is the supported way to obtain the Console object.

Why the others are wrong

  • A: wrong because Console has no getInstance() method.
  • C: wrong because Console has no public constructor taking InputStream.
  • D: wrong because Console has no public constructor taking InputStreamReader.
  • E: wrong because System.console() takes no arguments.

1z0-829 exam tip

For 1z0-829, Console is always System.console(); never new Console(...).

7Given the content of the in.txt file: 0123456789 and the code fragment: What is the content of the out.txt file?
Java SE 17 Developer (1Z0-829) question 7
  • 012345678
  • 01234567801234
  • 01234567
  • 0123456789
  • 012345678901234
  • 0123456789234567
Answer: F

The short version

Answer F: 0123456789234567.

Key concepts

  • FileReader.read(char[]) returns count read
  • out.write(buffer) writes the whole buffer, not just count
  • Second read leaves stale chars in buffer

Why F is correct

Settled answer F is corroborated (community 100%, verified output 0123456789234567). First read fills 8 chars 01234567 and writes 8. Second read puts 89 over positions 0-1, leaving 234567, so it writes 89234567. Total is 0123456789234567.

Why the others are wrong

  • A/B/C/D/E: all wrong because they assume only count bytes are written (e.g. 0123456789 or truncated forms), but the bug writes the full 8-char buffer twice.

1z0-829 exam tip

For 1z0-829, if you see out.write(buffer) in a loop, suspect the stale-buffer bug; correct code is out.write(buffer, 0, count).

8Which statement is true?
  • IllegalStateException is thrown if a thread in waiting state is moved back to runnable.
  • A thread in waiting state consumes CPU cycles.
  • After the timed wait expires, the waited thread moves to the terminated state.
  • A thread in waiting state must handle InterruptedException.
Answer: D

The short version

Answer D: A thread in waiting state must handle InterruptedException.

Key concepts

  • WAITING vs TIMED_WAITING vs TERMINATED
  • Object.wait() throws InterruptedException
  • Waiting threads do not consume CPU

Why D is correct

Settled answer D is corroborated (community 100%). Entering waiting via wait()/join() requires catching or declaring InterruptedException.

Why the others are wrong

  • A: wrong because moving waiting to runnable via notify does not throw IllegalStateException.
  • B: wrong because waiting threads are parked and do not consume CPU cycles.
  • C: wrong because timed-wait expiry returns to runnable/blocked, not terminated.

1z0-829 exam tip

For 1z0-829, waiting always pairs with InterruptedException handling.

9Given the code fragment: List listOfNumbers = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); Which code fragment returns different values?
  • int sum = listOfNumbers.stream().reduce(0, Integer::sum) + 5;
  • int sum = listOfNumbers.parallelStream().reduce(0, Integer::sum) + 5 ;
  • int sum = listOfNumbers.parallelStream().reduce((m, n) -> m + n).orElse(5) + 5;
  • int sum = listOfNumbers.parallelStream().reduce(5, Integer::sum);
  • int sum = listOfNumbers.stream().reduce(5, (a, b) -> a+ b);
Answer: D

The short version

Answer D: int sum = listOfNumbers.parallelStream().reduce(5, Integer::sum);

Key concepts

  • reduce(identity, accumulator) vs reduce(accumulator)
  • Identity must be a true identity; 5 is not for addition
  • Parallel reduce applies identity per partition

Why D is correct

Settled answer D is corroborated (community 100%). With identity 5, parallel partitions each add 5, so the result differs from sequential sums of 1..10 plus 5. The other forms add 5 exactly once.

Why the others are wrong

  • A: wrong because sequential reduce(0,sum)+5 adds 5 once: 60.
  • B: wrong because parallel reduce(0,sum)+5 also adds 5 once: 60.
  • C: wrong because Optional reduce then orElse(5)+5 adds 5 once.
  • E: wrong because sequential reduce(5,(a,b)->a+b) uses 5 as a single identity: 60.

1z0-829 exam tip

For 1z0-829, parallel reduce with a non-identity value is the classic different-result trap.

10Given the code fragment: Which two statements at Line n1 independently enable you to print 1250? (Choose two.)
Java SE 17 Developer (1Z0-829) question 10
  • Integer res = 250 + Integer.parseInt(s);
  • Integer res = 250 + Integer.valueOf(s);
  • Integer res = 250 + s2;
  • Integer res = 250; res =+ s2;
  • Integer res = 250 + s;
  • Integer res = 250 + Integer(s2);
Answer: C, D

The short version

Answers C and D: Integer res = 250 + s2; and the += form enable printing 1250.

Key concepts

  • Integer unboxing with +
  • Integer.parseInt/valueOf reject underscores like 10_00 in this context
  • String s cannot be added to int; Integer(s2) constructor form does not exist

Why CD is correct

Settled answer CD is corroborated (community 100%, compiler-verified). Only adding the Integer s2 (1000) to 250 unboxes to 1250; the D variant is the += assignment form.

Why the others are wrong

  • A/B: wrong because parseInt(s)/valueOf(s) fail on the underscored 10_00 form here.
  • E: wrong because String s cannot be added to int.
  • F: wrong because Integer(s2) is not valid syntax; valueOf is required.

1z0-829 exam tip

For 1z0-829, underscores in numeric strings break parseInt/valueOf; unboxing an Integer operand is the safe addition.

Want the full bank of 66 questions for Java SE 17 Developer (1Z0-829)? See all practice exams.