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 ]
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
posted
0
I think that is left up to the specific JVM to decide. I'm not sure.
Ken Blair
Ranch Hand
Joined: Jul 15, 2003
Posts: 1078
posted
0
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.
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
posted
0
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
Jeff Albertson
Ranch Hand
Joined: Sep 16, 2005
Posts: 1780
posted
0
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?
That would be a two bit implementation
There is no emoticon for what I am feeling!
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: How much space does boolean takes up in Java ?