10 Free Practice Questions for 1Z0-808 Certification
All 10 questions shown below with complete explanations
| # | Topic | Covered Concepts |
|---|---|---|
| 1 | LocalDate Basics | Date creation, immutability, rollover |
| 2 | Leap Year Handling | Feb 29 normalization, plusYears() |
| 3 | LocalTime Wraparound | plusSeconds(), midnight rollover |
| 4 | Month-End Adjustments | plusMonths(), last valid day logic |
| 5 | Invalid Date Creation | DateTimeException, strict validation |
| 6 | Period Factory Methods | ofYears(), ofMonths() chaining trap |
| 7 | Period Addition | Adding years, months, days sequence |
| 8 | Weeks Conversion | Period.ofWeeks(), days conversion |
| 9 | DateTimeFormatter | Custom patterns, formatting output |
| 10 | Formatter Compatibility | UnsupportedTemporalTypeException |
π‘ Exam Tip: Java Date & Time API questions often test immutability, normalization rules, and formatter compatibility rather than simple syntax.
2025 is not a leap year, so February has only 28 days.
Adding one day to 2025-02-28 rolls over to the next month automatically.
Therefore, the result is 2025-03-01.
The year 2025 is not divisible by 4, so it is not a leap year and February ends on the 28th.
LocalDate correctly enforces calendar rules and adjusts month boundaries automatically.
Calling plusDays(1) on February 28 moves to the next valid date, which is March 1.
LocalDate is immutable, so current = current.plusDays(1) creates a new date object.
There is no exception or invalid date because Date and Time API handles rollovers safely.
Thus, the printed output is 2025-03-01.
2024 is a leap year, so Feb 29 is valid.
Adding one year targets 2025-02-29, but 2025 is not a leap year.
Java automatically adjusts to the last valid day of February, which is 2025-02-28.
The date is created as February 29, 2024, which is valid because 2024 is a leap year.
Calling plusYears(1) moves the year to 2025 while keeping the same month and day when possible.
The target date becomes February 29, 2025, but that date does not exist because 2025 is not a leap year.
LocalDate resolves invalid dates by shifting to the last valid day of the month.
For February 2025, the last valid day is February 28.
Therefore, the printed result is 2025-02-28.
Adding 2 seconds wraps past midnight to 00:00:01.
The variable midnight is initialized using LocalTime.of(23, 59, 59), which represents the last valid second of the day.
The next line calls midnight.plusSeconds(2), which adds 2 seconds to this time.
Adding 1 second to 23:59:59 rolls the clock to 00:00:00 of the next day.
Adding the second second moves the time forward to 00:00:01.
LocalTime automatically handles wrap-around logic, so no exception occurs.
LocalTime does not track dates, so it simply cycles within 24 hours.
The updated time is returned and assigned back to the variable midnight.
Therefore, printing midnight outputs 00:00:01.
June has 30 days; May 31 + 1 month adjusts to June 30.
The starting date is: LocalDate.of(2025, 5, 31)
which represents May 31, 2025.
The code adds 1 month using: mayEnd.plusMonths(1)
Adding 1 month to May 31 means trying to create June 31, 2025.
But June has only 30 days.
Javaβs LocalDate adjusts invalid dates by moving to the last valid day of the month.
So June 31 becomes June 30.
No exception is thrownβthis is expected behavior.
Therefore, the output is 2025-06-30
2025 is not a leap year; attempting to create Feb 29 throws DateTimeException.
The code attempts to create a LocalDate representing February 29, 2025.
LocalDate.of(year, month, day) performs strict validation of the provided date components.
The year 2025 is not a leap year because it is not divisible by 4 (except century rules, which donβt apply here).
Therefore, February has only 28 days in 2025.
When Java evaluates LocalDate.of(2025, 2, 29), it detects that the date is invalid.
An invalid date cannot be constructed, so Java throws a runtime exception.
The specific exception thrown is DateTimeException from the java.time package.
Thus, the code does not compile an alternative date; instead, it fails at runtime with a DateTimeException.
Each Period.ofX() creates new object; chaining replaces previous, keeping only last.
The expression begins with Period.ofYears(1), which creates a Period representing 1 year (P1Y).
Even though .ofMonths(2) appears to be called on the result of the previous Period, it is actually a static method of Period.
Static methods do not use the instance they appear to be called on; instead, they create a new Period object.
So Period.ofYears(1).ofMonths(2) is evaluated as Period.ofMonths(2).
This new call completely replaces the earlier P1Y Period instead of adding to it.
Therefore, the final Period stored in duration represents only 2 months.
When printed, a Period uses ISO-8601 format, so 2 months becomes "P2M".
Thus, the output is P2M.
Period adds 1 year, then 2 months, then 15 days sequentially.
Period.of(1, 2, 15) creates a period representing 1 year, 2 months, and 15 days.
The starting date is 2025-01-01.
When calling start.plus(amount), Java adds the components of the period in the order: years β months β days.
Adding 1 year to 2025-01-01 produces 2026-01-01.
Adding 2 months to 2026-01-01 gives 2026-03-01, because January β March.
Adding 15 days to 2026-03-01 results in 2026-03-16.
March has more than enough days, so no overflow adjustment occurs.
Therefore, the final printed date is 2026-03-16.
Period.ofWeeks(2) equals 14 days; May 10 + 14 days = May 24.
The base date is created as:
LocalDate baseDate = LocalDate.of(2025, 5, 10);
So the starting date is 2025-05-10.
Period.ofWeeks(2) creates a period representing 14 days.
The plus() method adds the entire period to the date.
So we add 14 days to 2025-05-10.
Adding 10 days β 2025-05-20.
Add the remaining 4 days β 2025-05-24.
There is no exceptionβPeriod is valid and can be added to a LocalDate.
Therefore, the final result printed is 2025-05-24.
Custom pattern dd/MM/yyyy formats as day/month/year.
A LocalDate is created with: LocalDate.of(2025, 4, 29)
which represents 29 April 2025.
A DateTimeFormatter is created using the pattern: "dd/MM/yyyy"
dd β prints day with two digits β "29"
MM β prints month with two digits β "04"
yyyy β prints the full year β "2025"
No exception occurs because the pattern matches fields available in LocalDate.
The formatted output becomes: 29/04/2025
Therefore, the correct answer is A.
Formatter expects time fields (HH:mm) but LocalDate only has date fields.
someDate is a LocalDate, which contains only a year, month, and day.
It does not contain any time fields (no hour, minute, second).
The formatter is created with the pattern:
DateTimeFormatter.ofPattern("HH:mm");
This pattern requires time fields (hour and minute).
Calling: someDate.format(timeFormatter);
tries to extract hour and minute from a LocalDate.
LocalDate cannot supply these time fields.
Therefore, Java throws UnsupportedTemporalTypeException.
Nothing prints because the exception occurs before output.
Access all 1624 questions covering all OCA topics
β 1,624 practice questions
β 29 full certification tests
β Chapter-wise practice exams
β Detailed explanations for every answer
β Progress tracking & certificates