Why there are two Date classes; one in java.util package and another in java.sql?

15 Oct , 2016  

A java.util.Date represents date and time of day, a java.sql.Date only represents a date. The complement ofjava.sql.Date is java.sql.Time, which only represents a time of day.
java.sql.Date is a subclass (an extension) of java.util.Date. So, what changed in java.sql.Date:

 toString() generates a different string representation: yyyy-mm-dd
– a 
static valueOf(String) methods to create a date from a string with above representation
– the getters and setter for hours, minutes and seconds are deprecated

The java.sql.Date class is used with JDBC and it was intended to not have a time part, that is, hours, minutes, seconds, and milliseconds should be zero… but this is not enforced by the class.

Leave a Reply

Your email address will not be published. Required fields are marked *