Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects (Retired) Meet Objects Welcome Back

java.lang.Boolean v/s boolean

Why does REPL create two different data types for the boolean variable?

2 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Hi Mukul,

This is what is known as a wrapper type. All the primitive data types int, char, bool, etc. have classes that have a bunch of static methods that let you perform actions on them, for instance:

Integer.parseInt("3");
Character.isUpperCase('a');

Going between the types is called boxing and unboxing.

We will talk about these more in an upcoming course, but for now, you can basically just imagine them as synonyms for each other. The wrapper class just has methods, while the primitive one does not. The REPL stores the object. Here is documentation on wrapper types and autoboxing, don't worry if everything doesn't make sense, it will soon!

Hope that helps, let me know if it is unclear

Thanks. I read this in your voice

boolean is a primitive type, Boolean is wrapper type (object) so you can use methods on it.