Java基础 (关键字-字符)

发布时间 2023-12-30 17:44:13作者: 网抑杰

标识符

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

  • 关键字

abstractassertbooleanbreakbyte
case catch char class const
continue default do double else
enum extends final finally float
for goto if implements import
instanceof int interface long native
new package private protected public
return strictfp short static super
switch synchronized this throw throws
transient try void volatile while

 

标识符注意点

  • 所有的标识符都应该以字母(A-Z 或者 a-z),美元符($),或者下划线(_)开始。

  • 首字符之后可以是字母(A-Z 或者 a-z),美元符($),下划线(_)或者数字的任何字符组合。

  • 不能使用关键字作为变量名或方法名!

  • 标识符是大小写敏感的!

  • 可以使用中文命名,但一般不建议这样使用,也不建议使用拼音!

 

public class Demo02 {
  public static void main(String[] args) {

      String Ahello = "boy";
      String hhello = "boy";
      String $hello = "boy";
      String _hello = "boy";

      //String 1hello = "boy";
      //String #hello = "boy";
      //String *hello = "boy";

      //--------------------------------------

      String _Aa$666 = "boy";

      //--------------------------------------

      //String class = "boy";

      //--------------------------------------

      //标识符是大小写敏感!
      String Man = "boy";
      String man = "boy";

      //--------------------------------------

      String 王者荣耀 = "最强王者";

      //String 王者荣耀 = "倔强青铜";

      System.out.println(王者荣耀);
  }
}