From the course: Java Essential Training: Syntax and Structure

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Wrapper classes

Wrapper classes

- [Instructor] All primitive data types can also be expressed as objects via the use of wrapper classes. Here, we have two variables, number1 and number2. Number1 has a data type of int, which is primitive. And number2 has a data type of integer which is a wrapper class for the primitive data type int. This makes number2 an object. The benefit of using wrapper classes, as opposed to primitive data types, is the ability to utilize convenience methods that are available in the wrapper class. Wrapper classes exist for all primitive data types. Let's take a look inside of the integer wrapper class. The integer wrapper class is filled with helpful methods for working with integers. For example, there are fields for MIN_VALUE and MAX_VALUE which will return the minimum and maximum values for an integer memory space. There are the compare and compareto methods to compare integer values. There are methods that will allow you to…

Contents