Use Calendar instead of Date in Java
January 14th, 2009
No comments
Common Issue
When you use java.util.Date object with JDK version higher than 1.1
Date d = new Date(); d.getMonth();
You will get deprecated warning messages when you try to compile
The method getMonth() from the type Date is deprecated
However you can supress the warning message by adding @SuppressWarnings("deprecation") to you main() method
@SuppressWarnings("deprecation") public static void main(String[] args) { ... }
or adding @SuppressWarnings("unchecked") to other method
@SuppressWarnings("unchecked") public void otherMethod() { ... }
Note that this can only be used in JDK 5.0+
Alternative
Now let’s forget about working around the deprecated method, let’s learn how to use java.util.Calendar instead
Read more…
Categories: Programming
Amazon

