Monday, November 16, 2009

Right usage of Annotations in Java.

When I was reading the annotation in java, I can't really feel where it can be used. Most of them (like me J) think that Annotations are mostly used my IDE like Eclipse and other tools.

In one of my old projects they are using annotations for decision making purposes like permissions, I was not so convinced that is this is right use?.

But today I was learning Xdoclet (a code generation tool),where they use lots of javadocs kind of stuff to give the meta information's to Xdoclet tools. There we are J

*    @version 0.5

*    @web.servlet name="SimpleServlet"

* display-name="Simple Servlet"

* load-on-startup=" l"

*    @web-servlet-init-param name="table" value="production"

*    @web-servlet-init-param name="account" value="accounts"

In above code we are using lots of javadocs comments which are given inputs to Xdoclets, if they are using javadocs like comments it may not force you compile level syntax check.

If we are using Annotations, then we can achieve the compile check. In EJB3 they are using the Annotations for code generations for home interface and other classes.

As of I feel that the only usages of Annotations was it should be used when we do a code generations. I may not sure using Annotations for permission check for API classes is the right decisions?

Please feel free to add comments to this topic. Thank you.


Veera said...

Even Spring framework has started using Annotations, rather than the XML configurations.

Mohammed Yousuff said...

XML files bring the changes with out touching the source code, in that sense annotations lacks a bit :)....

Post a Comment


This content comes from a hidden element on this page.

The inline option preserves bound JavaScript events and changes, and it puts the content back where it came from when it is closed.
Click me, it will be preserved!

If you try to open a new ColorBox while it is already open, it will update itself with the new content.

Updating Content Example:
Click here to load new content