I need to know how to fix these error notes:
Note: Summer.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Here is my code:
import java.util.Calendar; import java.util.*; class Summer { public static void main(String[] args) { Date d1 = new Date(); Date j21 = new Date(d1.getYear(), 6, 21); if(d1.before(j21)) { long diff = j21.getTime() - d1.getTime(); diff = diff / (1000 * 60 * 60 * 24); System.out.println("There are " + diff + " days until June 21st" ); } else { long diff = d1.getTime() - j21.getTime(); diff = diff / (1000 * 60 * 60 * 24); diff = 365 - diff; System.out.println("There are " + diff + " days until June 21st" ); } } } 05 Answers
This is not an error; it's a warning message.
Your program would run as you wrote it.
The reason why the compiler is giving you this warning is because you have used a deprecated function call.
By "recompile with -Xlint", the compiler means to inform you that you need to recompile your program like this:
javac -Xlint abc.java If you do so, the compiler will tell you which methods are deprecated so you can remove your calls to them. (If some method is deprecated, it usually means that a better implementation is available and that you should use that instead of the deprecated method.)
0It's a warning. You're using a deprecated function call or object. You can recompile like so to find out where it's occurring:
javac -Xlint:deprecation Summer.java Generally, it's a bad idea to use deprecated libraries. They may go away in the next release.
1As the message says, you need to compile it with -Xlint command line switch to the javac command as follows:
C:\Temp>javac -Xlint Summer.java Summer.java:22: warning: [deprecation] getYear() in java.util.Date has been deprecated Date j21 = new Date(d1.getYear(), 6, 21); ^ Summer.java:22: warning: [deprecation] Date(int,int,int) in java.util.Date has been deprecated Date j21 = new Date(d1.getYear(), 6, 21); ^ 2 warnings 4Note: filename.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. for this ERROR. but its actually a warning for missing the try{}catch(){} block you can use to see the effected code by writing the following statement
javac -Xlint:unchecked filename.java it will show the unchecked all exceptions that must catch through the user define or system define exception code
Those are not errors. Just warnings. Those will not affect your program. But as you are using deprecated util class Date in future it may affect your program.
It is better to use java.util.Calendar instead of java.util.Date this provides same functionality as Date and someextra functionalities also