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?
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.
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.
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.
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad: