Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

size of boolean

 
Shivangi Joshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anybody please tell me what is size of boolean.i have already searched on net,the results are so much confusing,some says 1 bit(as per JVM specification),some says 1 byte, and not applicable,and many more.so please let me know what is correct size of boolean.


thanks in advance

shivangi...
 
Nathan Leniz
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a topic covering that question.

I found this on the sun forums.

"There is actually no boolean type. A Java expression that operates on boolean values is compiled to use the int data type to represent boolean variables. This means a boolean is usually a 32-bit variable. However arrays of booleans are treated as arrays of bytes, so booleans are 8 bits in an array"
[ July 26, 2008: Message edited by: Nathan Leniz ]
 
fred rosenberger
lowercase baba
Bartender
Posts: 12087
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as I understand it - it's not defined, and it doesn't matter. the authors of the JVM are free to make it whatever size they want or need to for whatever reason. They often choose a size that is most efficient on the specific platform their jvm will run on.

but more importantly, it doesn't matter. you can't do any byte manipulation like you would in C, so you never need to count over say seven bytes in an array...

Why is it so important that you know?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic