Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fundamental of Java Programming

Similar presentations


Presentation on theme: "Fundamental of Java Programming"— Presentation transcript:

1 Fundamental of Java Programming
Marwadi Education Foundation’s Group of Institutions Faculty of Computer Applications MCA Sem- III Fundamental of Java Programming (630002) Unit – 5 Annotations

2 Introduction Sun Microsystem added the features like annotation to make the development easier and more efficient in jdk 5. The main objective to develop the annotations is to make the development easier. Annotations behaves like the meta. The literal meaning of meta data is data about data. Java also signifies this meaning. Annotations are like meta data, means you are free to add your code and can also apply them to variables, parameters, fields type declarations, methods and constructors.

3 Introduction 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.

4 Fundamentals of annotations
While going through the annotations you should consider two things. The first one is the "annotation" itself and second one is the "annotations types". An annotation is the meta tag, used to give some life to the code you are using. While annotation type is used to define annotations so that you can use them while creating your own custom annotations.

5 Fundamentals of annotations
An annotation type definition appends an sign at the start of the interface keyword with the annotation name. On the other hand, an annotation includes the sign followed by the annotation type. You can also add the data within the parenthesis after the annotation name. Lets illustrate the concept more clearly by using some examples.

6 Fundamentals of annotations
Defining an annotation (Annotation type) Example { String showSomething(); } Annotating the code (Annotation) Example (showSomething="Hi! How r you") public void anymethod() { }

7 Annotation Types: Three types of annotations types are there in java.
(1) Marker: Marker annotations does not contain any elements except the name itself. The example given below clarifies the concept of marker. Example: Example { } Usage: @Example public void anymethod() { }

8 Annotation Types: (2) 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).

9 Annotation Types: Example: public @interface Example {
String showSomething(); } Usage:  @Example ("Hi ! How r you") public void anymethod()

10 Annotation Types: (3) 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.

11 Annotation Types: 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

12 Thank You


Download ppt "Fundamental of Java Programming"

Similar presentations


Ads by Google