⼋个基本数据类型及长度
8种基本数据类型为:
4种整形:byte,short),int,long
2种浮点类型:float,double
1种Unicode编码的字符单元的字符型:char
1中Boolean类型:boolean
unicode文件格式8中类型所占字节和位数和取值范围如下:
类型占⽤字节占⽤位数数值长度
byte18-128~127(-2的7次⽅到2的7次⽅-1)
short216-32768~32767(-2的15次⽅到2的15次⽅-1)
int432-2147483648~2147483647(-2的31次⽅到2的31次⽅-1)
long864(-9223372036854774808~9223372036854774807)(-2的63次⽅到2的63次⽅-1)
float432( 1.401298e-45~3.402823e+38)(e-45是乘以10的负45次⽅ ,e+38是乘以10的38次⽅)(2的-149次⽅ ~ 2的128次⽅-1)
double864(4.9000000e-324 ~ 1.797693e+308 )(2的-1074次⽅ , 2的1024次⽅-)
char216
boolean1
boolean 所占字节问题
The boolean type is compiled into the int type for use, occupying 4 bytes.
The boolean array is compiled into a byte array type, and each boolean array member occupies 1 byte.
In the Java virtual machine, 1 means true and 0 means false.
This is just a recommendation of the Java Virtual Machine.
To be sure, it will not be 1 bit.
1 byte = 1字节 = 8bit
⼆、⼩插曲 -----int和Integer的区别
1.从定义上来看
int 是基本类型,直接存数值(类似的还有float、double、String、char)
Integer是对象,⽤⼀个引⽤指向这个对象(类似的有Float、Double、String)
2.初始化的⽅式不同
int i =1;
Integer i= new Integer(1);//integer 是⼀个类
int 是基本数据类型(⾯向过程留下的痕迹,不过是对java的有益补充);Integer 是⼀个类,是int的扩展,定义了很多的转换⽅法
注意:类似的还有:float Float;double Double;String等,其中String较为特殊,基本类型和复杂类似关键字相同。
例如,当需要往ArrayList,HashMap中放东西时,像int,double这种内建类型是放不进去的,因为容器都是装 object的,这是就需要这些内建类型的外覆类了。Java中每种内建类型都有相应的外覆类。
Java中int和Integer关系是⽐较微妙的。关系如下:
int是基本的数据类型;
Integer是int的封装类;
int和Integer都可以表⽰某⼀个数值;
int和Integer不能够互⽤,因为他们两种不同的数据类型;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。