Java Wrapper Classes — தமிழ்

</>Coding Tamilan.← Java course & curriculum
Java Masterclass · Lesson 45 / 50 · தமிழ்

Java Wrapper Classes

Bridge primitive values and object APIs.

Step-by-step explanationsRunnable JavaPractice + answer

முக்கிய விளக்கங்கள் தமிழில் உள்ளன. 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.
01 / The concept

அடிப்படையைப் புரிந்துகொள்ளுங்கள்

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.

02 / Step by step

விரிவான விளக்கங்கள்

Java Wrapper Classes என்னன்னு தெரியுமா?

Wrapper classes primitive data types-ஐ objects-ஆ மாத்துது. Collections-ல primitives-ஐ use பண்ண முடியாது — wrapper classes வேணும்.

Primitive TypeWrapper Class
byteByte
shortShort
intInteger
longLong
floatFloat
doubleDouble
booleanBoolean
charCharacter

Autoboxing மற்றும் Unboxing

Java automatically primitive-ஐ wrapper-ஆ (autoboxing) மற்றும் wrapper-ஐ primitive-ஆ (unboxing) convert பண்ணும்:

Java reference fragmentJAVA
// 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()); // 3

Autoboxing என்றால் என்ன?

  1. Manual type casting
  2. Primitive type-ஐ automatically Wrapper class object-ஆக convert செய்வது
  3. Object-ஐ String-ஆக convert செய்வது
  4. 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);`

03 / Read and predict

முழுமையான உதாரணம்

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.

Main.java · complete runnable exampleJAVA
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.

04 / Learn by changing

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.

Open Java editor ↗
After the editor loads, choose Load this lesson example, then press RUN.

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.

05 / Your turn

நீங்களே முயற்சி செய்யுங்கள்

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.

Coding Tamilan · Understand the idea. Try the code. Build the habit.