In programming, annotations are used to add information to a code element which cannot be expressed by the type system.
In programming, annotations are used to add information to a code element which cannot be expressed by the type system.
Java annotations
Up to java1.4 annotations were only usable inside comments and were used for denoting special information like the author of a class or method or references to other entities.
In some cases they were also used for code generation, by facilitating the javadoc toolchain.
As these annotations were part of the code, it was not possible to use them in any way at run time since they were not part of the byte code.
With java-5, annotations became a proper part of java syntax. Annotations can be defined using a syntax similar to the definition of interfaces. They can be used to annotate classes, methods, fields, parameters and packages.
Depending on the definition an annotation is available in source code, byte code or run time. Therefore they can be used for code generation, byte code manipulation at class loading time and via reflection at run time.
For info more see Wiki page and docs.oracle.com
C# Attributes
c# Attributes are a similar concept to Java annotations, they provide a powerful method of associating declarative information with C# code (types, methods, properties, and so forth). Once associated with a program entity, the attribute can be queried at run time and used in any number of ways.