The largest Interview Solution Library on the web


« Previous | 1 | 2 | 3 | Next »

Java_8 New - New DateTime API


With Java 8, a new Data Time API is introduced to cover the following drawbacks of old data time API.
  • Not thread safe - java.util.Date is not thread safe, thus developer have to deal with concurrency issue while using date. New date time API are immutable and do not have setter methods.
  • Poor design - Default Date starts from 1900 , month starts from 1 and day starts from 0 so no uniformity. Less direct methods for date operations. New APIs provides numerous utility methods for such operations.
  • Difficult time zone handling - Developers have to write lot of code to deal with time zone issues. New API design is developend keeping domain specific design in mind.
JAVA 8 introduces a new date time API under package java.time. Following are some of the important classes introduced in java.time package.
  • Local - Simplified Date time API with no complexity of Time Zone handling.
  • Zoned - Specialized Date time API to deal with various time zones.
SNMethods with Description
1Local Date Time API
LocalDate/ LocalTime and LocalDateTime classes simplifies the development where timezone are not required.
2Zoned Date Time API
Zoned Date Time APIs is used when time zone is to be considered.
3Chrono Units Enum
java.time.temporal.ChronoUnit enum is added in java 8 to replace integer values used in old API to represent day, month etc.
4Period and Duration
These classes are introduced to deal with time differences.
5Temporal Adjusters
TemporalAdjuster is to do the date mathematics. For example to get the "Second Saturday of the Month" or "Next Tuesday".
6Backwards Compatibility
A toInstant() method is added to the original Date and Calendar objects which can be used to convert them to the new Date-Time API.
« Previous | 1 | 2 | 3 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com