1

Possible Duplicate:
What is the size of a boolean variable in java?
Java - boolean primitive type - size

A boolean value is a single-on off and could be represented in one bit. However, I have read that a language often uses more bytes are them to be accessed more efficiently.

What is the specific number of bytes in Java?

Community
  • 1
  • 1
james_dean
  • 1,477
  • 6
  • 26
  • 37
  • 1
    Do you mean capital-B Boolean in your title? In Java `Boolean` and `boolean` are different. `Boolean` is an object that wraps the primitive `boolean`. – Andrew Oct 22 '11 at 18:20
  • In most JVMs a boolean field uses one byte. A Boolean object can use 16 bytes, however you only need two Boolean.TRUE and Boolean.FALSE so there is no excuse in trying to create additional ones. This means only the reference matters (typically 4 bytes) – Peter Lawrey Oct 22 '11 at 20:06

1 Answers1

1

Oracle has a complete list of the data-types and sizes here: http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

Unfortunately, that page states:

This data type represents one bit of information, but its "size" isn't something that's precisely defined.

This answer seems to provide the reasoning of why the size isn't precisely defined.

Community
  • 1
  • 1
UnhandledExcepSean
  • 12,504
  • 2
  • 35
  • 51