码迷,mamicode.com
首页 > 编程语言 > 详细

java 各基本数据类型 所占有的字节数

时间:2014-12-17 22:45:41      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:java

Int: 4 字节
Short: 2字节
Long: 8字节
Byte: 1字节
Character: 2字节
Float: 4字节
Double: 8字节

Boolean:系统没有提供Size方法;

public class Calcsizof {

	/**
	 * @param args
	 */
	private static void calSize() {  
		System.out.println("Integer: " + Integer.SIZE/8);           // 4  
		System.out.println("Short: " + Short.SIZE/8);               // 2      
		System.out.println("Long: " + Long.SIZE/8);                 // 8  
		System.out.println("Byte: " + Byte.SIZE/8);                 // 1  
		System.out.println("Character: " + Character.SIZE/8);       // 2  
		System.out.println("Float: " + Float.SIZE/8);               // 4  
		System.out.println("Double: " + Double.SIZE/8);             // 8  
		System.out.println("Boolean: " + Boolean.toString(false));  

	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Calcsizof calcsizof= new Calcsizof();
		Calcsizof.calSize();
	}
}

运行结果:console 输出

Integer: 4
Short: 2
Long: 8
Byte: 1
Character: 2
Float: 4
Double: 8
Boolean: false

更多地封装后的Object的占用空间的分析 请参考

http://blog.csdn.net/ithomer/article/details/7310008

 

java 各基本数据类型 所占有的字节数

标签:java

原文地址:http://blog.csdn.net/youcharming/article/details/41987371

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!