Java annotation

From Wikipedia, the free encyclopedia

In computer programming, a Java annotation is a way of adding metadata to Java source code that can also be available to the programmer at run-time. Many times it is used as an alternative to XML technology.

Java annotations can be added to program elements such as classes, methods, fields, parameters, local variables, and packages. Unlike tags added to Java documentation and processed with tools such as XDoclet, Java annotations are completely accessible to the programmer while the software is running using reflection.

Contents

Java annotations were introduced to the Java Community Process as JSR-175 in 2002 and approved in September 2004. Annotations became available with the JDK version 1.5. The feature was added to the Java language through the specification.

When Java source code is compiled, the Java compiler stores annotation metadata in the class files. Later, the JVM or other programs can look for the metadata to determine how to interact with the program elements or change their behavior.

Declaring an annotation is a variation on tags that have been added to comment sections in the past.

Annotations take the form of an interface declaration with an @ preceding it and optionally marked with meta-annotations, as shown below:

 @Retention(RetentionPolicy.RUNTIME)
 @Target({ElementType.METHOD})

In the above example both Retention and Target are examples of annotations.

  • Declarative Programming. Annotations allow the programmer to declare in their source code how the software should behave. It is an example of how declarative programming constructs can be added to a procedural language.

  • Performance. Adding metadata to a run time causes additional memory overhead.
  • Standards lack. There are few standards that dictate what metadata tags should be used.

Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.