Annotations to represent the metadata in java

Posted by Gyan Guide on May 11th, 2017

Introduction :

Annotations , a form of metadata, provide data about a program that is not part of the program itself. Annotations have no direct effect on the operation of the code they annotate.

Java Annotations

Java Annotationis a tag which is used to represents the metadata(data about data)i.e. attached with class, interface, methods or fields to indicate some additional information which can be used by java compiler and Java Virtual Machine (JVM) .

Annotations are used to give additional information, so it is an alternative way for XML and java marker interfaces.

Uses of Annotations :

Annotations have a number of uses, among them: java/j2ee classes bangalore

1) Information for the compiler — Annotations can be used by the compiler to detect errors or suppress warnings.

2) Compile-time and deployment-time processing — Software tools can process annotation information to generate code, XML files, and so forth.

3) Runtime processing — Some annotations are available to be examined at runtime.

Where Annotations Can Be Used :

Annotations can be applied to declarations: declarations of classes, fields, methods, and other program elements. When used on a declaration, each annotation often appears, by convention, on its own line.

Built-In Java Annotations :

There are several built-in annotations in java . Some annotations are applied to java code and some to other annotations. Advanced java training in bangalore These are -

- @Override

- @SuppressWarnings

- @Deprecated

@Override Annotation :

@Override annotation assures that the subclass method is overriding the parent class method. If it is not so, compile time error occurs.

Sometimes, we does the silly mistake such as spelling mistakes etc. So, it is better to mark @Override annotation that provides assurity that method is overridden.

@SuppressWarnings :

@SuppressWarnings annotationis used to suppress warnings issued by the compiler.

@Deprecated :

@Deprecated annoation marks that this method is deprecated so compiler prints warning. It informs user that it may be removed in the future versions. So, it is better not to use such methods.

Java Custom Annotation :

Java Custom annotations or Java User-defined annotations are easy to create and use. The @interface element is used to declare an annotation.Java course in bangalore

@interface MyAnnotation{}

Here, MyAnnotation is the custom annotation name.

Points to remember for java custom annotation :

There are few points that should be remembered :

  1. Method should not have any throws clauses

  2. Method should return one of the following: primitive data types, String, Class, enum or array of these data types.

  3. Method should not have any parameter.

  4. We should attach @ just before interface keyword to define annotation.

  5. It may assign a default value to the method.

    Types of Annotation :

There are three types of annotations.

  1. Marker Annotation

  2. Single-Value Annotation

  3. Multi-Value Annotation

    java training center bangalore

  4. 1) Marker Annotation :

An annotation that has no method, is called marker annotation. For example:

@interface MyAnnotation{}
The @Override and @Deprecated are marker annotations

2) Single-Value Annotation :

An annotation that has one method, is called single-value annotation. For example:

@interface MyAnnotation{

int value();

}

3) Multi-Value Annotation :

An annotation that has more than one method, is called Multi-Value annotation. For example:

@interface MyAnnotation{

int value1();

String value2();

String value3();

}

Built-in Annotations used in custom annotations in java :

- @Target

- @Retention

- @Inherited

- @Documented

@Target :

@Targettag is used to specify at which type, the annotation is used.

Best core java training in bangalore

@Retention :

@Retention annotation is used to specify to what level annotation will be available.@Inherited ;

By default, annotations are not inherited to subclasses. The @Inherited annotation marks the annotation to be inherited to subclasses.

@Documented ;

The @Documented Marks the annotation for inclusion in the documentation.

This is the short description about the annotations in java to get the more knowledge on java join Infocampus Software Training Institute .

Author :

Infocampus is the best institute for java/j2ee classes bangalore with live project and 100% placement support. For Java course 4 days free demo classes are available. Java Training is provided by the more than 10 years experienced trainers.

Learn packages, multithreading , singleton class , servlet , struts framework in Core & Advanced Java classes. Every weekend mock test and mock interviews are conducted for Advanced java training. Infocampus provides best core java training in bangalore in lesser fees.

To get the more information on java course call at : 9738001024 or to get the syllabus of Core & Advanced Java enquire at : http://www.infocampus.co.in/java-training-bangalore.html


Gyan Guide

About the Author

Gyan Guide
Joined: February 8th, 2017
Articles Posted: 35

Claim 1 FREE Stock! No Purchase Necessary!
You have a 100% chance of receiving one free stock! Click to claim and have a chance to get one share of Facebook, Visa, Microsoft and others for free!
FREE App - Earn up to 25/gal cash back on gas!
Download this FREE app and earn cash-back when you buy gas, groceries and food! 100% FREE to join and FREE to earn cash back on your everyday purchases!
Quality Office Furniture USA Shipped Direct - Madison Liquidators
Nationwide vendor of quality office furnishings including Desks, Office Chairs, Conference Tables, Cubicles and more!
Earn HNT Tokens with a Helium Hotspot!
Pre-Order a Helium hotspot and earn HNT tokens that are redeemable for USD. Set it and forget it!
Lolli: Earn Free Bitcoin When You Shop Online!
Lolli is a rewards application that gives you bitcoin for shopping at your favorite online stores.
Fold - Earn free bitcoin when you shop
Earn bitcoin cashback rewards when you shop at top retailers, including Amazon, Uber, Starbucks, Chipotle, and more. Download the app, sync your payment method and start earning bitcoin today!