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!
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
Dervin BuckeryCourses Plus Student 531 Points
Primitive data types as an object
So I am trying to understand wrapper classes. Just a thought so basically once you get so far with coding you will just start to store any of the primitive data types inside of objects?
Brendon Butler4,254 Points
Primitive data types are a necessary part of Java to tell the compiler what type of variable you have. Other languages allow you to be vague, and the type will automatically be selected.
You still need things such as int, boolean, char, etc. But they are very basic -- only storing the binary values of whatever variable you have. This saves a lot of memory/space as you don't need to instantiate another object class every time you want to store a variable.
These primitive data types have wrapper classes that allow you to access methods to manipulate the primitive data type. For example, you can convert a string to an integer using the Integer class' methods.
int stringToInt = Integer.parseInt("1234");
parseInt method returns an
int that can be stored in a variable or used in a method.
I'm not sure if I directly answered your question, but if not, here's some resources to help you understand the topic a little better:
Primitive Wrapper Classes | Difference Between Integer and int | Integer vs int | Integer vs int (2)