Java Wrapper Classes
Bridge primitive values and object APIs.
முக்கிய விளக்கங்கள் தமிழில் உள்ளன. Runnable example மற்றும் கூடுதல் practice notes ஆங்கிலத்தில் உள்ளன.
இந்தப் பாடத்தில்…
- Explain the key idea behind Wrapper Classes.
- Read and run a complete example, then predict what changes.
- Recognize the topic-specific mistake discussed below.
அடிப்படையைப் புரிந்துகொள்ளுங்கள்
Wrapper classes such as Integer represent primitive-like values as objects. Autoboxing and unboxing make many conversions implicit, which is convenient for collections. Null references and object identity can still surprise you.
விரிவான விளக்கங்கள்
Java Wrapper Classes என்னன்னு தெரியுமா?
Wrapper classes primitive data types-ஐ objects-ஆ மாத்துது. Collections-ல primitives-ஐ use பண்ண முடியாது — wrapper classes வேணும்.
| Primitive Type | Wrapper Class |
|---|---|
| byte | Byte |
| short | Short |
| int | Integer |
| long | Long |
| float | Float |
| double | Double |
| boolean | Boolean |
| char | Character |
Autoboxing மற்றும் Unboxing
Java automatically primitive-ஐ wrapper-ஆ (autoboxing) மற்றும் wrapper-ஐ primitive-ஆ (unboxing) convert பண்ணும்:
// Autoboxing & unboxing
int num = 42;
Integer boxed = num; // autoboxing
int unboxed = boxed; // unboxing
// Useful static methods
System.out.println(Integer.MAX_VALUE); // 2147483647
System.out.println(Integer.parseInt("123")); // 123
System.out.println(Double.parseDouble("3.14")); // 3.14
System.out.println(Integer.toBinaryString(10)); // 1010
String s = Integer.toString(255);
System.out.println(s.length()); // 3Autoboxing என்றால் என்ன?
- Manual type casting
- Primitive type-ஐ automatically Wrapper class object-ஆக convert செய்வது
- Object-ஐ String-ஆக convert செய்வது
- Array-ஐ List-ஆக convert செய்வது
Reveal answer / விடை
Primitive type-ஐ automatically Wrapper class object-ஆக convert செய்வது
Autoboxing: Java automatically `int → Integer`, `double → Double` convert செய்யும். Unboxing: `Integer → int`. Collections primitives accept செய்யாததால் இது மிக useful — `List list = new ArrayList<>(); list.add(5);`
முழுமையான உதாரணம்
This complete Main.java program focuses on the lesson idea. Reference fragments above may demonstrate individual statements; this example includes the imports, entry point, and supporting types it needs.
public class Main {
public static void main(String[] args) throws Exception {
int value = 42;
Integer boxed = value;
int unboxed = boxed;
System.out.println(unboxed);
System.out.println(Integer.parseInt("125") + 5);
}
}Predict first. Then reveal the expected output / வெளியீடு
42 130
The output shown was checked by running this complete example. Trace the executed statements in order, then compare with your run.
Change it. Run it. Understand it.
Load this lesson example into the editor. Change one value or statement, predict the result, then press RUN to execute Java.
Powered by OneCompiler. Code you run is sent to OneCompiler for execution. For Scanner examples, supply input in the editor I/O panel; for file examples, files exist in its execution environment.
நீங்களே முயற்சி செய்யுங்கள்
Practice challenge
Change the parseInt input to abc, then restore the valid number.
Reveal the answer and reasoning / விடை
Parsing abc throws NumberFormatException because it is not a valid decimal integer.
தவிர்க்க வேண்டிய தவறு: Unboxing a null Integer throws NullPointerException. Use equals for wrapper value comparisons rather than relying on == reference identity.
பாடத்தின் சுருக்கம்
- Explain the example without reading the output first.
- Make the change requested in the practice task.
- Describe why the result changed—or why compilation failed.
Ready to move on? Follow the next lesson in course order, or return to the curriculum to review a prerequisite.