Java annotations are one of the very important features of core java which are used to associate meta data with your Java code and these meta data with annotations can be processed at compile time, deployment time and runtime time as per the need.
it does not play any role in business logic of the java code and simply associate meta data which can be processed for following purposes:-
Build-time or Deployment time instructions
Java annotations were added to Java since Java 5 (Tiger).
Java has three built-in annotations which are used to give instructions to the Java compiler. These annotations are:
Build-time or Deployment time instructions:-
These annotation are processed at the deployment time or build time.
these annotations are processed at the runtime and it is used in many popular frameworks like Spring ,Hibernate ,JSF, JAX-WS, JAX-WS , JSF 2.x etc.
and some annotations are :-
Spring Annotations - @Service ,@Autowired , @Controller, @PostConstruct etc.
Hibernate Annotations- @Entity , @Table , @Column, @Id, @OneToOne etc
JAX-RS Annotations- @Path, @Consumes, @Produces , @QueryParam, @FormParam etc.
Structure or Definition of a Annotation
As we know that Java allows us to define our own annotation. The annotations which are used to define costume annotations are known as "Meta Annotation".
There are four annotation types in the "java.lang.annotation" package. These so-called meta-annotations are used to annotate other annotation types.
The Annotation which does not have any attributes is known as marker annotation.
Example :- @Override , @ Remote, @Aspect , @RequestBody, @ResponseBody etc.
Single Value Annotations
The Annotation which has only one attribute is known as Single Value annotation.
Example :- @Autowired, @ Qaulifier,@Inject etc.
Multi Values Annotations
The Annotation which has more that one attribute is known as Multi Values annotation.
Example :- @Entity, @ Table, @Cacheable, @CacheEvict, @Column, @Scope, @RequestMapping etc.
Define and Process a Custom Annotation in Java