File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Regarding annotations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regarding annotations" Watch "Regarding annotations" New topic
Author

Regarding annotations

Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163

Hi All,

I am new to annotations. Please clarify the followings on annotations

1. When should we go for annotations?

2. What is the advantage of annotations? How annotations helps the developers?

3. Whether the annotations affects the behavior of the class @ run-time? if yes, please explain.

4. How the custom annotations are processed by apt?




Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

Read Annotations for start.


The quieter you are, the more you are able to hear.
Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163
Hi Kemal,

I have already gone through the link.
The link doesn't answer my questions.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2321
    
  28

Ok, then which kind of annotations are you having trouble with? Compile time annotations? Run time annotations? Documentation annotations?
Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163
I want to understand the annotations in general.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2321
    
  28

The posted link has a good general explanation of annotation. Which part are you having trouble with?
Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163

If you think the above link has answer for my questions, Could you please give the answer for each questions.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

1) When you want to provide your code with some additional information (metadata).

2) Annotations per se are not very useful. However, they can be very helpful when combined with tools that can use the information they provide. E.g. you can annotate some methods of your class to be used only for testing purposes (hence, JUnit can use that information).

3) No, they don't affect the way your code compiles/executes (meaning functionality of your class or method cannot be changed just because you add annotation).

4) Annotation Processing Tool
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7639
    
  19

Thennam Pandian wrote:If you think the above link has answer for my questions, Could you please give the answer for each questions.

If it does have the answer to your questions, why should we simply repeat its contents here? If it doesn't - or you can't follow the explanation - then you need to be clear about what it is you don't understand. Nobody is going to provide an "annotations tutorial" in a couple of paragraphs.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163
If everybody can understand everything from the reference link or tutorial , then what is the need of this forum?
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7639
    
  19

Thennam Pandian wrote:If everybody can understand everything from the reference link or tutorial , then what is the need of this forum?

To answer specific questions. It's not supposed to be a substitute for research.

Winston
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Annotations are designed to reduce the complexity of xml-based configuration.

WP
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3611
    
  14

Annotations in my opinion should only be used for tools to inspect and perform actions on source code. They should not be used to make code itself run differently.

I really hate frameworks that use annotations to make the code run. As an example, in my opinion JAX-RS is a huge offender.
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Stephen, Would you rather map your database entities using xml (now two files to change) or @Entity within the pojo itself?

WP
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3611
    
  14

I think annotations are very good to do that sort of thing. After all, you're telling a tool something about your code, so it can work with your code more easily.

One of the things I was referring to, is how in JAX-RS you tell the framework which method it has to run when a specific event occurs using an annotation above that method signature. That's just *wrong*. We have interfaces for that.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2321
    
  28

Stephan van Hulst wrote:Annotations in my opinion should only be used for tools to inspect and perform actions on source code. They should not be used to make code itself run differently.

I really hate frameworks that use annotations to make the code run. As an example, in my opinion JAX-RS is a huge offender.


How about Transactional annotations, DI annotations?

Sure, runtime annotations introduce a new paradigm in Java, but I don't think it is a bad thing. It requires developers to shift their thinking, and introduce a learning curve, but that's not the worst thing in the world.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2321
    
  28

Thennam Pandian wrote:If everybody can understand everything from the reference link or tutorial , then what is the need of this forum?


If reading that reference link doesn't help you understand, it's highly unlikely that reading a post on this forum can make you understand. The reference is written by professional technical writers who spend considerable time thinking about how to present information clearly, and (over time) has been vetted by thousands of programmers.

Sure, it's understandable to have difficulty with certain aspects, and you are welcome to ask specific questions. However, before you do RTFM!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding annotations