โ† All OCP Flashcard Decks

Date, Time, and Localization Flashcards

7 cards from real OCP practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 Date, Time, and Localization flashcards as text
  1. What is the result of executing `LocalDate.of(2024, Month.FEBRUARY, 29)`?

    Answer: Returns 2024-02-29 because 2024 is a leap year

    2024 is a leap year, making February 29 a valid date, so LocalDate.of(2024, Month.FEBRUARY, 29) successfully creates 2024-02-29.

  2. Which Java class represents a date and time without any time-zone information?

    Answer: LocalDateTime

    LocalDateTime stores a date-time without any zone or offset, while ZonedDateTime includes a zone, Instant is epoch-based, and OffsetDateTime carries a UTC offset.

  3. What does `Period.between(LocalDate.of(2023, 1, 1), LocalDate.of(2024, 3, 15))` return when printed?

    Answer: P1Y2M14D

    Period stores years, months, and days separately; from January 1 2023 to March 15 2024 is exactly 1 year, 2 months, and 14 days.

  4. Which method correctly obtains the current date using the UTC time zone?

    Answer: LocalDate.now(ZoneId.of("UTC"))

    LocalDate.now(ZoneId.of("UTC")) explicitly passes the UTC zone to get the current date in that zone, whereas the no-arg now() uses the JVM default zone.

  5. Which of the following correctly creates a Duration of 2 hours and 30 minutes?

    Answer: Both options produce the same valid Duration

    Both Duration.of(2, ChronoUnit.HOURS).plusMinutes(30) and Duration.ofHours(2).plus(30, ChronoUnit.MINUTES) are valid fluent ways to build a 2h30m Duration.

  6. Which of the following correctly parses the string "2024-06-15" into a LocalDate?

    Answer: Both options parse the string correctly

    LocalDate.parse(String) defaults to ISO_LOCAL_DATE format, so both the no-formatter overload and the explicit ISO_LOCAL_DATE formatter parse the same string identically.

  7. What does `LocalDate.now().with(TemporalAdjusters.firstDayOfMonth())` return?

    Answer: The first day of the current month

    TemporalAdjusters.firstDayOfMonth() adjusts any date to day 1 of its month, so the result is the first day of the current month.