16.1 Annotation

An annotation is a form of metadata that provides data about a program that is not part of the program itself. Annotations have no direct effect on the operation of the code which is annotated. The annotation has a number of uses and few of them are as follows: 

  • Annotation can be used by the compiler to detect errors or suppress warnings.
  • Annotations can be examined at runtime.
  • Software tools can be written that process annotation information to generate code, XML files, etc.

An important use of annotation in test automation is to define the test type (functional, regression) and test functional area (customer accounts, funds transfer, etc., for a banking application). Once this information is defined as an annotation in tests, the tool can be written to selectively execute a specific type of test. Also, the tool can provide info about the test coverage in each functional area.

16.1 | Built-in Annotations

Java provides some built-in annotations. Few of them are listed below:

  • @Override: Verifies that the specific method is an override. It causes a compile error if the method is not found in one of the parent classes or implemented interfaces.
  • @Deprecated: Marks the specific method as obsolete. It causes a compile-time error if the specific method is used.
  • @SuppressWarnings: Instructs the compiler to suppress the compile-time warnings which match the annotation parameters.

Section 'Interfaces' shows the use of @Override annotation.

Annotations can also be used to annotate annotations. Listed as follows are few annotations that define the behavior of an annotation:

  • @Retention: Specifies how the annotation is stored- whether in code only or compiles into the class or available at runtime through reflection.
  • @Documented: Marks another annotation for inclusion in the documentation.
  • @Target: Marks another annotation to restrict the kind of java elements the annotation may be applied to.
  • @Inherited: Marks another annotation to be inherited to a subclass of annotated class.

5 comments:

Renuraj said...

It was helpful indeed. Thanks a lot for the content and Keep maintaining a great job...!
Pega Training in Chennai
Pega Training Institutes in Chennai
Tableau Training in Chennai
Oracle Training in Chennai
Oracle DBA Training in Chennai
Job Openings in Chennai
Social Media Marketing Courses in Chennai
Primavera Training in Chennai
Advanced Excel Training in Chennai
Embedded System Course Chennai
Spark Training in Chennai

subhashini said...


Great Post!!! Thanks for sharing your blog and waiting for your new updates.
DevOps certification in Chennai
DevOps Training in Chennai
devops training in bangalore
devops training in coimbatore
Devops Course in Coimbatore
Best devops training in Coimbatore
devops training institutes in Coimbatore
ielts coaching centre in coimbatore

shalini said...

Thanks for sharing the valuable information. This blog contains various good concept and ideas.
DOT NET Training in Chennai
DOT NET Training in Bangalore
DOT NET Training Institutes in Bangalore
DOT NET Course in Bangalore
Best DOT NET Training Institutes in Bangalore
DOT NET Institute in Bangalore
Dot NET Training in Marathahalli
AWS Training in Bangalore
Data Science Courses in Bangalore
DevOps Training in Bangalore

arshiya fouzia said...

Thanks for sharing the useful information
software testing training in chennai

guptha said...

Thank you for this blog. I have read this and it gives more useful info to me.
statistics for data science tutorial
hacking tutorial tips and tricks