Make delicious recipes!

Java Annotations

Annotations provide data about a program that is not part of the program itself.
They have no direct effect on the operation of the code they annotate.
    name = "Benjamin Franklin",
    date = "3/27/2003"

class MyClass() {


Brackets may be omitted if there are no elements.
Example : @Override

Three annotations are provided by the language itself:
  1. @Deprecated
  2. @Override
  3. @SuppressWarnings ({“unchecked”, “deprecation”})

The type of annotation can be defined as an annotation type. The syntax for doing this is:

// Definition of a new annotation 

@interface ClassPreamble 
    String author();
    String date();
    int currentRevision() default 1;
    String lastModified() default "N/A";
    String lastModifiedBy() default "N/A";
    String[] reviewers(); // Note use of array

// Using the new annotation

    author = "John Malkovich",
    date = "01/03/2012",
    currentRevision = 20,
    lastModified = "4/12/2014",
    lastModifiedBy = "Jane Handerson",
    reviewers = {"Mike", "Bob", "Peter"} // Note array notation

public class SomeClass extends Generation2List { ... }

For multi-threading applications, JCIP provides a few handy annotations.

Like us on Facebook to remain in touch
with the latest in technology and tutorials!

Got a thought to share or found a
bug in the code?
We'd love to hear from you:

Email: (Your email is not shared with anybody)

Facebook comments:

Site Owner: Sachin Goyal