Meaning Of annatations and use

Meaning Of annatations and use

View Answers

December 1, 2008 at 12:31 AM

Hi friend,

Annotation is the way of associating the program elements with the meta tags so that the compiler can extract program behavior to support the annotated elements to generate interdependent code when necessary.

It provide data about a program that is not part of the program itself.
They have no direct effect on the operation of the code they annotate.

Annotations have a number of uses, among them:

* Information for the compiler ? Annotations can be used by the compiler to detect errors or suppress warnings.

* Compiler-time and deployment-time processing ? Software tools can process annotation information to generate code, XML files, and so forth.

* Runtime processing ? Some annotations are available to be examined at runtime.

Annotations can be applied to a program's declarations of classes, fields, methods, and other program elements.

Defining an annotation (Annotation type)

public @interface Example {
String showSomething();
}

Annotating the code (Annotation)

Example (showSomething="Hi! How r you")
public void anymethod() {
....
}


Annotation Types: Three types of annotations types are there in java.

* Marker: Like the marker interface, marker annotations does not contain any elements except the name itself.
The example given below clarifies the concept of marker interface.

Example:

public @interface Example{

}

Usage:

@Example
public void anymethod() {
------------
}

* Single-value: This type of elements provide only single value.
It means that these can be represented with the data and value pair or we can use the
shortcut syntax (just by using the value only within the parenthesis).

Example:

public @interface Example{

String showSomething();

}

Usage:

@Example ("Hi ! How r you")
public void anymethod(){

--------

}

* Multi-value or Full-value: These types of annotations can have multiple data members.
Therefore use full value annotations to pass the values to all the data members.

Example:

public @interface Example{

String showSomething();
int num;
String name;

}

Usage:

@Example (showSomething = "Hi! How r you", num=5, name="zulfiqar" )
public void anymethod{

// code here

}

For read more information on Annotations visit to :

http://www.roseindia.net/hibernate/hibernateannotations/hibernate-annotations-tutorial.shtml

http://www.roseindia.net/ejb/Annotations.shtml

Thanks









