Java初学

Java初学

  • 类的命名为驼峰命名

  • 源代码的文件名必须与公共类的名字相同,并用.java 作为扩展名

  • 为了代码能够执行, 在类的源文件中必须包含一个main方法,当然,也可以将用户自定义的方法添加到类中,并且在main方法中调用它们

  • main 方法必须声明为public

  • Java 中任何方法的代码都用"{"开始,用"}"结束。

  • 在Java 中, 每个句子必须用分号结束。

  • 注释方法

    1. 使用//注释每一行

      System.out.println("We will not use 'Hello World'"); // is this too cute?
      
    2. 长篇注释,使用/* */

      /*
      1
      2
      System.out.println("We will not use 'Hello World'");
      */
      System.out.println("We will not use 'Hello World'");
      
    3. 用于自动生成文档,格式为/** */

      /**
      * This is the first sample program is Java
      * author zlbingo
      */
      public class FirstSample
      {
          public static void  main(String[] args)
          {
              System.out.println("We will noe use 'hello world'");
          }
      }
      
posted @ 2022-02-09 20:47  zlbingo  阅读(28)  评论(0)    收藏  举报