10 free Oracle 1Z0-829 practice questions with the correct answer and a full explanation for each, taken from the CertStash pack of 130 questions. Work through them, then open each answer to check your reasoning.
Get all 130 questions (US$39) · Download these 10 as a PDF
Question 1
Given the code fragment:
and
Which is true?

Show answer and explanation
Correct answer: A. The program prints t1 : 1 : t2 : 1: t1 : 2 : t2 : 2 : in random order.
The code creates two threads that execute concurrently. Thread t1 increments the volatile variable x three times (printing x values 1, 2), while thread t2 increments the AtomicInteger xObj three times (printing values 1, 2). Since both threads run concurrently without synchronization between them, the interleaving of their print statements is no-eterministic. The actual values printed will always be in the pattern t1:1, t2:1, t1:2, t2:2, but the order in which these print statements execute is random due to thread scheduling. The volatile keyword on x and AtomicInteger's thread-safe operations ensure visibility, but do not enforce execution order between the two threads.
Why the other options are wrong
- B. This ignores the non-deterministic nature of concurrent thread execution; the output order is not guaranteed to be sequential.
- C. Both while loops terminate after their conditions are false (x < 3 and xObj.get() < 3), so the program does not print indefinitely.
- D. The code is syntactically valid and contains no operations that would throw an exception; both threads execute their loops and exit normally.
Question 2
Which statement is true?
Show answer and explanation
Correct answer: D. A thread in waiting state must handle InterruptedException.
InterruptedException. When a thread is in a waiting state (such as after calling wait(), join(), or sleep()), it can be interrupted by another thread calling interrupt() on it. If interrupted while waiting, the thread must handle the InterruptedException that is thrown when it transitions out of the waiting state. This is a fundamental requirement in Java's threading model, methods that put threads into waiting states are declared to throw InterruptedException precisely because waiting threads must be prepared to handle interruption.
Why the other options are wrong
- A. No exception is thrown simply for moving a waiting thread back to runnable; this is normal thread state transition when wait() completes or notify() is called.
- B. A thread in waiting state does not consume CPU cycles; it relinquishes the CPU and remains idle until notified or interrupted.
- C. After timed wait expires, a thread moves to the runnable state, not the terminated state; it must complete execution or be explicitly stopped to terminate.
Question 3
Daylight Saving Time (DST) is the practice of advancing clocks at the start of spring by one hour and adjusting them backward by one hour in autumn.
Considering that in 2021, DST in Chicago (Illinois) ended on November 7th at 2 AM, and given the fragment:
What is the output?

Show answer and explanation
Correct answer: C. true false
ZonedDateTime.of(2021-11-07, 01:30, America/Chicago) hits the overlap caused by the end of DST, and the rule for an ambiguous local time is to keep the earlier offset, so zdt is 01:30 CDT (UTC-5). plusHours(1) adds one hour of real elapsed time, which lands on 01:30 CST (UTC-6) because the clocks fall back at 02:00. Both objects therefore report hour 1, so the first comparison prints true, while the offsets -05:00 and -06:00 are not equal, so the second prints false.
Why the other options are wrong
- A. The offsets differ across the fall-back transition, -05:00 before and -06:00 after, so the equals call on ZoneOffset returns false.
- B. Adding one hour of elapsed time to 01:30 CDT produces 01:30 CST, so both getHour() calls return 1 and the first comparison is true.
- D. The hour does not change during the overlap, since the local time repeats, making the first comparison true rather than false.
Question 4
Given the code fragment:
What is the result?

Show answer and explanation
Correct answer: A. Can't logout
The code truncates both loginTime and logoutTime to MINUTES precision using truncatedTo(ChronoUnit.MINUTES). The loginTime is 2021-01-12T21:58:18.817Z, which truncates to 2021-01-12T21:58:00Z. The logoutTime is 2021-01-12T21:58:19.880Z, which also truncates to 2021-01-12T21:58:00Z. When both truncated values are equal, logoutTime.isAfter(loginTime) returns false because isAfter() requires strict temporal ordering. Therefore, the else branch executes and prints "Can't logout".
Why the other options are wrong
- B. This would require logoutTime to be strictly after loginTime, but truncating both to minute precision makes them equal, so isAfter() returns false.
- C. The code is syntactically valid; truncatedTo() is a legitimate Java 8+ method on Instant objects with no compilation error at line n1.
- D. The truncation to MINUTES eliminates the seconds and milliseconds, so the output would show :58:00Z not :58:19.880Z, and this branch never executes anyway.
Question 5
Given the code fragment:
What is the result?

