File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes size of boolean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "size of boolean" Watch "size of boolean" New topic

size of boolean

Shivangi Joshi

Joined: Jun 01, 2007
Posts: 23
can anybody please tell me what is size of boolean.i have already searched on net,the results are so much confusing,some says 1 bit(as per JVM specification),some says 1 byte, and not applicable,and many please let me know what is correct size of boolean.

thanks in advance

Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
Here is a topic covering that question.

I found this on the sun forums.

"There is actually no boolean type. A Java expression that operates on boolean values is compiled to use the int data type to represent boolean variables. This means a boolean is usually a 32-bit variable. However arrays of booleans are treated as arrays of bytes, so booleans are 8 bits in an array"
[ July 26, 2008: Message edited by: Nathan Leniz ]

The very existence of flamethrowers proves that at some time, some where, some place, someone once said to themselves "I'd really like to set those people on fire over there, but I just can't get close enough".
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

as I understand it - it's not defined, and it doesn't matter. the authors of the JVM are free to make it whatever size they want or need to for whatever reason. They often choose a size that is most efficient on the specific platform their jvm will run on.

but more importantly, it doesn't matter. you can't do any byte manipulation like you would in C, so you never need to count over say seven bytes in an array...

Why is it so important that you know?

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: size of boolean
It's not a secret anymore!