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