Show answer and explanation
Correct answer: B. PT5SPT1MP6D
The code creates three temporal objects and prints their ISO-8601 string representations. Duration.ofMillis(5000) creates a 5-second duration, which prints as "PT5S". Duration.ofSeconds(60) creates a 60-second duration, which prints as "PT1M". Period.ofDays(6) creates a 6-day period, which prints as "P6D". Concatenating these outputs produces "PT5SPT1MP6D", which matches option B.
Why the other options are wrong
- A. Includes unnecessary 'T' and 'P' characters in the concatenation; does not account for the fact that 5000 milliseconds equals 5 seconds (PT5S not PT5000S) and 60 seconds equals 1 minute (PT1M not PT60M).
- C. Omits the 'P' and 'T' prefix characters that are required in ISO-8601 temporal format strings.
- D. Incorrectly represents 5000 milliseconds as "5000S" instead of "PT5S", and 60 seconds as "60M" instead of "PT1M", failing to perform proper duration conversions.
Question 6
Given the code fragment:
Which action enables the code to compile?

Show answer and explanation
Correct answer: E. Make the regNo variable static.
A record may not declare instance fields; its state is limited to the record components listed in the header. The line int regNo = 100; is an instance field declaration, so the compiler rejects it. Declaring it static is allowed, because records do permit static fields, and getRegNumber() can then return it.
Why the other options are wrong
- A. void is a return type and cannot introduce a type declaration, so the file would not parse.
- B. A class declaration cannot carry a parameter list such as (int pNumber, String pName), so this swap introduces a syntax error.
- C. Dropping the initializer still leaves int regNo; which is an instance field, and records forbid instance fields entirely.
- D. Changing the access modifier does not help, because the restriction is on instance fields in records, not on their visibility.
Question 7
Given:
What is the result?

Show answer and explanation
Correct answer: C. 0 SNOWY
The first line calls Forecast.SUNNY.ordinal(), which returns the zero-based index position of SUNNY in the enum (0), then prints "0 ". The second line calls Forecast.valueOf("cloudy".toUpperCase()), which converts the string to uppercase ("CLOUDY"), looks up that enum constant, calls toString() on it, and prints the result. The Forecast enum overrides toString() to return "SNOWY" for all enum values, so the output is "SNOWY". Combined, the program outputs "0 SNOWY".
Why the other options are wrong
- A. valueOf() returns the CLOUDY enum constant, but its toString() method is overridden to return "SNOWY", not "CLOUDY".
- B. The ordinal() of SUNNY is 0, not 1, making the first part of the output incorrect.
- D. valueOf("CLOUDY") does not return RAINY; it returns the CLOUDY enum constant whose overridden toString() returns "SNOWY".
- E. The code compiles successfully; there are no syntax errors or type mismatches.
Question 8
Given the code fragment:
What is the result?

Show answer and explanation
Correct answer: B. false true true Optional[NewYear]
Optional wrapping the first element, and its toString is Optional[NewYear]. Java prints booleans as true and false, so the concatenated output is false true true Optional[NewYear].
Why the other options are wrong
- A. Booleans are never printed as 0 or 1 in Java, and findFirst() prints an Optional rather than 0.
- C. Besides using numeric output for booleans, it reports noneMatch as false even though Halloween is not in the list.
- D. The boolean results are false, true, true in that order, and findFirst() prints Optional[NewYear], not the bare string.
Question 9
Given:
Which statement is true while the program prints GC?

Show answer and explanation
Correct answer: D. Only one of the objects previously referenced by t1 is eligible for garbage collection.
When the program executes, t1 initially references an App object with name "t1". Then t2 is created referencing an App object with name "t2". The assignment t1 = t2 makes t1 reference the same object as t2 (the "t2" App object). Finally, t1 = null sets t1 to null. At the point when "GC" is printed, the original App object with name "t1" has no references pointing to it, making it eligible for garbage collection. However, the App object with name "t2" is still referenced by t2, so it is not eligible for garbage collection. Therefore, exactly one of the objects previously referenced by t1 (the original "t1" App object) is eligible for garbage collection.
Why the other options are wrong
- A. The object referenced by t2 is still referenced by the variable t2, so it is not eligible for garbage collection.
- B. The original App object with name "t1" has no references and is eligible for garbage collection.
- C. The object referenced by t2 is still strongly referenced by t2 and cannot be collected; it is the t1 object that becomes eligible.
Question 10
Given:
What is the result?

Show answer and explanation
Correct answer: C. hello
The code calls new Main().print(0b1101_1010), which passes the binary literal 0b1101_1010 (decimal 218) as an argument. Java resolves this to the print(int i) method because the argument is an int type. The print(long j) method is not invoked because int is the more specific match when both methods are available. Therefore, the print(int i) method executes, printing "hello".
Why the other options are wrong
- A. The code compiles successfully with no syntax or semantic errors.
- B. The print(long j) method is not called because int is a more specific type match than long for the argument 0b1101_1010.
- D. No exception is thrown; the binary literal is valid and successfully converts to the int value 218.
That was 10 of 130.
The full Oracle 1Z0-829 pack has all 130 questions, each with the answer, the explanation and why the other options are wrong, plus a questions-only copy for timed runs. US$39, paid once, with free monthly updates and a pass-or-your-money-back guarantee.
