Professional Documents
Culture Documents
Hello, I’m newbie to Java world & so new to Spring Boot. So, I don’t have
a prior experience with spring also. As a new one, I’m writing this to new
people to Java. Experts, correct me in the comments if its wrong.
. . .
What is Annotation..?
a note by way of explanation or comment added to a text or diagram.
In Java
1. methods
2. class
3. interface
which adds more information about those for Java compiler / JVM(Java
Virtual Machine).
You may have already experienced with some built-in Java function when
you done with basic Java stuffs.
Like,
Like this
@interface parathan{}
should return a class, method, enum, String like primitive data type
Type of Annotation
1. Marker Annotation
3. Multi-value Annotation
@interface parathan{}
@interface parathan{
int value();
@interface parathan{
@parathan(value=10)
@interface parathan{
int age();
String name();
String country();
@parathan(age=20,name=”Parathan Thiyagalingam”,country=”Sri
Lanka”)
1. @Target
2. @Retention
3. @Inherited
4. @Documented
we use
@Target(ElementType.some_thing)
then
@Target(ElementType.Type)
then
@Target(ElementType.METHOD)
Credit: Javatpoint.com
@Target({ElementType.Type,ElementType.METHOD})
@interface parathan{
int age();
String name();
2. @Retention
SOURCE — this refers the source code, which the annotation will not
be available in compiled class.
CLASS — this refers to the .class file, which the annotation will not
available to JVM but available for java compiler. So, it will be in the
class file.
Eg:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@interface parathan{
int age();
String name();
The above snippet represents the annotation will be available at the run
time & the annotation is targeted to the class.
@Inherited
@interface parathan{ }
class MainClass{}
class Subclass extends MainClass{} //sub class extends the super class
4.@Documented
. . .
The annotation I’m writing here, is because I’m posting REST API in Java
using Spring Boot & MySQL as Parts.
So, there we are using a lot of annotations to make our tasks easy.
72 claps
WRIT T EN BY
Deploying Spring Boot REST API: Java Spring Let’s explore Slice(), Microservices with
apps as Windows Boot and MongoDB Splice() & Spread Spring Boot and Spring
Services T homas Gleason Syntax(…) in JavaScript Cloud.
Okezie Arukwe Parathan T hiyagalingam in Marcus Hert Da Corégio in
freeCodeCamp.org IT NEXT