This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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?
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
'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.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors