Annotations in computer programming languages provide data about a program that is not part of the program itself by decorating them.Annotations in computer programming languages provide data about a program that is not part of the program itself by decorating them.
Annotations are mainly used for:
We can apply annotations to a program's declarations of classes, fields, methods, and other program elements. Rather than directly affecting on the program's semantic, they do affect the way programs are treated by tools and libraries, that can affect the semantics of an executing program. We can read the annotations from the class file, source files, or at run time.
Annotations are processed by compiler plug-ins called
annotation processors whenever java source code is compiled. Processors are
capable of producing informational messages, create additional Java source
files or resources which in turn may be compiled and processed. But processors
cannot modify the annotated code itself. The Java compiler stores annotation
metadata in the class files only when the annotation has a RetentionPolicy of
CLASS or RUNTIME, that is used to determine how to interact with the program
elements or to change their behavior.