java examples
Home Java Examples Resources Java Interview Questions
Brainpower SEO

How to 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 com.javacoderanch.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);