Ab tak aapne apni classes banayi hain — apne data members, apne methods, apne constructors. Lekin Java ke saath hazaaron classes pehle se aati hain, jo aam kaam pehle se kar chuki hain. Inhein library classes kehte hain. Is chapter mein hum unme se do parivaar dekhenge jo ICSE Class 10 ke syllabus mein naam se likhe hain: wrapper classes (Integer, Double, Character waghairah) aur unke methods, aur uske saath autoboxing aur unboxing. Yeh Unit 5 hai, aur ismein aane wale sawaal aksar chhote lekin pakke hote hain — ya toh aapko method ka kaam yaad hai, ya nahi.
Primitive vs Composite Data Types
Syllabus is chapter ki shuruaat ek zaroori fark se karta hai, isliye hum bhi wahin se shuru karenge.
- A primitive data type Java mein pehle se bana hua hai aur uske andar sirf ek value rehti hai —
int,double,char,booleanwaghairah. Inke paas koi method nahi hota. - A composite data type (jise class type ya reference type bhi kehte hain) kai values aur unke saath kaam karne wale methods, dono ko ek naam ke andar rakhta hai. Aapki banayi hui har class ek composite type hai — yaani aapne ek naya data type banaya.
Stringbhi ek composite type hai.
int n; ki default value 0 hoti hai — kyunki woh primitive hai. Lekin Integer n; ki default value null hoti hai — kyunki woh ek object hai, aur abhi koi object bana hi nahi. Compile karke dekha gaya: pehla 0 chhaapta hai, doosra null.int n = 5; n.length(); galat hai. Composite type par bula sakte hain — String s = "hi"; s.length(); sahi hai. Class ko syllabus “a new data type created by the user” kehta hai, aur yeh line one-mark answer ke liye kaafi hai.What a Wrapper Class Is
Ab ek dikkat samajhiye. Primitive types tez hain, lekin unke paas methods nahi hote. Kabhi-kabhi humein ek primitive value ke saath kaam karwana hota hai — jaise ek String ko number banana, ya yeh poochhna ki ek char digit hai ya nahi.
Iske liye Java har primitive type ke saath ek class deta hai, jise wrapper class kehte hain, kyunki woh primitive value ko ek object ke andar “lapet” deti hai. Syllabus kehta hai: all primitive types have corresponding class wrappers.
| Primitive type | Wrapper class |
|---|---|
byte |
Byte |
short |
Short |
int |
Integer |
long |
Long |
float |
Float |
double |
Double |
char |
Character |
boolean |
Boolean |
int ka wrapper Integer hai (Int nahi), aur char ka wrapper Character hai (Char nahi). Baaki sab bas pehla akshar capital kar dene se ban jaate hain.Turning Text Into Numbers: the parse Methods
Yeh wrapper classes ka sabse zyada kaam aane wala hissa hai. Jab aap keyboard se ya kisi text se koi number lete hain, toh woh shuru mein String hota hai — aur String par jod-ghatav nahi hota, sirf jud jaata hai. Use asli number banane ke liye parse methods hain.
int Integer.parseInt(String s) long Long.parseLong(String s) float Float.parseFloat(String s) double Double.parseDouble(String s)
class L1
{
public static void main(String args[])
{
String s1 = "250";
String s2 = "3.75";
int a = Integer.parseInt(s1);
double b = Double.parseDouble(s2);
System.out.println("String s1 + 10 gives : " + (s1 + 10));
System.out.println("int a + 10 gives : " + (a + 10));
System.out.println("double b * 2 gives : " + (b * 2));
}
}
Output
String s1 + 10 gives : 25010 int a + 10 gives : 260 double b * 2 gives : 7.5
Pehli line poora khel dikha deti hai. "250" + 10 ne jod nahi kiya — usne 10 ko peeche chipka diya aur 25010 ban gaya. Lekin Integer.parseInt("250") ke baad woh asli int hai, isliye 250 + 10 = 260 mila. Yeh fark har saal output questions mein aata hai.
parseInt("250") kaam nahi karega — Integer.parseInt("250") likhna zaroori hai, kyunki yeh Integer class ka static method hai. Isi tarah Character.isDigit(c), sirf isDigit(c) nahi.valueOf(), jo aage String handling chapter ki list mein bhi aata hai. Fark yaad rakhiye: Integer.parseInt("5") ek primitive int lautata hai, jabki Integer.valueOf("5") ek Integer object lautata hai. Screen par dono 5 hi chhaapte hain, isliye output se fark pata nahi chalta — sawaal return type par banta hai.Integer x = new Integer(5); sikhati hain. Java 9 se yeh tareeka deprecated hai — compiler khud chetavni deta hai: “uses or overrides a deprecated API”. Aaj ka sahi tareeka autoboxing hai: Integer x = 5;. Board mein yehi likhiye.The Character Class Methods
Ye methods ek char ke baare mein sawaal poochhte hain ya use badal dete hain. Syllabus in sab ko naam se likhta hai, isliye inhein rat lena faaydemand hai. Dhyaan dijiye ki pehle chhe boolean lautate hain (haan ya na), aur aakhri do naya char lautate hain.
Character method in one run
class L2
{
public static void main(String args[])
{
char ch = 'K';
char d = '7';
char sp = ' ';
System.out.println("isDigit('K') = " + Character.isDigit(ch));
System.out.println("isLetter('K') = " + Character.isLetter(ch));
System.out.println("isLetterOrDigit('7')= " + Character.isLetterOrDigit(d));
System.out.println("isUpperCase('K') = " + Character.isUpperCase(ch));
System.out.println("isLowerCase('K') = " + Character.isLowerCase(ch));
System.out.println("isWhitespace(' ') = " + Character.isWhitespace(sp));
System.out.println("toLowerCase('K') = " + Character.toLowerCase(ch));
System.out.println("toUpperCase('k') = " + Character.toUpperCase('k'));
}
}
Output
isDigit('K') = false
isLetter('K') = true
isLetterOrDigit('7')= true
isUpperCase('K') = true
isLowerCase('K') = false
isWhitespace(' ') = true
toLowerCase('K') = k
toUpperCase('k') = K
Ek baat gaur karne layak hai: '7' single quotes mein hai, isliye woh character saat hai, number saat nahi. isLetterOrDigit('7') ne true isliye diya kyunki digit bhi is method ke liye theek hai.
toUpperCase aur toLowerCase original char ko badalte nahi — woh ek naya char lauta dete hain. Agar aapko badla hua akshar chahiye toh use kisi variable mein lena hoga: ch = Character.toUpperCase(ch);. Sirf Character.toUpperCase(ch); likhne se kuch nahi hoga.Autoboxing and Unboxing
Purane Java mein primitive ko object banane ke liye poora likhna padta tha. Ab Java yeh kaam khud kar leta hai, aur usi suvidha ke do naam hain — syllabus dono ki definition maangta hai.
- Autoboxing — ek primitive value ka apne aap uske wrapper object mein badal jaana.
Integer x = 75;mein75ekinthai, lekin woh apne aapIntegerban gaya. - Unboxing — iska ulta. Wrapper object ka apne aap primitive value mein badal jaana.
int y = x;meinIntegerobject khudintban gaya.
class L3
{
public static void main(String args[])
{
Integer boxed = 75;
int plain = boxed;
Double dBoxed = 4.5;
double dPlain = dBoxed;
System.out.println("Autoboxed Integer : " + boxed);
System.out.println("Unboxed int + 25 : " + (plain + 25));
System.out.println("Autoboxed Double : " + dBoxed);
System.out.println("Unboxed double * 2 : " + (dPlain * 2));
}
}
Output
Autoboxed Integer : 75 Unboxed int + 25 : 100 Autoboxed Double : 4.5 Unboxed double * 2 : 9.0
Line 1 aur 4 par gaur kijiye. Integer boxed = 75; autoboxing hai. int plain = boxed; unboxing hai. Aapne ek bhi extra shabd nahi likha — Java ne dono taraf ka badlaav khud kar diya. Aakhri line 9.0 hai, 9 nahi, kyunki double ka jawaab hamesha decimal ke saath aata hai.
Putting It Together: Counting Inside a String
Board ke programming sawaalon mein wrapper methods akele nahi aate — woh ek loop ke andar aate hain, jahan aap String ke har character ko dekh kar kuch gin rahe hote hain. Yeh pattern yaad rakh lijiye, kyunki aage String handling chapter mein bhi yahi dobara aayega.
class L4
{
public static void main(String args[])
{
String data = "Aarav 17 88.5";
int count = 0;
for (int i = 0; i < data.length(); i++)
{
char c = data.charAt(i);
if (Character.isDigit(c))
count++;
}
System.out.println("Digits in the line = " + count);
}
}
Output
Digits in the line = 5
Ginne wale characters hain 1, 7, 8, 8 aur 5 — kul 5. Dhyaan dijiye ki dashamlav ka bindu (.) digit nahi hai, isliye woh nahi gina gaya. Yeh teen-line ka dhaancha — loop, charAt, phir ek Character method — is chapter ka sabse zyada kaam aane wala pattern hai.
Dry-Run Bank — Output Questions
Pehle kaagaz par trace kijiye, phir answer kholiye.
class DL1
{
public static void main(String args[])
{
String a = "12";
String b = "8";
System.out.println(a + b);
System.out.println(Integer.parseInt(a) + Integer.parseInt(b));
System.out.println(a + Integer.parseInt(b));
}
}
Show Answer
128 20 128
Pehli line: dono String hain, isliye jud gaye → 128. Doosri: dono parse ho gaye, isliye asli jod → 20. Teesri line asli trap hai — a abhi bhi String hai, isliye 8 ko parse karne ke baad bhi woh String ke saath chipak gaya → phir se 128. Ek taraf String hone se poora + concatenation ban jaata hai.
class DL2
{
public static void main(String args[])
{
String s = "Class 10 ICSE";
int letters = 0, digits = 0, spaces = 0;
for (int i = 0; i < s.length(); i++)
{
char c = s.charAt(i);
if (Character.isLetter(c))
letters++;
else if (Character.isDigit(c))
digits++;
else if (Character.isWhitespace(c))
spaces++;
}
System.out.println("Letters = " + letters);
System.out.println("Digits = " + digits);
System.out.println("Spaces = " + spaces);
}
}
Show Answer
Letters = 9 Digits = 2 Spaces = 2
"Class 10 ICSE" mein akshar hain C,l,a,s,s,I,C,S,E — kul 9. Digits 1 aur 0 — 2. Aur do khaali jagah. Kul milaakar 13 characters, jo length() se milta hai — yeh apne jawaab ko check karne ka accha tareeka hai.
char printed as a number
class DL3
{
public static void main(String args[])
{
char c = 'd';
System.out.println(Character.toUpperCase(c));
System.out.println((int) Character.toUpperCase(c));
System.out.println(Character.isLetterOrDigit('#'));
}
}
Show Answer
D 68 false
Doosri line mein (int) cast ne 'D' ko uski Unicode value dikha di — 68. (Yaad rakhiye: 'A' 65 hai, isliye 'D' 68 hua.) Teesri line false hai kyunki # na akshar hai na ank.
How This Chapter Is Examined
CISCE ke Class X syllabus ke anusaar Computer Applications (86) mein ek written paper, do ghante ka, 100 marks hota hai, aur uske alaawa Internal Assessment bhi 100 marks ka, jo poori tarah practical hai aur jismein saal bhar mein kam se kam 20 lab assignments karne hote hain. CISCE ke question paper mein yeh 100 marks do hisson mein bante hain: Section A — 40 marks, jismein saare sawaal karne hote hain, aur Section B — 60 marks, jismein chhe sawaalon mein se koi chaar karne hote hain. Section A khud do sawaalon ka banta hai: Question 1 20 marks ke MCQs, aur Question 2 20 marks ke chhote sawaal — das hisse, har ek 2 marks ka.
Library classes ka is paper mein ek khaas roop hai. Poora 60-marks wala programming sawaal is chapter par shaayad hi banta ho — lekin Section A mein yeh chapter lagbhag hamesha aata hai. Ek method ka output poochha jaata hai, ya do methods ka antar, ya autoboxing ki definition. Aur Section B ke bade programs ke andar yeh methods bar-bar kaam aate hain, khaaskar jab kisi String ke characters ginne hon.
isDigit boolean lautata hai, isliye woh if ke andar seedhe likha jaata hai. toUpperCase char lautata hai, isliye use kisi variable mein lena padta hai. parseInt int lautata hai. Agar return type galat maan liya, toh poora program galat ho jaata hai.Practice Worksheet (10 Questions)
Pehle khud kijiye, phir answer kholiye.
int, char, double and boolean.
Show Answer
A wrapper class is a library class that represents a primitive data type as an object, so that the value can be used where an object is required and so that useful methods become available for it. Every primitive type has a corresponding wrapper. For the four asked: int → Integer, char → Character, double → Double, boolean → Boolean.
Show Answer
Autoboxing is the automatic conversion of a primitive value into an object of its corresponding wrapper class, for example Integer x = 75;. Unboxing is the automatic conversion of a wrapper class object back into its primitive value, for example int y = x; where x is an Integer. In both cases the programmer writes nothing extra — the compiler inserts the conversion.
Show Answer
A primitive data type is built into Java and stores a single value; it has no methods of its own. Example: int. A composite (class or reference) data type groups several values together with methods that work on them, and is effectively a new data type; a class written by the programmer is a composite type. Example: String, or any user-defined class. The practical test is that a method can be called on a composite type using the dot operator, but not on a primitive.
class QL1
{
public static void main(String args[])
{
String marks = "45";
String bonus = "5";
int total = Integer.parseInt(marks) + Integer.parseInt(bonus);
System.out.println("Total = " + total);
System.out.println("Wrong way = " + (marks + bonus));
}
}
Show Answer
Total = 50 Wrong way = 455
Parse karne ke baad 45 aur 5 asli numbers hain → 50. Bina parse kiye woh sirf jud gaye → 455.
class QL2
{
public static void main(String args[])
{
String s = "Hello World 2026";
int up = 0, low = 0, dig = 0;
for (int i = 0; i < s.length(); i++)
{
char c = s.charAt(i);
if (Character.isUpperCase(c)) up++;
else if (Character.isLowerCase(c)) low++;
else if (Character.isDigit(c)) dig++;
}
System.out.println(up + " " + low + " " + dig);
}
}
Show Answer
2 8 4
Capital: H aur W → 2. Small: e,l,l,o,o,r,l,d → 8. Digits: 2,0,2,6 → 4. Do spaces kisi bhi counter mein nahi gine gaye, kyunki teeno conditions unke liye false hain.
Integer.parseInt(), Character.isLetter(), Character.toUpperCase(), Double.parseDouble().
Show Answer
Integer.parseInt() returns int. Character.isLetter() returns boolean. Character.toUpperCase() returns char. Double.parseDouble() returns double. Yaad rakhne ka tareeka: jo method is se shuru hota hai woh hamesha boolean lautata hai.
Character.toUpperCase(ch); and is surprised that ch is unchanged. Explain the error and give the corrected line.
Show Answer
toUpperCase() does not modify the character passed to it; it returns a new char. Since the returned value was not stored anywhere, it was simply discarded and ch kept its original value. The corrected line is ch = Character.toUpperCase(ch);. Yahi baat toLowerCase() par bhi laagu hoti hai.
"Principal Saab", treating capital and small letters alike.
Show Answer
class Vowels
{
public static void main(String args[])
{
String s = "Principal Saab";
int count = 0;
for (int i = 0; i < s.length(); i++)
{
char c = Character.toLowerCase(s.charAt(i));
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
count++;
}
System.out.println("Vowels = " + count);
}
}
Output:
Vowels = 5
Character.toLowerCase() pehle laga dene se capital aur small dono ek saath sambhal gaye — warna aapko das conditions likhni padtin. Vowels hain i, i, a, a, a → 5.
Show Answer
A primitive type is not an object — it stores only a value and carries no methods, so there is nothing for the dot operator to reach. A composite type is an object and does carry methods. Wrong: int n = 5; n.length();. Right: String s = "hi"; s.length();. This is exactly why wrapper classes exist — they give a primitive value an object form so that methods become available.
"30" and "6" are stored in p and q. Write the statement that prints their sum as 36, and explain what System.out.println(p + q); would print instead.
Show Answer
The correct statement is System.out.println(Integer.parseInt(p) + Integer.parseInt(q));, which prints 36. Writing System.out.println(p + q); would print 306, because both operands are still String objects and the + operator therefore joins them end to end instead of adding them.
Aage kya? Ab tak humne class ke andar ka saara saamaan dekh liya — data members, methods, constructors aur ab library classes. Agla sawaal yeh hai ki in sab ko bahar wale se chhupaya kaise jaaye, aur kaun sa hissa kis tak pahunche — woh encapsulation aur access specifiers ka kaam hai. Peeche jaana ho toh Constructors aur User-Defined Methods dobara padh lijiye.
Kaizen: Aaj se roz ek chhota program likhiye jismein kisi String ke characters par loop chale aur ek cheez gini jaaye — kabhi vowels, kabhi digits, kabhi capital letters, kabhi spaces. Dhaancha har baar wahi rahega: loop, charAt, ek Character method. Ek hafte mein yeh pattern aapki ungliyon ko yaad ho jaayega, aur paper mein aap ise bina soche likh denge.
