• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Size of boolean

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I like to know the size of the data type "boolean"
Diff books giving diff size( 1 bit or 1 byte)
Pls tell me the correct answer
Regards
Subramanian
[This message has been edited by nattami (edited November 28, 2001).]
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following link says 1 bit but I think it depends on the JVM implementation http://www.javaworld.com/javaworld/javaqa/2000-09/04-qa-0929-size.html
Then thew following link says that it is not defined http://www.javaworld.com/javaworld/jw-09-2000/jw-0908-eckelobjects.html


All numeric types are signed, so don't go looking for unsigned types. The size of the boolean type is not explicitly defined; it is only specified to be able to take the literal values true or false.


Please read the JavaRanch Naming Policy and register again.
Thank you for your cooperation.
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
[This message has been edited by Valentin Crettaz (edited November 28, 2001).]
 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sun's tutorial also does not speak about the size of the boolean...it just says true or false...
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html
Uma
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

To optimize memory access time, more than one bit is used to store a boolean value. In the Sun JVM all integer types smaller than 32 bits are promoted to 32 bits when pushed on the stack during execution. An array of booleans is treated as an array of bytes. ... In Java, the boolean type is not based on integers. In particular, the programmer cannot increment, decrement, or add boolean values. Inside a JVM, there are no instructions dedicated to booleans, and integer operstions are used. ... Despite popular belief, there is no speed advantage to bytes, shorts, or chars -- modern CPUs take the same amount of time to load or multiply 8 bits as they take for 32 bits.


Peter van der Linden currently leads a team of kernal programmers at Sun Microsystems, Just Java 2.

Note that a boolean is controlled by one bit which is either on or off. It is, however, stored in various ways by the JVM depending on how it is being used.

[This message has been edited by Marilyn deQueiroz (edited November 28, 2001).]
 
Uma Viswanathan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good explanation...thanks Marilyn deQueiroz
Uma
 
Ranch Hand
Posts: 782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this...Hope u'll enjoy http://www.javaranch.com/ubb/Forum24/HTML/012713.html
Bye.
Viki.
------------------
Count the flowers of ur garden,NOT the leafs which falls away!
 
His brain is the size of a cherry pit! About the size of this ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic