03数据类型
强类型语言
要求变量的使用严格符合规格,所有变量都必须先定义后才能使用
弱类型语言
JAVA的数据类型分为两大类
基本类型
数值类型
整数类型
-
byte占1个字节范围:-128~127
-
short占2个字节范围:-32768~32767
-
int占4个字节范围 (最常用)
-
long占8个字节范围 (long类型要在数字后面加L)
浮点类型
-
float占4个字节(要在数字后面加F)
-
double占8个字节
boolean类型
占1位只有true和false
引用类型
-
类
-
接口
-
数组
数据类型拓展
整数拓展
`
二进制0b 十进制 八进制0 十六进制0x
int i = 10;
int i2 = 010;
int i3 = 0x10;
System.out.println(i);//10
System.out.println(i2);//8
System.out.println(i3);//16
`
浮点数拓展
银行业务怎么表示
BigDecimol 数学工具类
//float 是有限的 离散的 含入误差 大约 接近但不等于
//最好完全使用浮点数进行比较
//最好完全使用浮点数进行比较
//最好完全使用浮点数进行比较
float f = 0.1f;
double d = 1.0/10;
System.out.println(f == d);//false
float d1 = 231125128212521f;
float d2 = d1 + 1;
System.out.println(d1 == d2);//true
字符拓展
char c1 = 'a';
char c2 = '中';
System.out.println(c1);
System.out.println((int)c1);//强制转换 97
System.out.println(c2);
System.out.println((int)c2);//强制转换 20013
char c3 = '\u0061';
System.out.println(c3);//a
所有的字符本质是数字
编码 Unicode 表(97 = a,65 = A)
转义字符
\t 制表符 相等于TAB键
\n 换行
String sa = new String("hello world");
String sb = new String("hello world");
System.out.println(sa==sb);//false
String sc = "hello world";
String sd = "hello world";
System.out.println(sc==sd);//true
对象 从内存分析
布尔值拓展
boolean flag = true;
if(flag==true ){}//新手
if(flag){}//老手

浙公网安备 33010602011771号