Java Zero to All All questionsPractise free
Interview questions › Java Foundations — Zero to Basics › Java 8 — Optional, Date/Time API, Method Refs

Why was java.time introduced to replace Date and Calendar, and what are its key design wins?

Level II · JuniorJava 8 — Optional, Date/Time API, Method Refs
Answer

The old Date/Calendar API was mutable (hence not thread-safe), 0-indexed months, and conflated instants with human dates, causing endless bugs. java.time is immutable and thread-safe, separates concepts cleanly — Instant (a point on the timeline, UTC), LocalDate/LocalDateTime (no zone), ZonedDateTime (zone-aware), Duration vs Period (machine vs calendar time) — and has fluent, null-safe operations. In production you store and compute in Instant/UTC and convert to a ZonedDateTime only at display boundaries to avoid DST and offset bugs.

Common mistakes
  • Still using java.util.Date and Calendar in new code.
  • Not mentioning immutability and thread safety as key wins.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for Java 8 — Optional, Date/Time API, Method Refs.

Practise free

More on Java 8 — Optional, Date/Time API, Method Refs