Archive

Archive for October, 2012

What is a Java annotation?

October 15, 2012 Leave a comment

Ahhh… always had this question.
Consider the class below:

In this class, @ManagedBean and @SessionScope are annotations.

An annotation is nothing but a markup. That’s all….

But aren’t annotations interfaces? That’s what Google says.

So yes they are interfaces… Sun merely picked an interface cause developers at that time were aware of interfaces. Note that some annotations take affect at compile time and some at runtime (dictated by the retention policy of that annotation). So this is what happens when an annotation is encountered….

  1. An annotation is always processed by the respective container… this container could be a Spring container (if it is a Spring annotation), JSF container (if it is a JSF annotation), Hibernate container (if it is a Hibernate annotation) and so on. And Java itself if it is a Java annotation.
  2. The container has something called as an annotation processor. This processor scans the code before it runs. So it is the annotation processor does the actions associated with the annotation. The annotation processor has all the intelligence. So if you have two annotations on a class and the annotation processor expects one to be before the other, you will get an error (not sure if it is runtime or compilation time.)
Categories: Java

An awesome ANT tutotial…

October 8, 2012 Leave a comment
Categories: Java, Programming