Predefined Annotation Types

This section describes annotation types predefined in the current Java version. A tutorial example is also provided on how to use predefined annotation @Deprecated.

In previous tutorials, we have learned how to declare your own annotation types and use them in annotation invocation statements.

Your own annotation types can help you adding information to your Java programs in a more structured way. But need to build your own tools to parse them and process them.

Before build your own annotation processing tool, you may want to look at annotation types predefined in the JDK package and processed by the "javac" compiler and other tools.

Here is a list of annotation types predefined in the current JDK version:

Here is a sample program that shows you how to use the predefined annotation, @Deprecated, on a class declaration:

/* Dummy.java
 * Copyright (c) HerongYang.com. All Rights Reserved.
 */
@Deprecated class Dummy {}

Now if you use this "@Deprecated" in another Java program, you will get a compilation warning.

/* DeprecatedDummyTest.java
 * Copyright (c) HerongYang.com. All Rights Reserved.
 */
class DeprecatedDummyTest {

   Dummy dummy = new Dummy();

   public static void main(String[] arg) {
      System.out.println("Hello world!");
   }
}

Compile the above program to see the warning message:

herong> javac Dummy.java

herong> javac DeprecatedDummyTest.java
Note: DeprecatedDummyTest.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

herong> javac -Xlint:deprecation DeprecatedDummyTest.java
DeprecatedDummyTest.java:6: warning: [deprecation] Dummy in unnamed package
   has been deprecated
   Dummy dummy = new Dummy();
   ^
DeprecatedDummyTest.java:6: warning: [deprecation] Dummy in unnamed package
   has been deprecated
   Dummy dummy = new Dummy();
                     ^

Table of Contents

 About This Book

 JDK - Java Development Kit

 Execution Process, Entry Point, Input and Output

 Primitive Data Types and Literals

 Control Flow Statements

 Bits, Bytes, Bitwise and Shift Operations

 Managing Bit Strings in Byte Arrays

 Reference Data Types and Variables

 Enum Types and Enum Constants

 StringBuffer - The String Buffer Class

 System Properties and Runtime Object Methods

 Generic Classes and Parameterized Types

 Generic Methods and Type Inference

 Lambda Expressions and Method References

 Java Modules - Java Package Aggregation

 Execution Threads and Multi-Threading Java Programs

 ThreadGroup Class and "system" ThreadGroup Tree

 Synchronization Technique and Synchronized Code Blocks

 Deadlock Condition Example Programs

 Garbage Collection and the gc() Method

 Assert Statements and -ea" Option

Annotation Statements and Declarations

 What Is Annotation

 Use "interface" as Annotation

 Default Values for Annotation Elements

 Single-Element Annotation Invocation

 No-Element (Marker) Annotation Invocation

 getAnnotations() Method - Annotation APIs

Predefined Annotation Types

 Java Related Terminologies

 Archived Tutorials

 References

 Full Version in PDF/EPUB