aspose file tools*
The moose likes Beginning Java and the fly likes Annotations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Annotations" Watch "Annotations" New topic
Author

Annotations

Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
Hi All,

I am just learning about Annotations and I have a question. I wrote the following code looking at an example but I am trying to understand the meaning here and the whole purpose of doing so.

MyAnnotation.java

Test.java


I really don't understand the above code. Can someone please explain?/

Thanks.
[ November 28, 2008: Message edited by: Arjun Reddy ]

Be Humble... Be Nice.
Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
Anybody?/

Thanks.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

What don't you understand? Annotations are simply a way to specify metadata through Java rather than something like XML. The first bit of code you show defines an annotation and its attributes.

The second part is how you use said annotation, although specifying an annotation on a main method is probably an odd example. In fact your entire example probably makes it more difficult to understand.

Additionally an annotation is useless without the code to process it. So by itself an annotation does nothing. Using the reflection API you can inspect classes and methods and determine what annotations exist. At that time is the work actually done.
[ November 29, 2008: Message edited by: Gregg Bolinger ]

GenRocket - Experts at Building Test Data
Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
Thanks for the reply Gregg. It would be really helpful if you can give an example in code if possible.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Arjun Reddy:
Thanks for the reply Gregg. It would be really helpful if you can give an example in code if possible.


Many people already have. Here is a good place to start:

http://java.sun.com/j2se/1.5.0/docs/guide/language/annotations.html

Also, Google is your friend.
Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
Ok I will check that.

Thanks.
Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
I understood it now Gregg. Thanks for the link.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Annotations