Java 8 – New way to deal with Date and Time

In this article, we will discuss Java 8 Date/Time API. The new Date/Time API was one of the long pending requests from the Java developer community. As the existing Date, related API is not developer friendly. With the older versions of Java, we used third-party date-time libraries like Joda-Time. As part of Java 8, the implementation of JSR 310 lead by Joda-Time author Stephen Colebourne along with Oracle-provided Date and Time API. This will be available under java package java.time

The main reasons behind the new Date and Time API are,

Immutability

Prior to Java 8, the date classes are mutable. When we are using it as part of multi-threaded environments, developers have to make sure the thread safety of date objects. The Java 8 Date and Time API provides all the immutable classes which are thread safe. Developers are free of concurrency issues.

Domain Driven Design Approach

The classes of new Date and Time API follows “Domain Driven Design”. For developers, understanding of the functionality of methods and classes is very easy.

Now, we will see some of the classes and operations of Date and Time API.