Very often I come across negative feedback on Java Date and other date-time-related classes. Being a .NET developer, I cannot fully (without having used them) understand, what’s actually wrong with them.
Can anybody shed some light on this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Ah, the Java
Dateclass. Perhaps one of the best examples of how not to do something in any language, anywhere. Where do I begin?Reading the JavaDoc might lead one to think that the developers have actually got some good ideas. It goes on about the difference between UTC and GMT at length, despite the fact that the difference between the two is basically leap seconds (which happen pretty rarely).
However, the design decisions really lay to waste any thought of being a well designed API. Here are some of the favourite mistakes:
null. As a result, we have 0..11 (and today being month 11 of the year 109). There are a similar number of ++ and — on the months in order to convert to a string.Calendar, designed to ‘fix’ this, actually makes the same mistakes. They’re still mutable.Daterepresents aDateTime, but in order to defer to those in SQL land, there’s another subclassjava.sql.Date, which represents a single day (though without a timezone associated with it).TimeZones associated with aDate, and so ranges (such as a ‘whole day’) are often represented as a midnight-midnight (often in some arbitrary timezone)Finally, it’s worth noting that leap seconds generally correct themselves against a good system clock which is updated with ntp within an hour (see links above). The chance of a system being still up and running in the introduction of two leap seconds (every six months minimum, every few years practically) is pretty unlikely, especially considering the fact that you have to redeploy new versions of your code from time to time. Even using a dynamic language which regenerates classes or something like a WAR engine will pollute the class space and run out of permgen eventually.