Java 注释 comments
1、注释是什么?为什么需要注释?
/**
* @desc
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
public class Comments {
public static void main(String[] args) {
System.out.println("Hello World!!!"); //Display the String.
}
/* this
is
a
multiple rows
comments
*/
}
注释被编译器忽略,但对其他程序员很有用。
Java编程语言支持三种注释:
/* text /
编译器会忽略从/到/的所有内容。
/* documentation */
这表示一个文档注释(简称文档注释)。编译器会忽略这种注释,就像它会忽略使用/和/的注释一样。javadoc工具在准备自动生成的文档时使用文档注释。
// text
编译器会忽略从//到行尾的所有内容。
2、举例说明
单行注释:
//Display the String.属于单行注释
多长注释:
/* this
is
a
multiple rows
comments
*/ 属于多行注释
JavaDoc:
/**
* @desc
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/属于java文档注释
3、注释的产生
注释为对代码的解释和说明,其目的是让人们能够更加轻松地了解代码。
注释为编写程序时,写程序的人给一个语句、程序段、函数等的解释或提示,能提高程序代码的可读性。
注释只是为了提高可读性,不会被计算机编译。