• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

boolean in java

 
Rui Wang
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In java, when you declare a variable with primitive type boolean, does it mean the JVM would only use 1 bit to represent this variable? What about the rest of the byte or word in the machine, is it used?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"mrchicos," please check your private messages by clicking on My Private Messages. Thanks!

The size of a boolean in Java is not specified, so this is left to the JVM.
 
Nishant Modak
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defined


Reference:SUN: Primitive Data Types
 
fred rosenberger
lowercase baba
Bartender
Posts: 12203
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'size' of things is java is not really a well defined concept. since java removes pointer arithmatic and the responsibility of memory management from the developer, it's not really needed.

As i understand it, the BEHAVIOR of things is defined. a boolean must represent 'true' and 'false'. As to the specifics of HOW that happens, that's up to the folks who write the JVM. if they want to do it with a single bit, that's fine. if they want to use 12 bytes, that's fine too. it's up to them.

really, you don't know, and you don't need to know.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's very true Fred. Certain things we are NOT required to bother much
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic