What are annotations in Java?

Java 8Object Oriented ProgrammingProgramming

Annotations are a tag (metadata) which provides info about a program.

  • Annotations in Java Start with the symbol ‘@’.
  • They are used by the compiler to detect errors.
  • Software tools to generate code.
  • They are used to show attributes of an element: e.g. @Deprecated, @Override.
  • Annotation are used to describe the purpose of an element of the framework, e.g. @Entity, @TestCase, @WebService
  • Annotations describe the behaviour of an element: @Statefull, @Transaction.

Example

Live Demo

class Sample{
   public void display(){
      System.out.println(" ");
   }
}
public class Test extends Sample {
   @Override
   public void display(){
      System.out.println("Welcome to Tutorialspoint");
   }
   public static void main(String[] args) {
      Test obj = new Test();
      obj.display();
   }
}

Output

Welcome to Tutorialspoint
raja
Published on 29-Dec-2017 11:07:58
Advertisements