Main Advantages Of Annotations Over XML

Meta data is some kind of description that you can supply along with your data. In java it’s possible to do with annotations, XML, there are other methods.

In order to take advantage of meta data you should have something that will process this data and decide what happens once the meta data is recognized.

Annotations have a lot of advantages over XML, to name a few:

  1. Static type checking – The compiler will check for you where the annotation (once defined properly) is applicable and how. It offers Static Type Checking. This helps the developers in catching most of the errors at ‘Compile Time’ and keeping the production systems functioning with minimal errors.
  2. Clean code – It’s much easier to see (visually) the meta data defined in annotations. However, it comes at a price:
  3. XML doesn’t require recompilation when you want to change something. With annotation you’ll have to recompile.
  4. Annotations are attached to classes and can be processed via reflection. XML has to be parsed with some library. Main feature of annotations are that they are created at compile time and cannot be changed afterwards – if you need flexible configuration you shall stick with xml / other means.

 

@Annotations

  1. Annotations and Its Benefits in Java
  2. Advantages Of Annotations Over XML
  3. Annotation Programming Basics
  4. Annotation Types
    1. Simple Annotation
    2. Meta Annotation
      1. Meta ‘Target’ Annotation
      2. Meta ‘Retention’ Annotation
      3. Meta ‘Documented’ Annotation
      4. Meta ‘Inherited’ Annotation
  5. Reflection to Extract Annotation Details

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.