标识符的使用规范
- 所有标识符都应该以字母(A-Z,a-z),美元符(💲),下划线( _ )开头
- 首字母之后可以是任意字符,个别特殊符号除外(#¥)
- 不能用关键字作为变量名和方法名
- 标识符是大小写敏感的
- 尽量不要使用拼音和汉字命名很low
数据类型
Java的基本数据类型分两大类
- 基本数据类型
- 整型
- type 1字节 -2^7----- 2^7-1
- shot 2字节 -2^15----- 2^15-1
- int 4字节 -2^31----- 2^31-1
- long 8字节 -2^63----- 2^63-1
- 浮点型
- float 4个字节
- double 8个字节
- 字符型
- char 2个字节
- boolean类型
- boolean 1个字节(值只有true和false)
- 整型
- 引用数据类型
- 类
- 接口
- 数组
什么是字节
-
位(bit):计算机内部存储的最小单位,11001100是一个八位二进制
-
字节(byte):计算机中数据处理的基本单位 习惯用大写B表示
-
1B == 8bit
-
字符:是指计算机中使用的字母,数字,字和符号。
数据类型扩展
public class DataTypeExtend {
public static void main(String[] args) {
//整型扩展 二进制 0b 八进制 0 十进制 十六进制 0x
int a1 = 10;
int a2 = 0b10;
int a3 = 010;
int a4 = 0x10;
System.out.println(a1);
System.out.println(a2);
System.out.println(a3);
System.out.println(a4);
//=============================
System.out.println("=============================");
//浮点型扩展
float f1 = 0.1f;
float f2 = 0.1f;
double d1 = 0.1;
System.out.println(f1==f2);//ture
System.out.println(f1==d1);//false
//float是离散的 有限的 舍入误差 大约 接近但不等于
//最好不要使用float比较是否相等,一把使用BigDecimal数学工具类
float f3 = 234234123434f;
float f4 = f3 + 1;
System.out.println(f3 == f4);//true
System.out.println("=============================");
//字符扩展
char c1 = 'a';
char c2 = '中';
System.out.println(c1);//a
System.out.println((int)c1);//97
System.out.println(c2);//中
System.out.println((int)c2);//20013
/*所有的字符本质还是数字
* Unicode编码 2字符 2^16 0-25536 eg:a==97 A==65 */
//Unicode编码 U0000-UFFFF
char c3 = '\u0061';
System.out.println(c3);//a
System.out.println("=============================");
//转义字符又很多今天介绍两个 \t 制表符 \n 换行符
System.out.println("hello\tword");
System.out.println("hello\nwo≈d");
}
}