`

boolean占用几个字节

    博客分类:
  • JVM
阅读更多
Although the Java virtual machine defines a boolean type, it only provides very limited support for it. There are no Java virtual machine instructions solely dedicated to operations on boolean values. 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.

The Java virtual machine does directly support boolean arrays. Its newarray instruction enables creation of boolean arrays. Arrays of type boolean are accessed and modified using the byte array instructions baload and bastore.2

The Java virtual machine encodes boolean array components using 1 to represent true and 0 to represent false. 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.

csdn上的有人这样说 

我的结论是:
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.


我比较赞同这一点 

我一开始也认为是用int类型表示的 boolean
但boolean 数组的问题  学习下、、、、、
分享到:
评论

相关推荐

    自考04747《Java语言程序设计(一)》简答题全集.doc

    〔2.5分〕 14、 简述编程语言的几个发展阶段 1 面向机器语言 〔1分〕 2 面向过程语言 〔1分〕 3 结构化程序设计阶段 〔1分〕 4 面向对象编程 〔1分〕 15、 什么是类及类的实现包括什么 类是组成java程序的基本要素 ...

    最新自考04747《Java语言程序设计(一)》简答题全集资料.doc

    (2.5分) 14、 简述编程语言的几个发展阶段 1 面向机器语言 (1分) 2 面向过程语言 (1分) 3 结构化程序设计阶段 (1分) 4 面向对象编程 (1分) 15、 什么是类及类的实现包括什么 类是组成java程序的基本要素 ...

    java 面试题 总结

    创建了几个String Object? 两个 28、设计4个线程,其中两个线程每次对j增加1,另外两个线程对j每次减少1。写出程序。 以下程序使用内部类实现线程,对j增减的时候没有考虑顺序问题。 public class ThreadTest1{ ...

    超级有影响力霸气的Java面试题大全文档

    创建了几个String Object? 两个 31、EJB包括(SessionBean,EntityBean)说出他们的生命周期,及如何管理事务的?  SessionBean: Stateless Session Bean 的生命周期是由容器决定的,当客户机发出请求要建立一个...

    powerbuilder

    功能定义打印作业使用的字体,对每个打印作业PowerBuilder支持八种字体。 语法PrintDefineFont(printjobnumber,fontnumber,facename,height,weight,fontpitch,fontfamily, italic,underline) 参数printjobnumber:用...

    SqliteDev 384

    SQLite 是一款轻型的数据库 是遵守ACID的关联式数据库管理系统 它的设计目标是嵌入式的 而且目前已经在很多嵌入式产品中使用了它 它占用资源非常的低 在嵌入式设备中 可能只需要几百K的内存就够了 它能够支持Windows...

    SQLite(SqliteDev)

    SQLite,是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了。...

    课程设计实验——八皇后_VC++游戏

    当某个皇后占了位置(i,j)时,在这个位置的垂直方向、水平方向和斜线方向都不能再放其它皇后了。用语句实现,可定义如下三个整型数组:a[8],b[15],c[24]。其中:  a[j-1]=1 第j列上无皇后  a[j-1]=0 第j列上有皇后...

    C++MFC教程

    我很难说得清楚,也很难下一个定义(谁在嘘我),我下面从不同的几个方面讲解一下,希望大家看了后有一点了解。 1、消息的组成:一个消息由一个消息名称(UINT),和两个参数(WPARAM,LPARAM)。当用户进行了输入...

    Java经典入门教程pdf完整版

    JWM将代码输入一个字节码校验器以 测试代码段格式并进行规则检査一一检査伪造指针、违反对象访问权限或试图改变对象类型 的非法代码。 注意-—所有源于网络的类文件都要经过字节码校验器 字节码校验器对程序代码进冇...

    oracle学习文档 笔记 全面 深刻 详细 通俗易懂 doc word格式 清晰 连接字符串

    日期类型 date 7字节 用于存储表中的日期和时间数据,取值范围是公元前4712年1月1日至公元9999年12月31日,7个字节分别表示世纪、年、月、日、时、分和秒 二进制数据类型 row 1~2000字节 可变长二进制数据,在具体...

Global site tag (gtag.js) - Google Analytics