File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes boolean in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "boolean in java" Watch "boolean in java" New topic

boolean in java

Rui Wang

Joined: Jun 02, 2005
Posts: 6
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

Joined: Aug 31, 2004
Posts: 11343

"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.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Nishant Modak

Joined: Sep 29, 2006
Posts: 27
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

Joined: Oct 02, 2003
Posts: 11955

'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
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3381

That's very true Fred. Certain things we are NOT required to bother much

Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
I agree. Here's the link:
subject: boolean in java
It's not a secret anymore!