简单的数据类型
| 数据类型 | 数据细分类型 | 占用空间 |
| 简单数据类型 | 布尔型 boolean | 1位 |
| 字符型 char | 2字节 | |
| 字节型 byte | 1字节 | |
|
短整型 short |
2字节 | |
| 整型 int | 4字节 | |
| 长整型 long | 8字节 | |
| 单精度型 float | 4字节 | |
| 双精度型 double | 8字节 | |
| 复合数据类型 | 类 class | |
| 接口 Internet | ||
| 数组 |
简单的数据类型之间的转换
byte ->short -> char -> int ->long -> float -> double
低 高
例子:
float floatTemp;
int intTemp=(int)floatTemp;
简单类型的包装
在Java中,可直接把简单数据类型的变量表示为一个类,以方便将简单的数据作为一个对象处理。(Boolean、Character、Internet、Long、Float、Double)
其构造函数如下:
Boolean(boolean)
Character(char)
Internet(int)
Long(long)
Float(float)
Double(double)
但是因为它们是类,所以在声明的时候要使用new关键字来给其分配空间
如:
boolean bTest=true;
Boolean objTest=new Boolean(bTest);

浙公网安备 33010602011771号