Hi guys, I know that an int takes up 32 bits but what about boolean ? does it takes up 2 bits in the heap ? Is it the same as Boolean Object?
Thank you ^^ [ March 27, 2006: Message edited by: Shunjie Liu ]
Joined: Feb 07, 2005
I think that is left up to the specific JVM to decide. I'm not sure.
Joined: Jul 15, 2003
The JLS does not specify the size of a boolean, it simply specifies that it has two values: true and false. Whether or not those values are stored as a single bit or 64 bits is entirely up to the JVM.
Joined: Oct 30, 2001
In general, you should not worry about exactly how much space is used by fields and objects in Java. It isn't fixed and the language doesn't let you find out (well, maybe there's something in 1.5...?).
A big reason for Java's popularity is that it gets you away from worrying about low-level stuff like how the data is actually stored in memory.
Occasionally, you do care, because you are working with huge amounts of data in memory, and want to avoid using more than you have to. A little experimentation is required, then, but remember that any results will be specific to the JVM and platform you're testing on.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
Joined: Sep 16, 2005
Originally posted by Shunjie Liu: Hi guys, I know that an int takes up 32 bits but what about boolean ? does it takes up 2 bits in the heap ? Is it the same as Boolean Object?