Java的数据类型


Java中有8种基本数据类型:

  • 6 种数字类型 (四个整数形,两个浮点型):

    • byte(8bit):2^-7  ——  (2^7)- 1

    • short(16bit):2^-15  ——  (2^15) - 1

    • int(32bit):2^-31  ——  (2^31) - 1

    • long(64bit):2^-63  ——  (2^63) - 1

    • float(32bit):单精度浮点数

    • double(64bit):双精度浮点数

  • 1 种字符类型:char

  • 1 种布尔型:boolean只有两个值true和false

这些基本类型还有其对应的包装类型分别为:Byte、Short、Integer、Long、Float、Double、Character、Boolean。

而出现包装类型的原因是:以面向对象的角度去看待基本数据类型