Java语言中的注释是什么?

通常,任何编程语言中的注释都有助于使源代码易于阅读,而编译器则忽略了这些注释。

Java支持三种类型的注释–

  • 单行注释-使用这些注释可以注释单行。编译器将忽略// //到行尾的所有内容。

  • 多行注释-使用这些注释可以注释多行。编译器会忽略从/ *到* /的所有内容。

  • 文档注释-这是文档注释,通常称为doc注释。在准备自动生成的文档时,JDK Javadoc工具使用文档注释。

示例

以下示例演示了Java中所有三种类型的注释的用法。

/**
   * @author Nhooo
*/ 
public class CommentsExample {
   /*
      Following is the main method here,
      We create a variable named num.
      And, print its value    
   * */
   public static void main(String args[]) {
      //声明一个名为num的变量
      int num = 1;
      //打印变量num的值
      System.out.println("value if the variable num: "+num);
   }
}

输出结果

value if the variable num: 1