Easy learning with example program codes

java annotations overview

Dictionary meaning of Annotation

Annotation refers to a note by way of explanation or comment added to a text or diagram.

Java Annotations:

Java annotations are used to provide the meta data to our Java code. Meta data is the additional information which can be used for any class, interface, method or field. Java annotations can be used as an alternative option for XML and java marker interfaces. Java annotations were added to Java from Java 5.

Java annotations basics:

A java annotation always starts with the symbol @ and followed by the annotation name. The @symbol signals the compiler that this is an annotation.





Here @ symbol signals the compiler that this is an annotation and the Entity is the name of this annotation.

An annotation can contain zero, one or multiple elements. We have to set values for these elements.

@Entity(tableName = "USERS")

Where we can use annotations?

We can use java annotations above classes, interfaces, methods, fields and local variables. Here is an example annotation added above a class definition:

 public class Users {

Java Annotations List:

  • @Deprecated
  • @Override
  • @SuppressWarnings
  • @Target
  • @Retention
  • @Inherited
  • @Documented

Please follow and like us:

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki