• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding annotations

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?




 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read Annotations for start.
 
Thennam Pandian
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kemal,

I have already gone through the link.
The link doesn't answer my questions.
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, then which kind of annotations are you having trouble with? Compile time annotations? Run time annotations? Documentation annotations?
 
Thennam Pandian
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to understand the annotations in general.
 
Jayesh A Lalwani
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The posted link has a good general explanation of annotation. Which part are you having trouble with?
 
Thennam Pandian
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If you think the above link has answer for my questions, Could you please give the answer for each questions.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Thennam Pandian
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If everybody can understand everything from the reference link or tutorial , then what is the need of this forum?
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Annotations are designed to reduce the complexity of xml-based configuration.

WP
 
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
reply
    Bookmark Topic Watch Topic
  • New Topic