What's the difference between boolean and Boolean in Java? [duplicate]

Solution 1:

It's fairly Simple and the same for GWT and Java:

  • boolean can be yes or no
  • Boolean can be yes, no or NULL.

So unless you need the NULL (like for example your loading the field from the database, and you want NULL to be different to false) then stick to boolean.

Solution 2:

I'm not sure if the GWT factor makes a difference but in general:

boolean is a java primitive type whereas Boolean is an object/reference type that wraps a boolean

Converting between primitives and objects like this is known as boxing/unboxing.

Here is more info:

http://javaeye.wordpress.com/2008/06/17/boxing-and-unboxing-conversion/

Why box you ask?

http://java.sun.com/j2se/1.5.0/docs/guide/language/autoboxing.html

http://www.javapractices.com/topic/TopicAction.do?Id=197