Hello! Im new to the java. During creating a program Im getting a warning "@suppresswarnings( deprecation )". I wants to know why is that warning occur and how to avoid it.

Recommended Answers

All 6 Replies

As Oracle keep improving Java, there are times when old classes and methods get replaced by newer better versions. The old versions are still there, so existing programs will continue to work, but they are marked as "deprecated" to tell programmers that they should replace or upgrade their code.
If you chose not to update your code, the constant warnings about using deprecated methods get very tedious, so you use the @suppresswarnings(deprecation) annotation to tell the compiler to stop bothering you.

IMO you should never blindly just ignore any warning. If you're not sure of why you get it, what the risks are of ignoring it and find those acceptable, and there's a solution, fix your code rather than ignoring the warning.

Deprecated methods are deprecated for a reason, they often are unreliable or have dangerous side effects.
So don't use them unless there is no other way (and there just about always is another way).
In fact sometimes (and especially outside the core Java APIs provided by Oracle) deprecated methods have been changed upon deprecation to do nothing at all, or to just log a warning and terminate, forcing users to replace calls to them.

Yes. Maybe I should have made that clearer in my earlier post instead of just literally answering the question.
If you see a @suppresswarnings(deprecation), or are invited to use one by Eclipse or NewBeans, look up the API in question, find out why it was deprecated, and if at all possible, replace it with the recommended new API.
Continuing to run with deprecated code, ie code that is known to have problems so severe that it needed a new API to fix them, is asking for trouble.

can you please tell me that how can I find out the reason? I don't understand why its getting depricated.

You haven't actually said which deprecated API you are using! Post the class and method name. I'm sure some here will be able to help.

the documentation for a deprecated method or class will often tell you why it was deprecated and what the suggested alternatives are.
If not, you're on your own and have to rely on your experience and knowledge of the language and API to figure it out for yourself.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.