This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
What is the difference between "Boolean" and "boolean" ? Seem to be both same even others(Float - float,Double - double, Character - char,...)
Boolean is predefined class so, is boolean reserved word used to represent Boolean class ? If so why we use boolean instead of Boolean.. I mean there is no
significant difference between length.. Like String why we don't use it's class name ?
Please help me to clear this.. Is there any difference ?
boolean is a primitive type whereas Boolean is wrapper class.Same applies for (int,Integer),(long,Long) etc.
Wrapper classes "wrap" the respective primitive data type into an object of that class.
They are used with collections, as primitive types are not allowed with collections.Also using wrapper classes give you access to many methods that you can call on that object.For eg. Character wrapper class have methods like:
isDigit() – to determine whether the character is digit.
isLower() – to determine whether the character is lower case alphabet.
is Letter() – to determine whether the character is an alphabet.
we cannot use the above methods if we use a primitive type as compared to a wrapper class.
A Boolean is an object, an instance of the class of that name. A boolean is a primitive, which keeps quiet about how many bits it uses, but has
When I started Java, you had to write Boolean bb = Boolean.valueOf(b); or similar. They introduced boxing in Java5, so you can write Boolean bb = true; or similar.
Joined: Oct 28, 2012
Winston Gutkowski wrote:
because the rest of your post suggests that you haven't come across this yet.
Ya, sir.. I am really new to the java... SO what to do...? these problems always come when studying.
Extremely Thank you.
Joined: Oct 28, 2012
Extremely Thank you for every one who gives me answers, opinions, advice, everything... They help me lot to develop as a beginner...
Thank you once again...
Autoboxing is supposed to translate seamlessly between Boolean and boolean without you having to write any code. But here's a problem which can arise because of that:
So when autoboxing finds itself trying to convert a null reference to a boolean value, it will throw a NullPointerException. I don't remember whether the tutorial mentions this -- hopefully it does, but I haven't checked.
Joined: Oct 13, 2005
Paul Clapham wrote: . . . trying to convert a null reference . . . I don't remember whether the tutorial mentions this -- hopefully it does, but I haven't checked.