Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to know the best way to add a comment to identify a deprecated class in Java. Should I remove the previous comment added to the top of the class that helps another programmer to know what was that class for, or should I add it below the comment?

share|improve this question
up vote 14 down vote accepted

The recommended approach to deprecating a class, method, or field in Java is to use the @Deprecated annotation, which became available in Java 5, or the @deprecated JavaDoc tag, which has been around since Java 1.1. Oracle has a document about the specifics on how and when to deprecate APIs that appears to be relevant.

Should i remove the previous comment added to the top of the class that helps another programmer to know what was that class for or add it below the comment?

You should not edit or remove any existing comments, other than to add the JavaDoc tag or annotation. Deprecated code might still be in use in legacy systems, and developers of those systems need to have access to the documentation that the original developers did in some form.

share|improve this answer
+1: Using the @Depricated annotations also give a heads up to IDEs like Eclipse to make sure to cross that method out and give other visual hints to developers. – Ryan Hayes Sep 5 '11 at 14:48
yes i know how to deprecate and the use off annotation my question is for example i have this code /** * comment about the class **/ public class ClassToDeprecate{ // some code here } should i remove the comment and be like this – Danilo Sep 5 '11 at 14:49
@Spammer The article I linked to discusses that. Also, browsing through the Java API documentation answers that. The only thing that you should do is add the @Deprecated annotation or the @deprecated JavaDoc tag. That's it - nothing else, nothing more. – Thomas Owens Sep 5 '11 at 14:53
by the way, the link you gave was very helpfull – Danilo Sep 13 '11 at 19:07
Adding @deprecated JavaDoc tag and description along with @Deprecated annotation will give more light into why it was deprecated. So it would be more beneficial to use both rather than just @Deprecated annotation. – WarFox Jul 8 '13 at 11:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.