What is Java annotation? Write some facts about Java annotation

What is Java annotation?

In Java annotations are meta object in a Java source file and they do not affect the semantics of a program directly. Annotation provides a mean to describe classes, fields and methods.

Built-in Annotations in Java

  • @Override
  • @Deprecated
  • @SuppressWarnings

Facts about Java annotations

  • An annotation always starts with the @ symbol followed by the annotation name
  • Annotations can provide compile-time instructions to the compiler
  • All annotations extends java.lang.annotation.Annotation interface
  • It is possible to create custom annotations
  • Annotations are lot easier compare to XML based configuration

Usage of Java annotations

  • Compilation
  • IDE
  • Testing framework, e.g. JUnit
  • IoC container e.g. as Spring
  • Serialization, e.g. XML
  • Aspect-oriented programming (AOP), e.g. Spring AOP
  • Documentation, e.g. XDoclet
  • Application servers, e.g. EJB container, Web Service
  • Object-relational mapping (ORM), e.g. Hibernate, JPA
Share