Java Annotations

Java Annotations

Java annotations are a kind of metadata that can be added to Java source code.
They are usually used by putting the @ symbol in front.
They are available from JDK 1.5 and later.
Java annotations are embedded in class files, generated by the compiler, and then included in the Java Virtual Machine where they operate.

Built-In Annotations

Java defines a set of annotations built into the language. Among the 7 standard annotations, 3 are part of java.lang, and the remaining 4 are imported from java.lang.annotation.

Built-In Annotations Applied to Java Code

  • @Override
  • @Deprecated
  • @SuppressWarnings

Annotations Applied to Other Annotations (Meta-Annotations)

  • @Retention
  • @Documented
  • @Target
  • @Inherited

Additional Annotations Were Added to the Language Starting with Java 7

  • @SafeVarargs
  • @FunctionalInterface
  • @Repeatable

Java Standard Annotations

Among annotations, annotations provided by the Java SE standard are called standard annotations.

Defining Custom Java Annotations with @interface

@interface, meta-annotations, annotation attributes

Using Java Annotations