Java Java Basics Perfecting the Prototype Parsing Integers

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?

1 Answer

Brendon Butler
Brendon Butler
4,235 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");

The 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)