Java Annotations (i)

Source: Internet
Author: User

Annotations are labels that are inserted into the source code so that they can be processed. These tools can be manipulated at the source level. Annotations do not change the way programs are compiled. The Java compiler generates the same virtual machine directives for code that contains annotations and code that does not contain annotations.
Annotations are introduced to Java as early as j2se1.5, providing a mechanism that allows programmers to write metadata directly while writing code. Before the introduction of annotations, programmers described the form of their code as not yet standardized, and everyone's approach was different: transient keywords, annotations, interfaces, and so on. This is obviously not an elegant way, followed by a new form of record metadata-annotations are introduced into Java. Let's take a look at the use of annotations:

Use of annotations:

The use of annotations is simple as long as you add @xxx to the class or Member or method, and xxx is the name of the annotation.
In the general Java development, the most frequent contact may be @override and @supresswarnings these two annotations. When using @override, you only need a simple declaration. This is called the markup annotation (marker annotation), which appears to represent a certain configuration semantics. Other annotations can have their own configuration parameters. Configuration parameters appear in the form of a name-value pair. The use of @SupressWarnings requires a syntax like @supresswarnings ({"Uncheck", "unused"}). Inside the parentheses is the value that the annotation is available for configuration. Since this annotation has only one configuration parameter, the name of the parameter defaults to value and can be omitted. The curly braces indicate the array type. The @table annotations in JPA use a syntax like @table (name = "Customer", schema = "APP"). You can see the usage of the name-value pairs from here. The value of the configuration parameter when using annotations must be a constant at compile time.
In some ways, annotations can be thought of as an XML element that can have different predefined attributes. The value of a property can be specified by itself when declaring the element. Using annotations in your code is equivalent to moving part of the metadata from an XML file into the code itself, and managing and maintaining it in one place.
Annotations in spring, hibernate and other frameworks used a lot of specific use of the situation I can not explain, the students interested in this will be able to learn their own. This blog's introduction to annotations is here for the time being, but I will write a blog to illustrate how to make custom annotations, which is the key to our learning.

Copyright NOTICE: This article is the original blog article, reproduced please indicate the source

Java Annotations (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.