KwickAcademy Java · 6 min · free
Wrapper Classes, Autoboxing and Character Methods
Why wrapper classes exist, the eight primitive-to-wrapper names, autoboxing and unboxing, parseInt and valueOf, and the Character methods.
Follows the syllabus of: CBSE Class 12 Information Technology (802), ICSE Class 10 Computer Applications, ISC Class 11 Computer Science (868), ISC Class 12 Computer Science (868)
On screen in this lesson
Why wrapper classes exist
| Primitives like int and char are not objects |
| A wrapper class wraps a primitive inside an object |
| Collections such as ArrayList store only objects |
| Wrappers give useful methods, like parseInt |
Primitive and wrapper
| Primitive | Wrapper class | Note |
|---|---|---|
| int | Integer | different name |
| char | Character | different name |
| double | Double | capital D |
| boolean | Boolean | capital B |
| byte, short, long | Byte, Short, Long | capital letter |
| float | Float | capital F |
Rules to remember
| Autoboxing: primitive to wrapper, automatically |
| Unboxing: wrapper to primitive, automatically |
| Added in Java 5, so all modern Java has it |
| Unboxing a null gives NullPointerException |
Conversion methods
| Method | Takes | Gives |
|---|---|---|
| Integer.parseInt(s) | String | int |
| parseDouble(s) | String | double |
| Integer.valueOf(s) | String or int | Integer object |
| String.valueOf(x) | any value | String |
Pause and predict: bad text
| Integer.parseInt("12.5") |
| Integer.parseInt("12a") |
| Both give NumberFormatException |
| Double.parseDouble("12") works: 12.0 |
Character methods
| Method | Question | Example |
|---|---|---|
| isDigit(c) | 0 to 9? | '7' gives true |
| isLetter(c) | a letter? | 'k' gives true |
| isWhitespace(c) | space, tab, newline | ' ' gives true |
| isUpperCase(c) | a capital? | 'a' gives false |
| toUpperCase(c) | makes capital | 'a' gives 'A' |
Quick answers
Why does "25" + 5 print 255?
Text plus a number joins them. Integer.parseInt("25") first, then + 5 gives 30.
What does Integer.parseInt("12.5") do?
It throws a NumberFormatException, because an int cannot hold a decimal point.
KwickClips from this lesson
Short clips, one idea each. Good for revision the night before.
Is an int an object in Java?42 sec
Does Integer obj = 45 compile?42 sec
Why is "25" + 5 equal to 255?40 sec
How do you check if a character is a digit?43 secThe full lesson, in text
Hello students, welcome to Kwickprep. In Java, the text twenty five plus the number five prints two five five, as text, not thirty. Why? Today we will fix that with wrapper classes, and learn autoboxing and the Character methods.
Let us see why wrapper classes are needed. Primitive types, like int, double and char, hold simple values, and they are not objects. A wrapper class wraps one primitive value inside an object, like a gift inside a box. Some Java tools, like the list called ArrayList, can store only objects. Wrapper classes also give ready methods, such as converting text into a number.
Each of the eight primitive types has its own wrapper class. Int becomes Integer, which is a different name, so remember it. Char becomes Character, also a different name. Double becomes Double, with a capital D. Boolean becomes Boolean, with a capital B. Byte, short and long just take a capital first letter. Float becomes Float, with a capital F.
Autoboxing means Java automatically puts a primitive into its wrapper object. Here forty five, an int, is boxed into the Integer object called obj. Unboxing is the reverse, taking the primitive value back out. When we add five to obj, Java unboxes it to forty five. So num is fifty, and it prints fifty.
Here is where autoboxing really helps. The list called m can hold only Integer objects, and ArrayList is the kind of list we create. When we add ninety one, Java boxes it into an Integer for us. When we get it back and add nine, Java unboxes it. So total is one hundred.
Here are four rules to remember. Autoboxing turns a primitive into its wrapper object automatically. Unboxing turns the wrapper back into a primitive automatically. This feature was added in Java version five, so every modern Java has it. But a wrapper variable can be null, meaning empty, and unboxing a null gives a null pointer exception.
Now let us solve the puzzle from the start. The string variable s holds the text twenty five. Text plus a number joins them, so it prints two five five. Integer dot parse int converts the text into a real int, stored in the variable n. Now n plus five is thirty.
Double dot parse double works the same way for decimal text. The cost text, forty nine point five, becomes a double stored in the variable d. Integer dot value of also reads text, but it returns an Integer object, not a primitive int. Java unboxes qty when we add, so the output is fifty nine point five.
Let us put these methods in one table. Integer dot parse int takes a String and gives a primitive int. Double dot parse double takes a String and gives a double. Integer dot value of takes a String or an int, and gives an Integer object. String dot value of goes the other way, and turns any value into a String.
Pause and predict before running. Can parse int read twelve point five? No, because an int cannot have a decimal point. Can it read twelve a? No, a letter is not a digit. Both lines stop the program with a number format exception. But parse double of twelve works, and gives twelve point zero.
The Character wrapper class has methods that test one character, and we write Character dot before each. Is digit asks, is this a digit from zero to nine? Is letter asks, is this an alphabet letter? Is whitespace asks, is this a space, a tab or a new line? Is upper case asks, is this a capital letter, so small a gives false. To upper case does not ask, it returns the capital form, so small a becomes capital A.
Board exams often ask for counting programs. The text is B four, seat fifty two. The for loop takes each character, one by one, into the variable c. If Character dot is digit of c is true, we add one to the counter d. The digits are four, five and two. So it prints three.
Here the variable c holds small k. To upper case returns capital K, which we store in up. Notice that c itself does not change, because the method returns a new value. So it prints small k to capital K.
Let us revise what we learned today. Wrapper classes put primitive values inside objects. Autoboxing and unboxing convert between them automatically. Parse int and parse double turn text into numbers. Value of returns a wrapper object instead of a primitive. And the Character methods test or change a single character.
Courses that teach this
| Course | Unit |
|---|---|
| CBSE Class 12 Information Technology (802) | Fundamentals of Java Programming |
| ICSE Class 10 Computer Applications | Library Classes |
| ISC Class 11 Computer Science (868) | Object-Oriented Programming with Java |
| ISC Class 12 Computer Science (868) | Primitive Values, Wrapper Classes, Types and Casting |
| Programming All levels Java | Arrays and Strings |
Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.
Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

