0
Boolean is datatype or Variable?
5 Réponses
+ 15
Edit:
Boolean is data type and the variable of type boolean can hold 1-bit of data (true/1 or false/0). However, its representation inside the memory would be different. For some more precise info see the following link:
[https://stackoverflow.com/questions/383551/what-is-the-size-of-a-boolean-variable-in-java]
+ 14
Oh yeah. That's true Vincent. I should be more precise next time. ;)
+ 13
In theory it's 1bit long for T and F, but it's clear machine can't handle a single bit for addressing reason.
+ 3
@Babak Sheykhan (PERS), No variable can have 1-bit size, since the minimum addressable information chunk is 1 byte, and minimal processible chunk is 1 word (size of processor's register). According to the link you provided:
"Size of the boolean in java is virtual machine dependent. but Any Java object is aligned to an 8 bytes granularity. A Boolean has 8 bytes of header, plus 1 byte of payload, for a total of 9 bytes of information. The JVM then rounds it up to the next multiple of 8. so the one instance of java.lang.Boolean takes up 16 bytes of memory."
And as to the original question, Boolean is a type, you can create variables of some type. So there may be a variable of type Boolean.
+ 3
I'm just nitpicking to the fact that 'variable of type Boolean has a size of 1 bit in Java' and 'variable of type Boolean can hold 1 bit of information' are different things, and first one isn't correct.