Annotations in Java introduced in Java 1.5. Now it is an essential part of Java technology and most of the frameworks like Spring ,Hibernate are using annotations.
Annotations in Java
Annotations gives data about a program . Annotation is not a part of program logic. Instead it provides metadata about program.Annotations usually appear just before the definition of a class or a method or an attribute of a class ,with an @ symbol.
Annotations are useful in many ways. Some of them are:
1)To give some information for the compiler
2)To pass some information to process while running the code.
Now let us discuss the compile time annotations. The concept of annotation will become more clear once we finish the discussion.
There are three inbuilt annotations in Java for compile time processing . They are :
@Deprecated :- If a method is annotated using @Deprecated then it means the method should no longer be used. When a method is annotated with this annotation then a compile time warning will be generated.The same can be applied to a class , method or an attribute in a class.
@Override:-If a method is annotated with this , it means that it is an overridden method of the super class.
@SuppressWarnings-:It asks the compiler to suppress all warnings that can be generated.
We can define our own annotations.This is very useful because all modern frameworks uses this technique to simplify the coding. The steps in defining our own annotation is explained here