您的位置:首页 > 编程语言 > Java开发

java基础数据类型的内存占用

2015-01-15 20:37 351 查看
工作中慢慢接触架构方面的设计,内存使用、带宽预估等工作离不开基础类型与内存的换算,整理一份简单的代码,备忘遗失的基础。

public class ElementaryDateType {

private static final String TYPE = "type";
private static final String BIT_UNIT = "(bit)";
private static final String BYTE_UNIT = "(Byte)";

public static void main(String[] args) {
// 8 bit = 1 Byte
System.out.println(TYPE + "\t" + BIT_UNIT + "\t" + BYTE_UNIT);
System.out.print("Byte\t");
System.out.println(Byte.SIZE + "\t" + Byte.SIZE / 8);

System.out.print("Short\t");
System.out.println(Short.SIZE + "\t" + Short.SIZE / 8);

System.out.print("Integer\t");
System.out.println(Integer.SIZE + "\t" + Integer.SIZE / 8);

System.out.print("Long\t");
System.out.println(Long.SIZE + "\t" + Long.SIZE / 8);

System.out.print("Float\t");
System.out.println(Float.SIZE + "\t" + Float.SIZE / 8);

System.out.print("Double\t");
System.out.println(Double.SIZE + "\t" + Double.SIZE / 8);

System.out.print("Character\t");
System.out.println(Character.SIZE + "\t" + Character.SIZE / 8);
System.out.println("Boolean is 1 bit");
}
}

type     (bit)   (Byte)
Byte        8   1
Short       16  2
Integer     32  4
Long        64  8
Float       32  4
Double      64  8
Character   16  2
Boolean is 1 bit
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: