Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do Annotations works internally in Java or any other programming language?

I having hard time understanding importance and benefits of Annotations and so have two questions regarding them:

  1. What are the benefits of Annotations as compared to XML Configuration?
  2. How do Annotations work internally?
  3. Is it fair enough to say that annotation binds application tightly whereas with XML Configuration Application is loosely coupled?

Would appreciate pros and cons comparison with XML Configuration with example so that it would be much more helpful for me to understand.

Regards.

like image 656
Rachel Avatar asked Jul 08 '11 01:07

Rachel


People also ask

What is annotation and how it works?

An annotation is a construct associated with Java source code elements such as classes, methods, and variables. Annotations provide information to a program at compile time or at runtime based on which the program can take further action.

How do spring annotations work internally?

Spring Boot Annotations is a form of metadata that provides data about a program. In other words, annotations are used to provide supplemental information about a program. It is not a part of the application that we develop. It does not have a direct effect on the operation of the code they annotate.

What does annotate mean in Java?

Java annotations are metadata (data about data) for our program source code. They provide additional information about the program to the compiler but are not part of the program itself. These annotations do not affect the execution of the compiled program. Annotations start with @ .

How are annotations used?

Annotations have a number of uses, among them: Information for the compiler — Annotations can be used by the compiler to detect errors or suppress warnings. Compile-time and deployment-time processing — Software tools can process annotation information to generate code, XML files, and so forth.


1 Answers

For your 1st question,

  • Xml configuration versus Annotation based configuration

Personally, I feel, there are two criteria's

  1. Can annotations simplify the metadata ?

    If annotations do not reduce the amount of metadata that you have to provide (in most cases they do), then you shouldn’t use annotation.

  2. Can changes to the metadata break behavior in your application?

    If not, then you can feel comfortable applying the change while the system is running in production. External config files are the best place for the metadata in this case because you don’t want to have to recompile your code to make the change.

For your 2nd question,

  • How Do Annotations Work?

Important Links :

  • What are annotations and how do they actually work for frameworks like Spring?
like image 137
Saurabh Gokhale Avatar answered Oct 21 '22 18:10

Saurabh Gokhale