i am new to java here, I was reading about annotations and xml, personally I find out xml has lot of advantages like it can be put outside application, changes can be made without recompiling class files. If i use annotations if I need to make changes need to go to source code and recompiling should be done. If this is the case why should we use annotations
The biggest disadvantage of XML is indeed its size. Multiple lines are needed for things that you can do in one simple annotation. They are far away from the part in the code where it applies, whereas annotations are just on top of them. So annotations seem a lot more logical and simpler.
XML configurations can take a lot of work when there are a lot of beans, while annotations minimize the XML configurations. Annotation injection is performed before XML injection. Thus, XML configurations will override that of the annotations.
The benefits of type annotations and example use cases For instance, they can produce informational messages for the developer at compile time, detecting errors or suppressing warnings. In addition, annotations can be processed to generate Java source files or resources that can be used to modify annotated code.
what is easy to understand? Obviously, the Java-based config is easy to understand. people who write codes and others can easily understand java code than XML. and you do not need to know about XML if you only know Java.
Advantages of the annotation:
1) All the information is in a single file (no need to open two files to configure a given behavior)
2) When the class changes, no need to modify the xml file
Advantages of xml file:
1) Clear separation between the POJO and its behavior
2) When you do not know which POJO is responsible for the behavior, it is easier to find that POJO (searching in a subset of files rather than all the source code)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With