一.包的概念:
package
解决开发过程中,文件名重名
命名规则:大-->小
com.ffyc.type
二.变量与常量
1.变量
变量是什么?
变量的本质是地址,人类使用简易的标记:英文字母,拼音等命名。
变量命名:见名知意,驼峰法命名
2.常量
(1)普通常量
int a = 3;
(2)符号常量
不可变
final int LOGIN_MAX_TIMES = 3;
常量有类型
三.基本数据类型
类型的本质是空间大小
1.byte类型
· 计算机最小类型:0.1---比特 位
· 每8个0.1---字节
2.short
· 2 bytes
3.int(默认)
· 4*8=32 bit
4.long(3333L)
· 8*8=64 bits-->8 bytes
//byte最大值,最小值
System.out.print("byte的最大值:"+Byte.MIN_VALUE);
System.out.println("byte的最小值:"+Byte.MAX_VALUE);
//short最大值,最小值
System.out.print("short的最大值:"+Short.MIN_VALUE);
System.out.println("short的最小值:"+Short.MAX_VALUE);
//int最大值,最小值
System.out.print("int的最大值:"+Integer.MIN_VALUE);
System.out.println("int的最小值:"+Integer.MAX_VALUE);
//long最大值,最小值
System.out.print("long的最大值:"+Long.MIN_VALUE);
System.out.println("long的最小值:"+Long.MAX_VALUE);
5.char
char c1 = 'a';
char c2 = 97;
char c3 = '\u0061';//unicode写法,16进制
(1)ASCII码
中文:19968 ~ 40869
for(int a = 19968; a<=40869;a++){
System.out.println((char) a);
}
char c='惇';
System.out.println("c="+(int)c);
6.浮点型-单精度float(3.222f)
4 bytes
7.浮点型-双精度double(默认)
BigDecimal a = new BigDecimal("2.2222222222222222222222");
BigDecimal b = new BigDecimal("3.3333333333333333333333");
BigDecimal c = a.add(b);
System.out.println(c);
8 bytes
double a = 3.0000000000001;
double x = 0.0000000000001;
for(int i=0;i<10;i++){
a = a+x;
System.out.println(a);
}
8.boolean布尔型
true/false
boolean f = false;
char ch = '中';
f=ch >= '0' && ch <= '9';
System.out.println("f:"+f);
问题
short a = 3;
short b = 4;
short c1 = 3 + 4;//没问题
short c2 = a + 4;
short c3 = 3 + b;
short c4 = a + b;
原因:编译器对整数默认int
a,b -short -----> +以后有可能超出界限 ---- 提升类型int
四.运算符
1.算术运算符
+
·'a'+'b'--->拼接
·1+2数学
-
·数学
*
·数学
/
·数学除+计算机
会出现小数
%
模运算
long x = 2343234234;
boolean can =(x % 3==0);
System.out.println(can);
2.复合运算
转型和运算合为一体
+=
byte a = 3;
a+=1;//a = a + 1;
-=
*=
/=
%=