Code Work with Java Annotations

This article tells you how to use Java annotations to take the grunt work out of coding. Annotations are a familiar sight to any Java developer who has ever read the Java API docs.

Annotations are a familiar sight to any Java developer who has ever read the Java API docs. They are the text snippets preceded by an @ sign that have been appearing in JavaDoc comments since Java was introduced. They may seem like simple snippets of extra information, but there is much more to annotations than meets the eye. Here, you will learn how to use annotations at coding time, compile time, and run time to make the most of your development efforts.



What Are Annotations?



An annotation is a snippet of text in a JavaDoc comment that provides a little extra information. For example, listing 1 shows a method that is discouraged from continued use as indicated by the @Deprecated annotation.

Listing 1: A sample annotation in code




/**
* @Deprecated
* This method does something that was super duper ten years ago.
*/
public void doSomething() {
} // doSomething()


When Javadocs are generated for this method, it is flagged as deprecated, and will appear in the Deprecated section of your generated API docs. Also, at compile time, you will receive a warning that you are using a method that is no longer recommended for use.

Although this useful functionality has been around for many years, the real power of annotations was unleashed in JDK 1.5 when the annotations API was made available to developers. For the first time, developers could write their own annotations. This made it possible for developers to create their own home-grown annotations, opening the way for the creation of powerful development tools.

Read the Rest of this Article at Developer.com

Regional Articles
- Code Work with Java Annotations Alabama
- Code Work with Java Annotations Alaska
- Code Work with Java Annotations Arizona
- Code Work with Java Annotations Arkansas
- Code Work with Java Annotations California
- Code Work with Java Annotations Colorado
- Code Work with Java Annotations Connecticut
- Code Work with Java Annotations DC
- Code Work with Java Annotations Delaware
- Code Work with Java Annotations Florida
- Code Work with Java Annotations Georgia
- Code Work with Java Annotations Hawaii
- Code Work with Java Annotations Idaho
- Code Work with Java Annotations Illinois
- Code Work with Java Annotations Indiana
- Code Work with Java Annotations Iowa
- Code Work with Java Annotations Kansas
- Code Work with Java Annotations Kentucky
- Code Work with Java Annotations Louisiana
- Code Work with Java Annotations Maine
- Code Work with Java Annotations Maryland
- Code Work with Java Annotations Massachusetts
- Code Work with Java Annotations Michigan
- Code Work with Java Annotations Minnesota
- Code Work with Java Annotations Mississippi
- Code Work with Java Annotations Missouri
- Code Work with Java Annotations Montana
- Code Work with Java Annotations Nebraska
- Code Work with Java Annotations Nevada
- Code Work with Java Annotations New Hampshire
- Code Work with Java Annotations New Jersey
- Code Work with Java Annotations New Mexico
- Code Work with Java Annotations New York
- Code Work with Java Annotations North Carolina
- Code Work with Java Annotations North Dakota
- Code Work with Java Annotations Ohio
- Code Work with Java Annotations Oklahoma
- Code Work with Java Annotations Oregon
- Code Work with Java Annotations Pennsylvania
- Code Work with Java Annotations Rhode Island
- Code Work with Java Annotations South Carolina
- Code Work with Java Annotations South Dakota
- Code Work with Java Annotations Tennessee
- Code Work with Java Annotations Texas
- Code Work with Java Annotations Utah
- Code Work with Java Annotations Vermont
- Code Work with Java Annotations Virginia
- Code Work with Java Annotations Washington
- Code Work with Java Annotations West Virginia
- Code Work with Java Annotations Wisconsin
- Code Work with Java Annotations Wyoming

Rss   Delicious   Digg   Add To My Yahoo   Add To My Google   Bookmark   Search Plugin

Topics:
Architecture & Design Languages & Tools Project Management Web Services
Database Microsoft & .NET Security Wireless
Java Open Source Techniques XML