官术网_书友最值得收藏!

2.7 Comments

Comments are very important (and often neglected). The primary purpose of a comment is to provide additional information to a person that is reading a program. As far as the computer is concerned, a comment is just like more white space. The comment does not result in a token, it only separates other tokens or gets ignored completely when it is not needed to separate tokens. Java has 3 ways to specify comments.

2.7.1 Single Line

Typing // causes the rest of the line (all characters up to the next newline) to be treated as a comment and ignored by the compiler. This is called a single line comment because the comment cannot be longer than a single line. By definition, the comment ends at the end of the line containing the //.

單行的注釋用//。

2.7.2 Multi-line

As the names suggests, this style of comment can extend across several lines in a program. The comment beginning is marked with /* and the comment ending is marked with */. Everything between the marks and the marks themselves is a comment and is ignored. Here is the multi-line comment from our first Java program.

多行的注釋用/* */。

/* HelloWorld.java
 * Purpose:
 *This program is the classic "Hello World" program for Java. It simply prints a message to the screen.
 */

The single asterisks on the 2nd through 6th lines are not required and are just used to accent the extent of the comment. These comments are also called block comments.

2.7.3 Javadoc

The third style of comment is a minor variation on the previous multi-line comment. The comment beginning marker has an additional asterisk. These comments are identical to the multi-line comment except that they are recognized by a special program called “javadoc” that will automatically extract such comments and produce documentation for the program organized as an HTML document. HTML stands for Hyper Text Markup Language and it is the formatting language used for World Wide Web documents.

javadoc注釋是一種多行注釋,以/**開頭,以*/結束,注釋可以包含一些HTML標志符和專門的關鍵詞。

/** starts with slash DOUBLE asterisk and
   continues
   until asterisk slash
*/
主站蜘蛛池模板: 鲜城| 盘山县| 延川县| 望都县| 建湖县| 诸暨市| 滨海县| 沽源县| 剑河县| 株洲县| 龙海市| 泰州市| 沧源| 甘谷县| 富顺县| 建瓯市| 高尔夫| 来凤县| 依安县| 灌阳县| 迁安市| 夏河县| 尖扎县| 金坛市| 齐河县| 且末县| 万载县| 旺苍县| 淳化县| 额济纳旗| 高唐县| 荆州市| 彭泽县| 庆城县| 惠来县| 尤溪县| 河间市| 伊通| 楚雄市| 天峨县| 汉寿县|