3

Possible Duplicate:
Xml configuration versus Annotation based configuration

Can some one let me know what are the main advantages of java Annotations over Xml, i heard meta meta always while searching about this in google, what that meta.

Thanks a lot.

Community
  • 1
  • 1
Siva
  • 3,297
  • 7
  • 29
  • 35

3 Answers3

5

Meta data is some kind of description that you can supply along with your data. In java its 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 :

  • Static type checking - the compiler will check for you where the annotation (once defined properly) is applicable and how

  • Clean code - its much easier to see (visually) the meta data defined in annotations

However it comes at a price:

  • XML doesn't require recompilation when you want to change something. With annotation you'll have to recompile.

Hope this helps

Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
1

Annotations are attached to classes and can be processed via reflection. XML has to be parsed with some library. Main disadvantage of annotations is that they are created at compile time and cannot be changed afterwards - if you need flexible configuration you shall stick with xml / other means.

Konstantin Pribluda
  • 12,329
  • 1
  • 30
  • 35
1

The main advantage (or one of the main advantages) is that 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.

bchetty
  • 2,231
  • 1
  • 19
  • 26