Single-line comments and multiline comments

Source: Internet
Author: User

In actual coding, we always need to add some comments to the program.

What is a comment? A comment is a piece of text that is not required and is not directly involved in code execution.

Annotations are used to describe the function of a piece of code, or to describe the purpose of a class, the function of each method, and the data type and meaning of the method's parameters and return values.


Why would you like to add a comment?

1, never be too trusting in your own comprehension. It is recommended to add comments in order to be able to understand your own previous code in a short time.

2, readability first, efficiency second. in team development, it is important for team members to communicate, and it is recommended to add comments for their own code to be understood by the whole team.

3, the code is the document. I usually write some code, in order to generate some specifications of the document, it is recommended to add comments.


In the actual work, often hear some colleagues say that someone else's code is not annotated how, actually write beautiful code does not need too many comments , on the contrary, I personally for full screen comments or some useless code is extremely anti-

, especially with tools such as GIT,SVN, I delete all the useless commented out code.

Here's a look at my personal understanding of the notes:

1, necessary comments or must have, such as javabean in the meaning of the field, there should be relevant comments. For example, some of the code in the temporary implementation of functions, but there are some bad to optimize the place, I usually write a

TODO, implement basic functions follow me back to perfection myself.

2, do not write some idiot's useless comments, do not keep any line of commented out code, now the code generally has a version of the tool to manage, so there is no need to worry about the code will be discarded.

3, strict adherence to the Java naming specification, do not worry about variable name too long, do not worry about the method name is too long, a reasonable English translation of the name than the useless Chinese comments are much stronger .


Program comments are an important part of the source code, for a specification of the program source code, the note should be accounted for about one-third of the source code.

Almost all programming languages provide the functionality of annotations, and the General programming language provides basic single-line comments and multiline comments, and Java is no exception. In addition, the Java language provides a document comment.

This blog first organizes single-line comments and multiline comments in Java, and document annotations are typically used to generate APIs.

Later I will be a set of my own framework to organize a related API, so about the Java documentation comments, Next I will be dedicated to write a blog.


Single-line comments and multiline comments

A single-line comment is one line of code in the program, and in the Java language, a double slash "//" is placed before the content that needs to be commented on.

In Eclipse, the shortcut key for a single-line comment is command+/, which is to add a comment once, and to cancel the comment once it is pressed.

Multi-line annotations are a one-time comment out of multiple lines of code in the program, in the Java language, use "/*" and "/*" to include the contents of the program that require comments, "/*" to start the comment, "*/" to indicate the end of the comment.

In Eclipse, the shortcut keys for multiline annotations are command+control+/, and when you use them, I rarely use multiline comments.


Now post a piece of code to illustrate the single-line comments and multiline comments in Java.

/** * Single-line comments and multiline comments for Java. *  * @author Linkinpark */public class comment{public static void Main (string[] args) {// Here is a single-line comment for Java System.out.println ("demo Java single-line comment ... */* * Here is a multi-line comment */system.out.println java ("Demo Java multi-line comment ... ");}}





Single-line comments and multiline 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.