Java Annotation is a tag that represents the metadata i.e. attached with class, interface, methods or fields to indicate some additional information which can be used by java compiler and JVM.
Annotations in Java are used to provide additional information, so it is an alternative option for XML and Java marker interfaces.
First, we will learn some built-in annotations then we will move on creating and using custom annotations.
There are several built-in annotations in Java. Some annotations are applied to Java code and some to other annotations.
Built-In Java Annotations used in Java code
@Override
@SuppressWarnings
@Deprecated
Understanding Built-In Annotations
Let's understand the built-in annotations first
There are few points that should be remembered by the programmer.
Method should not have any throws clauses
Method should return one of the following: primitive data types, String, Class, enum or array of these data types.
Method should not have any parameter.
We should attach @ just before interface keyword to define annotation.
It may assign a default value to the method.
There are three types of annotations.
*Marker Annotation
*Single-Value Annotation
*Multi-Value Annotation