Java基础语法1-注释、标识符、关键字

1.注释、标识符、关键字

代码注释

单行注释

public class Hello {
    public static void main(String[] args) {
        // 我是单行注释
        System.out.println("hello world~~");
    }
}

多行注释

public class Hello {
    public static void main(String[] args) {
        /*
        我是多行注释1
        我是多行注释2
        我是多行注释3
         */
        System.out.println("今天的天气怎么样?");

    }
}

文档注释

public class Hello {
    public static void main(String[] args) {
        System.out.println("今天的天气怎么样?");
        /**
         * @Description HelloWorld文档注释(JavaDoc配合来用的)
         * @Autor miyazhu
         */
    }
}

百度:有趣的代码注释


标识符

Java所有的组成部分都需要名字。类名、变量名以及方法名都被称为标识符

  • 所有标识符都以字母A-Z或a-z,美元符号($)或者下划线(_)开始
  • 首字母后可以是字母A-Z或a-z,美元符号($)或者下划线(_)或数字的任意字符
  • 标识符是大小写敏感的
  • 标识符不能为关键字
  • 标识符可以为中文,但不建议
String $l = "ccc";
String _123 = "hello";
String p1 = "hello1";
String Aplan = "world";
String man = "man1";
String Man = "man2";
String mingzi = "miyazhu"; // 不建议
String 名字 = "miyazhu"; // 不建议

关键字

- - - - -
if class for void static
public boolean long try this
goto catch package new return
extends synchronized interface final finally
double protected switch throw throws
abstract assert break byte case
char const continue default do
else enum float implements import
instanceof int native private strictfp
short super transient volatile while
posted @ 2022-05-06 09:42  浅浅水声  阅读(26)  评论(0编辑  收藏  举报