jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes boolean Variable Size? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "boolean Variable Size?" Watch "boolean Variable Size?" New topic

boolean Variable Size?

Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
Q) What is the size of boolean Variable in JAVA???

SCJP 6.0 96%

(Connecting the Dots ....)
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33106

Welcome to JavaRanch!

A boolean is one bit since there are only two choices of value. Search "java primitive size" if you are looking for sizes of other types.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

I found this quote from sun tutorial Primitive Data Types
This data type represents one bit of information, but its "size" isn't something that's precisely defined.

Please correct me, if i am wrong.

Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
Thanks Jeanne Boyarsky !!!

@Muhammad Ali Khojaye
I think its JVM dependent feature, but since it represents only 1 bit of information , it should be of size 1-bit.
But may be JVM has to store something else in it .....So the size may vary i think.

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46349
The tutorial is correct; the "size" of a boolean can vary from one implementation to another. It is only necessary to use 1 bit, but that leaves at least 7 bits in the byte which cannot be used. So it might be easier to use all 8 bits.
I agree. Here's the link: http://aspose.com/file-tools
subject: boolean Variable Size?
It's not a secret anymore!