Test4 banner

Test 4 - Free Java SE 25 certification Mock test - Exam Code 1Z0-831-Oracle certified Java SE 25 Professional

Dates and times are the area of the Java SE 25 Developer exam that causes the most confusion, so this free 1Z0-831 mock test is all about the java.time package. If you've ever mixed up a Period with a Duration or been genuinely surprised by a daylight saving transition then these questions are for you.

You'll be working with the core classes: LocalDate, LocalTime, LocalDateTime, ZonedDateTime, OffsetDateTime, Instant, Duration and Period. The questions will be testing which class is the right one for the job. A LocalDate has no time and no zone, an Instant is a point on the UTC timeline and a ZonedDateTime has the full zone rules. You'll also learn why mixing up the wrong types will either fail to compile or throw a DateTimeException at runtime.

Immutability is a big one. The plusDays, minusMonths and withHour methods all return new objects so if you don't capture the return value the original is left untouched. Month end arithmetic is also considered: adding one month to 31st January gives you the last valid day of February rather than throwing an exception.

Daylight saving time is the key issue. You'll be looking at what happens when the clocks spring forward (and so there is no local time for that hour) and when they fall back (and so that hour occurs twice). You'll be comparing adding a Duration of 24 hours to adding a Period of one day across a transition in a zone such as America/Los_Angeles where the results can differ by an hour.

Formatting and parsing is the whole story here. The questions use DateTimeFormatter with the ISO constants and custom patterns, test the difference between upper and lower case pattern letters and ask you which inputs will result in a DateTimeParseException. You'll be using ChronoUnit.between, Duration.between and Period.between and will be asked about the toString output of those (e.g. PT90M, P1Y2M3D). You'll come across some gotchas with Instant (it can't be queried for months or years) and will be asked about the various ways of converting between ZonedDateTime and Instant using offsets. A good way to avoid making a mistake when the question involves more than one time zone is to simply trace the conversion along a number line.

Every explanation walks you through the timeline step by step so you can reason through the edge cases without having to memorise the tables. Just finish the test, go back and look at each one you got wrong and redraw the timeline for yourself. Once you can see the clock ticking in your head you'll find these questions to be some of the most reliable questions on the exam.

Welcome to your Free Java SE 25 – Test 4