• 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

Java Annotation guide

 
Ranch Hand
Posts: 264
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,

I need to know what are the annotation. Is there any good resource for this.

Thanks
Pawan
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pawan,

annotations were introduced to the Java language with version 1.5. In short they are kind of comments or hints you can insert into Java code. The big advantage is that they can easily be processed and are handled like Java classes which wouldn't be as easy or even possible with ordinary code comments. Oh, and you can of course define your own annotations.

So you can insert any kind of meta data directly into the source code and it's easy for any tools to recognize and handle the relevant meta data. Take a look at Sun's tutorial for more information on annotations

Marco
[ May 28, 2008: Message edited by: Marco Ehrentreich ]
 
Pawanpreet Singh
Ranch Hand
Posts: 264
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Marco.
 
Pawanpreet Singh
Ranch Hand
Posts: 264
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marco,
http://java.sun.com/j2se/1.5.0/docs/guide/language/annotations.html

link has lines

we need not to create DD for EJBs, we can do deployment settings using annotations, but my question is that for change in setting, we have to change java file and later we have to compile it again. Is it not a tough job.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not familiar with the annotations defined for EJBs, but there are several ways to use annotations.

One way would be like you described - using the annotations in the class files directly for the deployment. You're right that that would indeed require recompilation for changes, and thus would be rather inconvenient.

Another way would be to create a DD from the annotations at build time. The DD file would reflect what's in the source -which presumably are reasonable defaults-, and could then be used as the basis for further customization, if necessary.

One could also envision a scheme where what's in the class files is used for deployment, but could be overridden by a DD file if necessary. This is actually the approach taken by the upcoming servlets/JSP specification - it defines a number of annotations, but allows those to be overridden by the web.xml file.

Either of these last two options would be much better than the first one.
 
Marco Ehrentreich
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With EJB 3.0 (and I think you'll be using version 3.0 if you're using annotations) you have to possibilities to give deployment and container instructions. You can use the mentioned annotations and you can still use an XML descriptor file as used in older versions of EJB, i.e version 2.x.

If you need or want to specify other parameters after compilation you can use the XML descriptor for these tasks. The options specified in the descriptor file take precedence over the same options already specified with annotations directly in the source code files.

So it's perhaps the best to give reasonable default values in the source code with annotations and use the XML descriptor only where really necessary to override parameters or give additional ones to the container. This is pretty much the same Ulf already told you for the web.xml descriptor of JSPs and servlets.

Marco
[ May 28, 2008: Message edited by: Marco Ehrentreich ]
 
Pawanpreet Singh
Ranch Hand
Posts: 264
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Ulf and Marco.
 
Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic