Java code Comments

Source: Internet
Author: User

Code annotations can improve the readability of your program. The notes contain information about the program, which helps to better read and understand the program from the programmer. Comment statements can be added anywhere in the Java source file. Note the text of the Java compiler does not compile, and the comment text in all the code has no effect on the program. Java provides three types of annotation methods, namely single-line comment, multiline comment, and document comment.

1 Single-line comment

"//" is a single-line comment symbol, which is ignored by the Java compiler from the beginning of the symbol "//" to the newline position . The syntax is as follows:

//comment content

For example, the following code adds a comment for declaring an int type variable.

 int age; Define an int variable to hold age information

 2 Multi-line comments

 "/**/" is a multiline comment marker, and everything between the symbol "/*" and "* *" is commented. The contents of the note can be "wrapped."

The syntax is as follows:

 /*

Note Content 1

Note Content 2

*/

 Attention

Multiple lines of comments can be nested in a single line, for example:

 /*

Program Name: Hello Word//Development time is 2017 years

*/

However, you cannot nest multiple lines of comments in a multiline comment, for example:

  /*

Program Name: Hello Word

/*

Development Date: 2017

CHEN

*/

*/

This program is incorrect.

  3 Documentation Comments

"/***/" is the symbol for the document comment, and the amount between the symbol "/**" and the symbol "* *" is the content of the comment. A document comment is read as a Javadoc document content when it appears before a declaration variable (such as a class's sound, a declaration of a class member variable, a declaration of a class member method, and so on). The format of a document comment is the same as for a multiline comment, and for beginners, the document comment is not very important to understand.

  

Description

Must form a good programming style, the Software programming specification refers to "readability first, efficiency second", so programmers must add the appropriate amount of comments in the programming to improve the readability and maintainability of the code. Note in the program to account for the total number of program code 20%~50%.

Java code Comments

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.