File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How much space does boolean takes up in Java ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How much space does boolean takes up in Java ?" Watch "How much space does boolean takes up in Java ?" New topic
Author

How much space does boolean takes up in Java ?

Shunjie Liu
Greenhorn

Joined: Feb 21, 2006
Posts: 7
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: 2367
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
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
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.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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://aspose.com/file-tools
 
subject: How much space does boolean takes up in Java ?