What are annotations in Java?
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
Published on 29-Dec-2017 06:37:58