aspose file tools
The moose likes Beginning Java and the fly likes About boolean data type Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "About boolean data type" Watch "About boolean data type" New topic
Author

About boolean data type

Sethu Raman
Greenhorn

Joined: Oct 18, 2007
Posts: 14
Hi all

Why is boolean data type is called as Virtual Machine Deppendent....?
I come across this line while learning for certification exam.
Could anyone give me a clear idea regarding this...
How the jvm manages the boolean data type.....


Thanks in advance

Regards,
Sethu
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12928
    
    3

I'll have to guess exactly what the context of that question is, but probably what is meant is that it's not specified how much memory a boolean uses - how much memory a boolean uses can be different on different underlying platforms or JVM implementations.

For example, Sun's JVM might use a 32-bit integer for storing booleans in the computer's memory, while HP's JVM might use an 8-bit integer or something else. (This is just an example I just made up, these are not how Sun's or HP's JVMs really work).

For your Java program it makes no difference. A boolean can be 'true' or 'false', and how exactly the JVM stores a boolean in memory doesn't make any difference in the way your Java program works.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 318
Another point of view....
Some people might like to say that an int 0 is false, while an in 1 is true

Others might like to say int 0 is false and -1 is true, or the other way (since branch-on-minus, branch-on-not-minus is a quick conditional branch in many micro-architectures).

Some might like to say that 0 is fals and any non-zero value is a true...

What Sun is saying is..... we don't care HOW you choose to do it internally but let there be a notion of true and false.


------------------------
Bob
SCJP - 86% - June 11, 2009
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: About boolean data type
 
Similar Threads
boolean
How to get the all results using HQL
Ask & Read Questions to Think More
question about boolean data type
Boolean mapping