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.

8 comments:

Rajesh said...

thanks for sharing this information
aws training in bangalore
Amazon web services training in bangalore
best AWS Training institute in Bangalore
aws certification course in bangalore
devops training in bangalore
devops training institutes in bangalore
devops certification course in bangalore
data science training in bangalore

htop said...

nice post
aws training center in chennai
aws training in chennai
aws training institute in chennai
best angularjs training in chennai
angular js training in sholinganallur
angularjs training in chennai
azure training in chennai
data Science training in chennai

anonymous said...

I really enjoyed your blog Thanks for sharing such an informative post.Looking For Some More Stuff.

shuttering works

anonymous said...

I really enjoyed your blog Thanks for sharing such an informative post.Looking For Some More Stuff.

best seo company in bangalore SSS digital Marketing

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

Manthra Pavi said...

Excellent post, it will be definitely helpful for many people. Keep posting more like this.
Ethical Hacking course in Chennai
Ethical Hacking Training Institute in Chennai
Hacking course in Chennai
ccna Training in Chennai
Salesforce course in Chennai
PHP Training in Chennai
Tally course in Chennai
Ethical Hacking course in OMR
Ethical Hacking course in Anna Nagar
Ethical Hacking course in Vadapalani

The India said...

Delhi Agra Jaipur Tour by Bus
Delhi to Jaipur Same Day Tour
Delhi One Day Tour Package
Delhi Sightseeing One Day
Delhi Sightseeing Tour by Bus
Delhi Jaipur One Day Tour Package
Haridwar, Rishikesh Tours by Volvo