• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

How much space does boolean takes up in Java ?  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 2410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that is left up to the specific JVM to decide. I'm not sure.
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!