Notice

╠ This is my personal blog and my posts here have nothing to do with my employers or any other association I may have. It is my personal blog for my personal experience, ideas and notes. ╣
Showing posts with label JDK 8. Show all posts
Showing posts with label JDK 8. Show all posts

Monday, March 7, 2016

Yet another date time in Java 8

In Java 8 there is new package introduced related to Date and Time java.time package.  
This improvement is done against JSR - 310 by threeten.org  


Why we need another Date/Time class in Java 8 as there is already lots of Date/Time class available in previous Java versions ?

In previous versions of JDK we didn't find good support for date/time operation. Everything thing jumbled up together in Date and Calendar class as a result it is not convenient to use for developer.
Date and Time is wrapped in Date class. So whenever we need to do operations related to date only then we need to remove the time component from Date object. To do simple things developers need to write lots of extra code just to do formatting, getting date/time and day light saving. Using Date class we cannot go below milliseconds. 
More than that Date class have lots of bugs in API and equals method equality breaks when using date object case to case basis. 

In case of Calendar class it better than Date but it still have some problems like date formatting support is not available. We need to covert Calendar object to Date object to do formatting. 


So, what we are going to get in JDK 8  Date and Time ? 

  1. Clear bug free API for date, time and date-time. 
  2. All these objects are thread safe as these objects are immutable. 
  3. Package are organised well and classes are design to cater API extensible.  
Detail about new Java 8 Date-Time 



Examples can be downloaded from https://github.com/andysundar/JDK8