• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

boolean Variable Size?

 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q) What is the size of boolean Variable in JAVA???
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34965
378
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sahil,
Welcome to JavaRanch!

A boolean is one bit since there are only two choices of value. Search "java primitive size" if you are looking for sizes of other types.
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found this quote from sun tutorial Primitive Data Types
This data type represents one bit of information, but its "size" isn't something that's precisely defined.



Please correct me, if i am wrong.
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne Boyarsky !!!

@Muhammad Ali Khojaye
I think its JVM dependent feature, but since it represents only 1 bit of information , it should be of size 1-bit.
But may be JVM has to store something else in it .....So the size may vary i think.


 
Campbell Ritchie
Sheriff
Pie
Posts: 50175
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The tutorial is correct; the "size" of a boolean can vary from one implementation to another. It is only necessary to use 1 bit, but that leaves at least 7 bits in the byte which cannot be used. So it might be easier to use all 8 bits.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic