Dictionary meaning of Annotation
Annotation refers to a note by way of explanation or comment added to a text or diagram.
Java annotations are used to provide the meta data to our Java code. Meta data is the additional information which can be used for any class, interface, method or field. Java annotations can be used as an alternative option for XML and java marker interfaces. Java annotations were added to Java from Java 5.
Use of java annotations
Java annotations are mainly used for the following:
- Compiler instructions
- Build-time instructions
- Runtime instructions
Java provides the 3 in built annotations which are used to give certain instructions to the compiler. Java in built annotation are @Deprecated, @Override & @SuppressWarnings.
Java annotations can be used for build time or compile time instructions. These instructions can be used by the build tools for generating source code, compiling the source, generating XML files, packaging the compiled code and files into a JAR file etc.
Normally, Java annotations are not present in your Java code after compilation. However, we can define our own annotations that can be available at runtime. These annotations can be accessed using Java Reflection.