Related Tutorials/Questions & Answers:
Meaning Of annatations and use - Java Interview Questions
Meaning Of annatations and use  Hi all use of Annatations and exat meaning of annatations we create our own annatations give an Example... or we can use the shortcut syntax (just by using the value only within
why we use ^ operator in sql, and what is the meaning of that operator?
why we use ^ operator in sql, and what is the meaning of that operator?  why we use ^ operator in sql, and what is the meaning of that operator
Advertisements
Meaning of invoice
Meaning of invoice  hello, What is the meaning of invoice?   hii,ADS_TO_REPLACE_1 Invoice is a statement which contains the following listed things. Invoice Number Invoice dateADS_TO_REPLACE_2 Name and address
what is the meaning of abstract?
what is the meaning of abstract?  what is the meaning of abstract
what is the meaning this coad?
what is the meaning this coad?  what is the meaning this coad? Example Form example form = (Example Form) form
ModuleNotFoundError: No module named 'meaning'
ModuleNotFoundError: No module named 'meaning'  Hi, My Python... 'meaning' How to remove the ModuleNotFoundError: No module named 'meaning... to install padas library. You can install meaning python with following command
what is the meaning of this or explain this
what is the meaning of this or explain this  List<Object[]> list=query.list();   Hi Friend, It will return the query values in the form of list. For more information, visit the following link: Hibernate
MEANING OF THe CODE IN BOLD LETTERS
MEANING OF THe CODE IN BOLD LETTERS  public static void main(sting args[]) { shape s[] = {new circle(),new rectangle()}; } //HERE SHAPE RECTANGLE AND CIRCLE ARE THREE CLASSES WHICH ARE DEFINED EARLIER IN THE PROGRAM
What is the special meaning of __sleep and __wakeup?
What is the special meaning of __sleep and __wakeup?  What?s the special meaning of _sleep and _wakeup
What is the meaning of Java Platform?
What is the meaning of Java Platform?  Hi, Java is is very popular there are many requirements of Java Developer. I want to understand the difference between Java Platform and simple Java. What is the meaning of Java Platform
ModuleNotFoundError: No module named 'name-meaning'
ModuleNotFoundError: No module named 'name-meaning'  Hi, My Python... 'name-meaning' How to remove the ModuleNotFoundError: No module named 'name-meaning' error? Thanks   Hi, In your python
What?s the special meaning of __sleep and __wakeup?
What?s the special meaning of __sleep and __wakeup?  What?s the special meaning of _sleep and _wakeup
Tattoo Ideas for Girls with Meaning
Tattoo Ideas for Girls with Meaning: Tattoos with deep meaning While many tattoos are just creative work of art, some text tattoos have a deeper meaning. There are many tattoo ideas for girls with meaning. To show pain and distress
Introduction
be differ in meaning based on different use of uppercase and lowercase letters. Sometime words can differ in meaning with the same words while starts with capital
Keyword - this
Keyword - this       A keyword is a word having a particular meaning to the programming language... variables same. Now to avoid the confliction between them we use this keyword
Green UML
Green UML       green is a LIVE round-tripping editor, meaning that it supports both software engineering and reverse engineering. You can use green to create a UML
Baby names iPhone, Baby Names Application, Baby name iPhone app, iPhone Baby Names, iPhone baby apps,iPhone baby application
section to be use later. The near and dears can help you in selecting names... to your origin, sex, religion, country and race but also provides the meaning to any particular name. You can also search the meaning of your own name or your
Show Oval Icons
is an image that shows some concept or specific entity with meaning for the user...(Component container, Graphics g, int p, int q) { g.drawOval(p, q, width - 1...;Graphics g,    int p, int q) {   g.drawOval
Web 3.0
Web 3.0         Web 3.0 is a term, which definition is not confirmed or defined so far as several experts have given several meaning, which do not match to each other
Web 3.0 Technologies
Web 3.0 Technologies       Web 3.0 Web 3.0 is a term, which definition is not confirmed or defined so far as several experts have given several meaning, which do
JavaScript Variables
and this should be start with either a letter or underscore. We can use var
Web 3.0
Web 3.0       Web 3.0 is a term, which definition is not confirmed or defined so far as several experts have given several meaning, which do not match to each other, but sometimes
Java Keywords
Java Keywords Keyword is a reserved word in programming language which is predefined. Because it has a special meaning. keyword cannot be used as name for class, method and function. Keyword cannot be used as a identifier also
Why we should use string args[] in main method in java?
Why we should use string args[] in main method in java?  we use only string in the main method not any other one.. specify the reason... and tell me each and every meaning of public static void main(String args[])...   
Difference between Java and C++
Difference between Java and C++ Java is an Object Oriented Programming(OOPs) language, developed by James Gosling 1992. Important feature of java is that it allows the developer to Write Once Run Anywhere (WORA) meaning
What is maven dependency and how to use it in project?
What is maven dependency and how to use it in project?  I am new... dependency. What is the meaning of maven dependency and where to get it How to use Maven in Project? What is maven dependency and how to use it in project
java swing
java swing  meaning of out.flush
Java split string example
Java split string example This section illustrates you the use of split() method. The String class has provide several methods for examining the individual... a special meaning in a regex expression. Here is the code: class StringSplitExample
help me please
help me please  how can i do dictionary with the use of array code in java, where i will type the word then the corresponding meaning for that word will appear...thanks
struts-config.xml - Struts
struts-config.xml  in struts-config.xml i have seen some code like in this what is the meaning of "{1}". when u used like this? what is the purpose of use
java code
java code  what is meaning bufferedreader
java code
java code  what is meaning bufferedreader
interface - Java Beginners
Interface meaning in java  What is the meaning of Interface? and why we need to call
Why to use Spring Framework?
Why to use Spring Framework in a web application? In this article I... is so useful and easy to use that it is used in almost all the modern enterprise... the JEE based applications easier and fun. It aims to provide the easy to use
urgent...pleAse help me.....please!
urgent...pleAse help me.....please!  please help me urgent! how can i do dictionary with the use of array code in java, where i will type the word then the corresponding meaning for that word will appear...thanks
tools in java - Java Interview Questions
tools in java  HI! Can you please tell me that what are the tools available for desining the java applications. And also for oracle which tools we use. Exactly what is the meaning of tools in java or in orcle pl
java - JDBC
java  what is the meaning of the precompiled query in preparedStatement object
__sleep and __wakeup
__sleep and __wakeup  What?s the special meaning of _sleep and _wakeup
java
java  What is the meaning of File file : f.listFiles() in java
hash value
hash value   what is the meaning of this line private int hashValue = 0
INSTANCE
INSTANCE  PLEASE TELL ME THE EXACT MEANING OF INSTANCE?AND EXPLAIN
java
java   how to search the meaning of the word in a String that will be asked to enter a word of your own choice and then you will get the meaning of that word from the String
Applet In Jsp
;    In this example we are going to show you how you can use... what is the meaning of an applet. Applets are small programs or applications..., usually written in java. We can use the applets in jee also. In jee it runs
HTML5 figure example, Define figure and figcapation tag.
HTML5 figure example, Define figure and figcapation tag. In this section, you will see the use of figure and figcapation tag of HTML5. Both are new... remove figure tag. It can not affect document actual meaning. It works
XMLHttpRequest Object:
; As the use of XML and web services is increasing day by day, it is good...;); How to use an XMLHttpRequest Object and Handle the server response: ADS_TO_REPLACE_3 We need to create an XMLHttpRequest, after that we will use few
Analysis tool - SourceGlider for Eclipse
programs make heavy use of methods overloading, polymorphism and subtle design... of quality assurance. You can use Points-to Analysis to find out all possible cases... of reverse engineering. Find out the actual meaning of fields and variables
P - Java Glossary
between the files and make possible to use them in an easier way.   .... Keywords are basically reserved words which have specific meaning relevant... are basically reserved words which have specific meaning relevant to a compiler in java
path - Java Beginners
meaning of path and classpath  what is the meaning of path and classpath. How it is set in environment variable.  Path and ClassPath in in JAVAJava ClassPath Resources:-http://www.roseindia.net/java/java-classpath.shtml
Reference passing in java
Reference passing in java  plz tell me wat d meaning of refernce in java? for example : Class M(){ N n; } Class N(){ } wats dis meaning
isErrorPage attribute in the page directive
to false, meaning that the user cannot make use of the exception object.... By default, the value is set to false, meaning that the user cannot make use..., meaning that the user cannot make use of the exception object in the JSP page

Ads