File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Size of bool variable

 
Mehul Sanghvi
Ranch Hand
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I tried and look for size of bool variable in java but was not able to find the same. Can anyone please let me know.
Thanks in advance.
Regards,
Mehul.
 
Ron Newman
Ranch Hand
Posts: 1056
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java, you never deal with the byte-size of variables, unless you are serializing them.
 
Mehul Sanghvi
Ranch Hand
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am sorry but I didnt get the gist of what you are trying to say.
Just like int = 32bits, double = 64bits, same way, bool = ?bits ??
Thanks again!
Regards,
Mehul.
 
Ron Newman
Ranch Hand
Posts: 1056
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not a meaningful question. A boolean is either true or false. Java does not have C's pointers or sizeof() operator.
If you call the writeBoolean() method of a DataOutputStream, you will write one byte.
[ September 03, 2003: Message edited by: Ron Newman ]
 
Mehul Sanghvi
Ranch Hand
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ron!
I get the point that for a user it does not make any difference as bool variable can only store true/false.
What I wanted tot know was how does JVM internally represent it, as a byte or as a bit?
Thanks again.
Regards,
Mehul.
 
Ron Newman
Ranch Hand
Posts: 1056
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since that decision is not visible to you as the user of the JVM, I presume it's implementation-dependent.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JVM instruction set actually doesn't contain any boolean-specific instructions; Java compilers use int instructions for them. So booleans in registers are basically 32-bit, like an int.
I've heard it said that it's possible for the JVM to optimize the storage of arrays of boolean to use one byte or even one bit each; don't know if any actually do this or not.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
boolean variable memory size is platform dependent. Many JVMS booleans are implemented internally as ints so this means 4 bytes. So dont think that boolean means less memory.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic