What are annotations in Java?

Created May 8, 2012

Brad Jones (jGuru)

Annotations are a language construct that is introduced in Java 5.0 that allows metadata to be assigned to classes, interfaces, fields, and methods. Such metadata is often called attributes. (Annotations were defined in JSR-175)

Annotations are used like other keyword within the Java language. Annotations, however, differ in that they are preceded with an '@'. Additionally, annotations are expected to be located in certain areas. For example, the target may be a package, a class, an enum, an interface, a field, a cosntructor, a method, a parameter, a local variable declaration, or some combination of these.