Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Annotation guide

 
Pawanpreet Singh
Ranch Hand
Posts: 264
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

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

Thanks
Pawan
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • 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 Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Marco.
 
Pawanpreet Singh
Ranch Hand
Posts: 264
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • 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
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • 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 Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ulf and Marco.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic