本文概要
java的意见是不是由编译器和解释器执行的语句。这些评论可以用来提供有关变量,方法,类或声明的任何资料或解释。它也可以用来为特定的时间隐藏的程序代码。
Java的注释类型
有3种类型的Java中的意见。
- 单行注释
- 多行评论
- 文档注释
1)Java单行注释
在单行注释用于注释只有一行。
句法:
//This is single line comment
例:
public class CommentExample1 {
public static void main(String[] args) {
int i=10;//Here,i is a variable
System.out.println(i);
}
}
输出:
10
2)JAVA多行注释
多行注释用于注释的多行代码。
句法:
/*
This
is
multi line
comment
*/
例:
public class CommentExample2 {
public static void main(String[] args) {
/* Let's declare and
print variable in java. */
int i=10;
System.out.println(i);
}
}
输出:
10
3)Java文档注释
文档注释用于创建文档的API。要创建文件API,你需要用javadoc工具。
句法:
/**
This
is
documentation
comment
*/
例:
/** The Calculator class provides methods to get addition and subtraction of given 2 numbers.*/
public class Calculator {
/** The add() method returns addition of given numbers.*/
public static int add(int a,int b){return a+b;}
/** The sub() method returns subtraction of given numbers.*/
public static int sub(int a,int b){return a-b;}
}
通过javac的工具编译:
javac Calculator.java
通过创建javadoc工具文档API:
javadoc Calculator.java
现在,会在当前目录为你的计算器类创建的HTML文件。打开HTML文件,并识破文档注释提供的计算器类的解释。
评论前必须登录!
注册