Test with 6u22:
% cat MyTest.java
public class MyTest {
public static void main(String[] args) {
java.sql.Date jsd1 = java.sql.Date.valueOf("0000-01-01");
java.sql.Date jsd2 = java.sql.Date.valueOf("0001-01-01");
System.out.println(jsd1);
System.out.println(jsd2);
System.out.println(jsd1.equals(jsd2));
System.out.println(jsd1.getTime());
System.out.println(jsd2.getTime());
}
}
% javac MyTest.java
% java MyTest
0001-01-01
0001-01-01
false
-62167395600000
-62135773200000
The internal representation of the two sql.Dates differ by 366 days in this case and therefore the equals method return false. The toString method prints 0001-01-01 in both cases however.
java.sql.Date.valueOf accepts invalid dates, because year 0 does not exist (the transition from BC to AD is ..., 2 BC, 1 BC, 1 AD, 2 AD).
% cat MyTest.java
public class MyTest {
public static void main(String[] args) {
java.sql.Date jsd1 = java.sql.Date.valueOf("0000-01-01");
java.sql.Date jsd2 = java.sql.Date.valueOf("0001-01-01");
System.out.println(jsd1);
System.out.println(jsd2);
System.out.println(jsd1.equals(jsd2));
System.out.println(jsd1.getTime());
System.out.println(jsd2.getTime());
}
}
% javac MyTest.java
% java MyTest
0001-01-01
0001-01-01
false
-62167395600000
-62135773200000
The internal representation of the two sql.Dates differ by 366 days in this case and therefore the equals method return false. The toString method prints 0001-01-01 in both cases however.
java.sql.Date.valueOf accepts invalid dates, because year 0 does not exist (the transition from BC to AD is ..., 2 BC, 1 BC, 1 AD, 2 AD).