Why use Java annotations?

Java 8Object Oriented ProgrammingProgramming

Annotations provide information about java elements. Annotations can be interpreted by compiler or IDE at compile time or by JVM at runtime. Annotations can be used

  • to show attributes of an element: e.g. @Deprecated, @Override, or @NotNull

  • to describe the purpose of an element of the framework, e.g. @Entity, @TestCase, @WebService

  • to describe the behavior of an element: @Statefull, @Transaction

Before Java 5, XML was primarily used to store information about java objects, with annotations, this information can be stored within the java code itself.

Updated on 24-Feb-2020 10:15:44