编写方法名时,我们应该遵循驼峰命名法,即第一个单词的首字母应小写,其余(后面)单词的首字母应大写。示例public class Test { public void sampleMethod() { System.out.println("This is sample method"); } public void demoMethod() { System.out.println("This is demo method"); } public static void main(String args[]) { Test obj = new Test(); obj.sample(); obj.demo(); } }输出This is sample method This is demo method
Java 中的有效标识符 – 必须以字母(A 到 Z 或 a 到 z)、货币字符 ($) 或下划线 (_) 开头。第一个字符之后可以是任何字符组合。不能是关键字。示例以下示例显示了在 Java 中声明变量时使用的各种可能的标识符。实时演示public class VariableTest { public static void main(String args[]) { // 声明一个名为 num 的变量 int num = 1; ... 阅读更多
多行注释 (/* */) 用于注释源代码中的多行。示例实时演示public class CommentsExample { /* 以下是此处的主方法,我们创建一个名为 num 的变量。并打印其值 * */ public static void main(String args[]) { //声明一个名为 num 的变量 int num = 1; ... 阅读更多
要注释特定行,只需在该行之前放置“双反斜杠 (//)”即可,如下所示。// Hello this line is commented示例以下示例演示了在 Java 中使用单行注释。实时演示public class CommentsExample { 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