java注释是不被编译器和解释器执行的语句。用于有关变量,方法,类或其他任何语句的解释。也可以隐藏程序代码。
java有三种注释:
1. 单行注释 //This is single line comment
2. 多行注释 /* This is multi line comment */
3. 文档注释 /** 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;} }
对于文档注释,通过一下步骤可以生产html文档,功能相当强大
javac Calculator.java
javadoc Calculator.java