Thursday, April 28, 2022

Annotation In Java

What is annotation in Java with example?

Annotation in java is a kind of a tag that represents the metadata or information attached with class, interface, methods, or fields to show some additional information that Java compiler and JVM can use.

Built-In Java Annotations used in Java code

  • @Override
  • @SuppressWarnings
  • @Deprecated

Built-In Java Annotations used in other annotations (used to create custom annotations)

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

What does annotate mean in Java?

What is a Java annotation type?

Types of Java Annotations

There are five types of Java Annotations which are:

  • Marker Annotations
  • Single Value Annotations
  • Multi-Value Annotation
  • Full Annotations
  • Type Annotation
  • Repeating Annotation

What is annotation in Java and how it works?

@Retention annotation is used to specify to what is the level annotation and where it will be available.There are 3 type of RetentionPolicy like SOURCE, CLASS, RUNTIME

  • RetentionPolicy.SOURCE : This is refers to the source code, It will not be available in the compiled class.
  • RetentionPolicy.CLASS : This is refers to the .class file, available to java compiler but not to JVM . It is included in the class file.
  • RetentionPolicy.RUNTIME : This is refers to the runtime, available to  java compiler and JVM .

No comments:

Post a Comment