Return to site

JAVA INTERVIEW QUESTION

· java

Can you tell some differences between old and new Date Time API of Java 8?

Even though new Date and Time API are a completely new API, you can deduce the following difference between them:

1) In old API, Date was mutable but in Java 8 all date and time classes like LocalDate, LocalTime or LocalDateTime are Immutable.

2) In old API, SimpleDateFormat was not thread-safe, but in Java 8 Formatter are thread-safe.

3) In old Date and Calendar API, Year starts with 1900, Months starts with 0, which is corrected in Java 8, here numbers make more sense.

4) Old Date and Calendar API has just one class Date to represent date and time, but Java 8 has separated classes for Date and Time e.g. LocalDate and LocalTime