1)关键字
在java代码中具有特殊含义的单词
数据类型:class、interface、enum、byte、short、int、long、float、double、char、boolean、void
流程控制:if、else、switch、case、default、while、do、for、break、continue、return
访问权限修饰符:private、protected、public
类型修饰符:abstract、final、static、synchronized
类关系:extends、implements
实例相关:new、this、super、instanceof
异常处理:try、catch、finally、throw
包相关:package、import
其他修饰:native、strictfp、transient、volatile
字面量:true、false、null
保留字(未使用):goto、const
2)标识符
变量、方法、类的名字
// 类名 Identifier
public class Identifier {
// 方法名 main 参数 变量名 args
public static void main(String[] args) {
// 局部 变量名 a
int a = 1;
// 命名规则
// 由26英文字母大小写,0-9,_或$组成
// 不能以数字开头、不能是关键字保留字
// 区分大小写,长度无限制
// 命名规范 不遵守不错误但不优雅
// 包名:所有字母小写
// 类名、接口名:形如XxxYyyZzz
// 变量名、方法名:形如xxxYyyZzz
// 常量名:形如XXX_YYY_ZZZ
// 见名知意
}
}
3)变量、数据类型、进制
用标识符表示在某个区间范围取值的量
变量的属性:数据类型,值,作用域
public class Variable {
public static void main(String[] args) {
// 变量定义
// 数据类型 变量名 [= 值];
// 变量被定义才能使用
// 作用域 成员变量 局部变量
// 数据类型
// 基本类型
// 整数 byte short int long
// 浮点数 float double
// 字符 char
// 布尔型 boolean
// 引用类型
// 类 class
// 接口 interface
// 数组 []
// 整型
// byte 1字节=8bit 范围-128~127
// short 2字节 范围-2^15~2^15-1
// int 4字节 范围-2^31~2^31-1(21亿)
// long 8字节 范围-2^63~2^63-1
byte b = 127;
// 编译不通过
// byte b1 = 128;
long l = 10000000000L;
// int i = 2147483647;
// 编译不通过 需要末尾加L声明为long类型 默认int类型
// long l = 10000000000;
// 浮点型
// float 4字节 范围-3.403E38~3.403E38
// double 8字节 范围-1.798E308~1.798E308
// 存在精度问题
// 字面量 默认double类型
float f = 0.99999999F;
// 输出为 1.0
System.out.println(f);
// 字符型
// char 2字节 一个字符
char c = 'a';
char c1 = '中';
// 转义字符
char c2 = 'n'; // 换行
char c3 = '\'; //
// unicode字符编码表示 万国编码
char c4 = 'u0043';
// ascii码 美国编码
char c5 = 97; // 'a'
// 布尔类型 用于判断
boolean bl = true;
boolean bl1 = false;
// 类型转换
// 自动类型转换
byte b2 = 1;
short s = 1;
//编译不通过 运算结果自动转int
// short s1 = b2 + s;
// 运算自动转换 类型提升
// byte、short、char --> int --> long --> float --> double
// 强制类型转换 数据损失
byte b3 = (byte) 128;
int i = (int) 1.1;
// 字符串 引用类型
// 赋初始值才能使用
// 可和基本类型做连接运算 运算过程从左到右
String str = "hello String";
String str1 = new String("hello String");
System.out.println(str==str1); //false
// 进制
int int2 = 0B111;
int int8 = 017;
int int16 = 0xABC;
}
}



