Posts

Showing posts from October, 2008

Java Annotations - Simple Explanation

Java 5.0 added a lot of language features to Java. One of the new features is Annotations. Annotations are tags in the source code that can be processed by a tool, compiler etc. (e.g. JavaDoc comments "@author"). The purpose of annotations is to simplify programming by helping programmers avoid boiler-plate code. Annotations are not part of the program itself, they provide data about the program. They have no effect on the code that they annotate. Uses for Annotations: 1. Information for the compiler 2. Deployment time processing 3. Runtime processing How do annotations work? Annotations can be applied to packages, classes, parameters, variables, fields or methods. It is defined using an "@" syntax. Annotations has a corresponding annotation type. The annotation type defines the content of the metadata. There are predefined annotations in Java as well as some API's provide their own annotation library. But to define your own annotation, here is how. Defining a s