• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Effective representation size of a boolean in bits

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Just re-started studying language fundamentals for certification so here is a very basic question:

I have read that boolean type may take only the values true and false and the representation size might vary. Why does it vary, within what limits, and what does the variation depend upon and how much do I need to know for the certification exam?

Best regards,

Mike
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mike,

Welcome to the JavaRanch.

What you need to know for the exam is limited to:

1- boolean is a primitive data type that can be assigned true or false.
2- You can't assign 0 or 1 to it as in some programming languages it is.
3- There is a wrapper class corresponding to boolean primitive that can
encapsulate the boolean. Its constructor can take either primitive boolean
or String as:

Boolean B1 = new Boolean(true);
Boolean B2 = new Boolean("TrUe"); //non case sensitive
boolean b1= false;
Boolean B3 = new Boolean(b1);


Note: You need not to bother the representation of boolean at physical
level for the exam.

Thanks,
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You do not need to know the size of a boolean for the SCJP.

Just know it takes values true and false, and that you cannot convert it to an integral or floating-point type.

Any more effort or other thoughts about this issue can be better spent on some other SCJP topic, Generics for example

Take a look at the JVM specification if really want.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello "Mike in Southwark"-

Welcome to JavaRanch.

On your way in you may have missed that we have a JavaRanch Naming Policy for displayed (screen) names. Your displayed name must consist of a first name (or an initial), a space, and a family name (in that order) and not be obviously fictitious. Since yours "Mike in Southwark", does not conform with it, please take a moment to change it, which you can do right here.

Posters with nonconforming displayed names will be locked out of JavaRanch after a few posts using those names.

Thanks
-Barry

(NR) - search tag
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Other people have said that the size of a boolean can differ from one implementation of the JVM to another and that we don't need to know the size of a boolean for the SCJP exam. I believe that they are right because I looked it up in a SCJP book.

If you're wondering why the size would vary, In Pascal & in C, I have seen the size of a boolean vary to pad to a word boundry where a word size was 2 bytes or 4 bytes with an option to pack booleans to a single byte or a single bit in an array of booleans.

Kaydell
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic