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" );
}
}
}
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.
You can resolve this warning message by using generics with Collections. In our example, we should use ArrayList<String> rather than ArrayList() . When you will compile above code, you won't get warning message anymore. That's all about how to fix uses unchecked or unsafe operations.
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.)
It'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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With