|Navigate Javadoc & Annotations topic: )|
In Java, an annotation is a language construct that was introduced in J2SE 1.5 that provides a mechanism for including metadata directly in the source code.
Annotations can provide metadata for java classes, attributes, and methods. Syntactically, annotations can be viewed as special kind of modifier and can be used anywhere that other modifiers (such as
final) can be used
One of the main forces of adding this feature to Java was the wide spread use of XML descriptors to add additional information, metadata for Java classes. Frameworks like EJB, JSF, Spring, Hibernate were heavily using external XML descriptors. The problem of those external descriptors is that those files are out of reach of the Java compiler and for that reason compiler type checking could not be used. A small spelling mistake bug in a huge XML descriptor file is hard to locate and fixed. The Java annotations on the other hand use the Java compiler type checking features, so annotation names spelling mistakes will be caught by the Java compiler.
In summary, annotations can be...
- used as a source of information for the compiler;
- made available for compile-time or deployment-time processing;
- examined at runtime.
-  The Java™ Tutorial on Annotations