弱类型语言 java的数据类型分为两大类要求变量的使用要严格符合规定,所有的变量必须先定义,再使用
基本数据类型:有8种,分别是,byte,short,int,long,float,double,char,boolean
整数类型:
-
byte
-
short
-
int
-
long
byte num1 = 10; short num2 =20; int num3 = 30; long num4 = 40L;//Long类型的,数字后面加一个L
浮点类型:
-
float
-
double
float num5 = 3.1F;//float类型,后面加一个F double num6 = 3.1415926;
字符类型:char
char a = "A"; char name = "中国";//这个就会报错,char是字符类型,它只支持一个字符 String name = "中国"//String是一个类,它可以定义字符串
boolean类型: 只有true和false
-
引用数据类型:类,接口,数组
其中:Integer,Short等,是基本数据类型的包装类
什么是字节bite(位),是计算机中最小的单位
byte(字节),是计算机中最基本的数据单位
1B=8b
1个字节=8个位
数据类型拓展面试题 整数拓展进制:十进制,二进制(0b),八进制(0),十六进制(0x)
int i = 10; int i2 = 010;//八进制0 int i3 = 0x10;//十六进制0x 0~9 A~F浮点数拓展
银行业务怎么表示?
不能用float或者double,需要用一个类:BigDecimal 数学工具类
float和double是有限的,离散的,舍入误差,接近但是不等于、
float f = 0.1f//0.1 double d = 1.0/10 //0.1 System.out.println(f==d)//false float f1 = 2323232455f; float f2 = f1+1; System.out.println(f1==f2);//true
最好完全使用浮点数进行比较
字符拓展所有的字符本质还是数字
char c1 = 'A'; char c2 = '中'; System.out.println(c1); System.out.println((int)c1);//强制类型转换转义字符
t 制表符
n 换行
..........
String sa = new String("hellotworld");
//hello world
String sb = new String("hellonworld");
//hello
//world
String sc = "hello world";
String sd = "hello world";
System.out.println(sa==sb);//false
System.out.println(sc==sd);//true
数据类型 强类型语言
弱类型语言 java的数据类型分为两大类要求变量的使用要严格符合规定,所有的变量必须先定义,再使用
基本数据类型:有8种,分别是,byte,short,int,long,float,double,char,boolean
整数类型:
-
byte
-
short
-
int
-
long
byte num1 = 10; short num2 =20; int num3 = 30; long num4 = 40L;//Long类型的,数字后面加一个L
浮点类型:
-
float
-
double
float num5 = 3.1F;//float类型,后面加一个F double num6 = 3.1415926;
字符类型:char
char a = "A"; char name = "中国";//这个就会报错,char是字符类型,它只支持一个字符 String name = "中国"//String是一个类,它可以定义字符串
boolean类型: 只有true和false
-
引用数据类型:类,接口,数组
其中:Integer,Short等,是基本数据类型的包装类
什么是字节bite(位),是计算机中最小的单位
byte(字节),是计算机中最基本的数据单位
1B=8b
1个字节=8个位
数据类型拓展面试题 整数拓展进制:十进制,二进制(0b),八进制(0),十六进制(0x)
int i = 10; int i2 = 010;//八进制0 int i3 = 0x10;//十六进制0x 0~9 A~F浮点数拓展
银行业务怎么表示?
不能用float或者double,需要用一个类:BigDecimal 数学工具类
float和double是有限的,离散的,舍入误差,接近但是不等于、
float f = 0.1f//0.1 double d = 1.0/10 //0.1 System.out.println(f==d)//false float f1 = 2323232455f; float f2 = f1+1; System.out.println(f1==f2);//true
最好完全使用浮点数进行比较
字符拓展所有的字符本质还是数字
char c1 = 'A'; char c2 = '中'; System.out.println(c1); System.out.println((int)c1);//强制类型转换转义字符
t 制表符
n 换行
..........
String sa = new String("hellotworld");
//hello world
String sb = new String("hellonworld");
//hello
//world
String sc = "hello world";
String sd = "hello world";
System.out.println(sa==sb);//false
System.out.println(sc==sd);//true
布尔值扩展
boolean flag = true;
if(flag){}
强制类型转换
由于java是强类型语言,因此有些运算的时候,需要类型转换
低——————————————>高
byte,short,char,int,long,float,double (boolean不参与)
int i1 = 10; double b1 = i1; char c1 = (int)i1; //强制转换:(类型)变量名 高——>低 //自动转换:低——>高 System.out.println((int)23.55);//23



