Annotations

Annotations #

Annotations are metadata that can be added to classes, methods or properties. They provide additional information about the code, and they can be used by the compiler, tools or frameworks to generate or modify code behavior, perform validations or add runtime functionality.

Annotations are denoted by @ symbol followed by the annotation name. And then they are placed directly befor the code element.

Here is a simple example of an annotation:

class ChildClass extends BaseClass {
	@Override
	public void display() {
		System.out.println("Hello from javatutorials.dev");
	}
}

In Java there are 5 types of annotations.

  • Marker Annotations
  • Single Value Annotations
  • Full Annotations
  • Type Annotations
  • Repeating Annotations