Java Annotations, XDoclet, or Neither?


First, let me explain why I have "Neither" on the subject line. Annotations in Java have been and remain controversial. They are a way to place tags in your Java source code to facilitate the automatic generation of source code artifacts, e.g. XML configurations or other boilerplate Java code. A very common use might be to place annotations in your POJO (plain old Java object) that allow for the automatic generation of Hibernate object-relational mapping (ORM) XML files (i.e. the *.hbm files). Folks in the "Neither" camp argue that annotations clutter the code and that code and configuration ought to reside in separate files. Folks who favor annotations argue that having configuration inline with the code makes it easier to keep track of all aspects of the component -- only one Java file per component -- and reduces mundane work since tools can use brief annotations in the primary Java source file to generate elaborate peripheral artifacts. However, once we're convinced of the benefit of annotations, we still have the challenge of choosing between XDoclet, which is what started it all, and Java annotations, which is a feature in Java 5 that makes annotations part of the Java language. In my view, annotations are the way to go. Further, Java annotations are superior to XDoclet because they are part of the Java language, can be validated during compile-time, included into the compiled code, and queried at run-time via reflection. Creating a new Java annotation is as simple as creating a new inline interface-like Java structure.

Comments

Popular posts from this blog

Utility trailer buying guide

My Experiments with the PICAXE 08M2+

How to Select and Install Shelves