java基础-数据类型

时间:2019-02-11
本文章向大家介绍java基础-数据类型,主要包括java基础-数据类型使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1.基本数据类型

数据类型有哪些

整形 大小(byte) 浮点型 大小(byte) 布尔类型 大小(byte) 字符 大小(byte)
byte 1 float 4 boolean 1 char 2
short 2 double 8        
int 4            
long 8            

 

 

 

 

 

 

PS.     1:“字节”是byte,“位”是bit ;     2: 1 byte = 8 bit ;    英文占 1 byte, 中文 在-gb2312-下占 2 byte

2.引用类型

类似String ,自定义类型,数组,集合等

这里还涉及到基本数据类型的包装类,装箱/拆箱的细节分析

Q1 :    integer a=100 ; integer b=100;    a==b    返回 true

           integer c=129 ; integer d=129;    c==d    返回 false

A1 :  1. == 比较的是内存地址和值是否全相等       2. integer.class 中重写过valueOf方法,方法的内容是:

    public static Integer valueOf(int i) {
        if (i >= IntegerCache.low && i <= IntegerCache.high)
            return IntegerCache.cache[i + (-IntegerCache.low)];
        return new Integer(i);
    }

 3. integerCache.low 是 (int)-127  , high 是(int)128     4. 当值为100时比较的时integer中的缓存值,取的是同一个,超出返回就会重新new