5

I am writing new project in Java 8 in company. I have suggested to use Java 8 date time API but one of my co workers says that new Date time API works slow.

Is it true? Also I want to get some official documentation from Oracle which will mention that you should not use java.util.Date in new projects.

user1321466
  • 1,889
  • 2
  • 21
  • 29
  • 6
    this is why you should use new date and time api [Why do we need a new date and time library?](http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html) – matoni Jul 11 '17 at 11:15
  • 2
    Tell your co-worker about the [lots of problems](https://stackoverflow.com/questions/1571265/why-is-the-java-date-api-java-util-date-calendar-such-a-mess) and [design issues](https://stackoverflow.com/questions/1969442/whats-wrong-with-java-date-time-api) of the old API (`Date`, `Calendar` and `SimpleDateFormat`). Even if the new API was slower (does he have evidences?), it's still worth using it. –  Jul 11 '17 at 12:03

3 Answers3

12

When java.time.* was developed, this phrase was what I wanted to add to java.util.Date:

"This class is now effectively deprecated by the Time Framework for Java."

It was in the source repository for a while, see here.

However, this change was rejected by Oracle, and as such there is no explicit deprecation of java.util.Date. However, all sensible developers should use Instant and java.time.* generally instead of java.util.Date.

JodaStephen
  • 60,927
  • 15
  • 95
  • 117
  • 2
    Thank you. I think that it was wrong decision by Oracle to remove it from javadoc. – user1321466 Jul 11 '17 at 11:51
  • 2
    @JodaStephen It would have been interesting to comment on the performance question - I've seen a benchmark in the past but can't find it right now. – assylias Jul 11 '17 at 12:49
  • 2
    Perhaps it's time to re-submit that doc change for Java 9 or Java 10? – Basil Bourque Jul 12 '17 at 01:00
  • 1
    Some performance issues have been fixed, others are still to be done. Anything specific that can be identified and is fixable should be raised in the Oracle bug tracker. – JodaStephen Jul 12 '17 at 10:44
5

You can find answer on Oracle site here

In few words -- no, java.util.Date is not deprecated, but Oracle strongly recommend to use a new java.time library (and pros they are mention you can find in a link above).

4

Oracle Tutorials

I want to get some official documentation from Oracle

The official Oracle Tutorials has replaced the tutorial on date-and-time with new material covering only the java.time classes.

Now ‘legacy’

The troublesome old date-time classes have been dropped from the tutorial, except for a page on migrating from the old classes to the modern classes. Note that the page is explicitly labeled as ‘legacy’.

Performance

As for performance, I am not aware of any significant difference between the legacy and modern classes.

Internally, the classes work with similar data, integer count-from-epoch and similar time zone info. So I can't imagine any great difference in performance between, say, java.util.Date and java.time.Instant. If anything, in practice java.time may be faster as it is entirely thread-safe, so you can cache and reuse values rather than regenerate them.

Even if the java.time classes proved slower, their modern design and clarity of usage and correctness of results are far more important than some minor speed difference.

Anyone alleging performance issues should demonstrate with example code. As the old saying goes, “Put up, or shut up”.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154