Transient is a modifier and annotations are also a kind of modifiers. This is information is meant for programmers, automated tools, java compiler and runtime. Now instead of having such keywords decorating an attribute annotations provide a generic way of adding information to class/method/field/variable. For example take serialization, we have the keyword transient to tell that this field is not serializable. In java we have been passing information to compiler for long. Annotations are not only comments, it brings in new possibilities in terms of automated processing. One main difference with annotation is it can be carried over to runtime and the other two stops with compilation level. Annotations were introduced in JDK 1.5 Uses of AnnotationsĪnnotations are far more powerful than java comments and javadoc comments.
ANNOTATIONS IN JAVA CODE
IDE benefits using this javadoc as it is able to render information about the code as we develop. Javadoc facility gives option for understanding the code in an external way, instead of opening the code the javadoc document can be used separately.
Therefore, we can use a tool and parse those comments and prepare a javadoc document which can be distributed separately. The way we need to add is organized using a syntax. Javadoc is an additional step over it, where we add information about the class, methods, variables in the source code. We have basic java comments infrastructure using which we add information about the code / logic so that in future, another programmer or the same programmer can understand the code in a better way. It can be parsed by the compiler, annotation processing tools and can also be made available at run-time too.
In other words, organized data about the code, embedded within the code itself.
Last modified on September 7th, 2014 by Joe.Īnnotation is code about the code, that is metadata about the program itself.