java中 boolean类型占多少字节
2012-06-20 08:58
381 查看
java中 boolean类型占多少字节
今天面试问到了这个问题,java中boolean类型到底占多少字节呢,到网上搜了下,最后采用了这个答案:
答:我的结论是:
1)boolean a=true;//这个a在JVM中占4个字节即:32位。
2)boolean[] b = new boolean[10];//数组时,每一个boolean在JVM中占一个字节。
理由:
1)JAVA规范中没有定义boolean类型的大小。
2)但是:在JVM规范第2版中讲得十分清楚。我上边的结论就是从它当中取出来的。
根据:(JVM规范第2版 3.3.4节)
Instead, expressions in the Java programming language that operate on boolean values are compiled to use values of the Java virtual machine int data type.
Where Java programming language boolean values are mapped by compilers to values of Java virtual machine type int, the compilers must use the same encoding. 而:Java virtual machine type int, whose values are 32-bit signed two's-complement integers。
Arrays of type boolean are accessed and modified using the byte array instructions
In Sun's JDK releases 1.0 and 1.1, and the Java 2 SDK, Standard Edition, v1.2, boolean arrays in the Java programming language are encoded as Java virtual machine byte arrays, using 8 bits per boolean element.
今天面试问到了这个问题,java中boolean类型到底占多少字节呢,到网上搜了下,最后采用了这个答案:
答:我的结论是:
1)boolean a=true;//这个a在JVM中占4个字节即:32位。
2)boolean[] b = new boolean[10];//数组时,每一个boolean在JVM中占一个字节。
理由:
1)JAVA规范中没有定义boolean类型的大小。
2)但是:在JVM规范第2版中讲得十分清楚。我上边的结论就是从它当中取出来的。
根据:(JVM规范第2版 3.3.4节)
Instead, expressions in the Java programming language that operate on boolean values are compiled to use values of the Java virtual machine int data type.
Where Java programming language boolean values are mapped by compilers to values of Java virtual machine type int, the compilers must use the same encoding. 而:Java virtual machine type int, whose values are 32-bit signed two's-complement integers。
Arrays of type boolean are accessed and modified using the byte array instructions
In Sun's JDK releases 1.0 and 1.1, and the Java 2 SDK, Standard Edition, v1.2, boolean arrays in the Java programming language are encoded as Java virtual machine byte arrays, using 8 bits per boolean element.
相关文章推荐
- Java中boolean数据类型占用多少个字节
- Java中boolean类型占用多少个字节
- Java中boolean类型占用多少个字节
- 你真的知道Java中boolean类型占用多少个字节吗?
- 你真的知道Java中boolean类型占用多少个字节吗?
- Java中boolean类型占用多少个字节
- 你真的知道Java中boolean类型占用多少个字节吗?
- Java中boolean类型占用多少个字节
- Java中boolean类型到底占用多少个字节?
- java boolean类型占多少字节
- java如何判断一个String类型数据由多少字节组成?
- Java 8 种数据类型 字节大小,int 4个字节,boolean几个字节
- java中Boolean类型到底占几个字节?
- Java中boolean占多少字节 boolean a = 123是不是正确?
- JAVA 中的几种基本数据类型是什么,各自占用多少字节。
- Java的基本数据类型各占多少个字节
- java中的基本数据类型?各占多少位?多少字节?取值范围?
- Java中各基本类型占多少字节数
- java中的基本数据类型?各占多少位?多少字节?取值范围?
- java string类型转换boolean类型