How do I mark method as deprecated?

To mark a method as deprecated we can use the JavaDoc @deprecated tag. This is what we did since the beginning of Java. But when a new metadata support introduced to the Java language we can also use annotation. The annotation for marking method as deprecated is @Depreated.

The difference between these two that the @deprecated is place in the JavaDoc comment block while the @Deprecated is placed as a source code element.

package org.kodejava.example.annotation;

import java.util.Date;
import java.util.Calendar;

public class DeprecatedExample {
    public static void main(String[] args) {
        DeprecatedExample de = new DeprecatedExample();

     * Get current system date.
     * @return current system date.
     * @deprecated This method will removed in the near future.
    public Date getDate() {
        return new Date();

    public int getMonthFromDate() {
        return Calendar.getInstance().get(Calendar.MONTH);


Programmer, runner, recreational diver, live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. Support me, buy me ā˜• or šŸµ

Leave a Reply