aspose file tools*
The moose likes Beginning Java and the fly likes Boolean or boolean what is the difference in term of use? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Boolean or boolean what is the difference in term of use?" Watch "Boolean or boolean what is the difference in term of use?" New topic
Author

Boolean or boolean what is the difference in term of use?

Ranji Sura
Ranch Hand

Joined: Oct 28, 2012
Posts: 84


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 ?
Thank you.
Rohan Deshmkh
Ranch Hand

Joined: Aug 31, 2012
Posts: 127
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.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

Ranjith Suranga wrote:What is the difference between "Boolean" and "boolean"?

The same as the difference between Long and long, or Short and short: The first is a class, the second is a primitive.

Seem to be both same even others(Float - float,Double - double, Character - char,...)

No, they're very different; but they are automatically converted in certain situations.

Have a look at tutorials for a full explanation, because the rest of your post suggests that you haven't come across this yet.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39396
    
  28
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.
Ranji Sura
Ranch Hand

Joined: Oct 28, 2012
Posts: 84
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.
Ranji Sura
Ranch Hand

Joined: Oct 28, 2012
Posts: 84
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...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39396
    
  28
You’re welcome
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18656
    
    8

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.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39396
    
  28
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.

I have checked, and it doesn’t.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Boolean or boolean what is the difference in term of use?