I'm very eager to know about custom constraints can be added in default java compiler I wanna implement a functionality only when java program has my own annotations, so the compiler has to read my annotations and it should implement the what I wanted. Is it possible? (Like this I wanna to check my own exceptions etc.) Thanks in advance.
I'm not sure because I've never used it myself, but maybe you can use the apt tool that's included with the JDK to do what you want.
Annotations are not really meant for extending the Java language in the way that you seem to want to do. Using the reflection API, you can find out if classes, methods etc. have annotations on them. Most libraries or frameworks that use annotations use the reflection API to read information about the annotations.
Jesper de Jong wrote:Annotations are not really meant for extending the Java language in the way that you seem to want to do.
That's true, as far as the original intent of Sun et al is concerned. However, others have indeed used annotations much as the original poster describes. Check out Project Lombok for example. It might be worthwhile to study just how that's been implemented; I suspect it uses apt internally, as Jesper recommends.