SlideShare a Scribd company logo
JSpiders - Wrapper classes
• Java is not pure object oriented.
• Any language which makes use of primitive
type of data such languages are not object
oriented.
• Few purely object oriented languages are
Ex: Scala, Smalltalk, Eiffel ..etc
• The primitive data types are not objects, they
do not belong to any class.
• Sometimes, it is required to convert data types
into objects in Java language.
• A data type can be converted into an object and
then used with the help of Wrapper Classes.
• A wrapper class wraps (encloses) around
a data type and gives it an object
appearance.
• Wherever, the data type is required as an
object, Wrapper class object can be used.
• Wrapper classes include methods to
unwrap the object and give back the data
type.
• It can be compared with a chocolate. The manufacturer
wraps the chocolate with some foil or paper to prevent
from pollution. The user takes the chocolate, removes
and throws the wrapper and eats it.
To wrap (or to convert) each primitive data type, there comes a
wrapper class. Eight wrapper classes exist in java.lang package that
represent 8 data types. Following list gives.
JSpiders - Wrapper classes
• All wrapper classes are final classes.
• All Wrapper classes implements comparable type.
• All wrapper classes overrides 3 object class methods
1.toString()
2.hashCode()
3.equals(Object obj)
Conversion of primitive data to object type is known as Boxing.
EX: int k = 100;
Integer it1 = new Integer(k);
double d = 3.3;
Double dt2= new Double(d);
Conversion of Object type of data to Primitive type is called as
Un-Boxing.
EX: int m = it1.intValue();
System.out.println(m); // prints 100
double n = dt2.doubleValue();
System.out.println(n); // prints 3.3
Boxing and Un-Boxing Can be done implicitly by compiler, it is
known as Auto Boxing and Auto Un-Boxing.
Integer a1=30; Auto Boxing
int l= a1; Auto Un-Boxing
Wrapper Classes In Collection FrameWorks
• Wrapper Classes are used in collection framework.
• In Collection we can add only Object type of data.
• If primitive data added in Collection Framework then auto boxing and
auto un-boxing both happens Implicitly.
Ex: ArrayList a1 = new ArrayList();
a1.add(12);
a1.add(2356);
a1.add(4.5);
• Here First auto boxing happens and then up-casting to Object class
happens.
Parsing Technique
• Conversion of String type of data to Number format is called as Parsing
• For Parsing we make use of parseX() methods which are present in Wrapper
classes.
Ex:
String str = “1234”;
int i = Integer.parseInt(str);
System.out.println(i); // 1234
• Parsing has to be done carefully, else we may get Exception.
• In previous example if String value is “1234g” ,in this case during parsing the
value doesn’t match with Integer hence we get NumberFormatException.

More Related Content

PPT
PPT
Wrapper class (130240116056)
PPTX
Data Structures in Python
PPTX
Advanced Python : Static and Class Methods
PPT
Java ppt
PPT
sets and maps
PDF
Numpy tutorial
PPT
Priority queues
Wrapper class (130240116056)
Data Structures in Python
Advanced Python : Static and Class Methods
Java ppt
sets and maps
Numpy tutorial
Priority queues

What's hot (20)

PDF
Wrapper classes
PPTX
Arrays In C++
ODP
Garbage collection
PPTX
Deque and its applications
PDF
Standard template library
PPTX
Polymorphism in java
PPTX
Queue
PPTX
Stack and Queue by M.Gomathi Lecturer
PPTX
String Builder & String Buffer (Java Programming)
PPT
Lecture 5 sorting and searching
PDF
Generics
PDF
Python tuple
PDF
Queue as data_structure
PPT
PDF
Java Arrays
PDF
Python programming : Arrays
DOCX
Report 02(Binary Search)
PPTX
Chapter 16 Dictionaries
PDF
Java conditional statements
PPT
Stl Containers
Wrapper classes
Arrays In C++
Garbage collection
Deque and its applications
Standard template library
Polymorphism in java
Queue
Stack and Queue by M.Gomathi Lecturer
String Builder & String Buffer (Java Programming)
Lecture 5 sorting and searching
Generics
Python tuple
Queue as data_structure
Java Arrays
Python programming : Arrays
Report 02(Binary Search)
Chapter 16 Dictionaries
Java conditional statements
Stl Containers
Ad

Viewers also liked (6)

PPT
Partnering with communities in Colorado
PPTX
Ays Summer Meet the Stars
PPTX
Business health check business infoload 2016
PPTX
Are you keen to know about upcoming trends in Live Event Industry
PDF
Resource wrappers in C++
PPTX
C++ 11 range-based for loop
Partnering with communities in Colorado
Ays Summer Meet the Stars
Business health check business infoload 2016
Are you keen to know about upcoming trends in Live Event Industry
Resource wrappers in C++
C++ 11 range-based for loop
Ad

Similar to JSpiders - Wrapper classes (20)

PPTX
L9 wrapper classes
PPTX
Java tutorial part 3
PPTX
Java Unit 2(Part 1)
PPTX
C# Generics
PPTX
________JAVA___wrapper___classes___.pptx
PPTX
Ch 2 Library Classes.pptx
PDF
Ch 2 Library Classes.pdf
PDF
7. VARIABLEs presentation in java programming. Pdf
PPTX
static members in object oriented program.pptx
PPTX
static MEMBER IN OOPS PROGRAMING LANGUAGE.pptx
PPTX
class as the basis.pptx
PPTX
Object Oriented Programming.pptx
PPTX
Java Tutorial Lab 2
PPTX
Module 1.pptx
DOCX
Library methods class 10 NOTES FOR EXAM
PPT
02._Object-Oriented_Programming_Concepts.ppt
PDF
Java Day-4
PDF
oopm 2.pdf
PPTX
C++ training
L9 wrapper classes
Java tutorial part 3
Java Unit 2(Part 1)
C# Generics
________JAVA___wrapper___classes___.pptx
Ch 2 Library Classes.pptx
Ch 2 Library Classes.pdf
7. VARIABLEs presentation in java programming. Pdf
static members in object oriented program.pptx
static MEMBER IN OOPS PROGRAMING LANGUAGE.pptx
class as the basis.pptx
Object Oriented Programming.pptx
Java Tutorial Lab 2
Module 1.pptx
Library methods class 10 NOTES FOR EXAM
02._Object-Oriented_Programming_Concepts.ppt
Java Day-4
oopm 2.pdf
C++ training

More from JSpiders Basavanagudi (9)

DOCX
Profit n loss assignments
DOCX
JSpiders_Percentages assignments 1
DOCX
JSpiders-Ratios assignments
DOCX
JSpiders Numbers assignment 1
PDF
JSpiders BTR Uco bank clericalcadreexam2008e
PDF
JSpiders BTR Oriental bank of commerce clerical sample question paper all ...
PDF
JSpiders BTR Cw emocktest
PDF
JSPiders Common written exam (cwe) for various public sector banks in india s...
DOCX
Profit n loss assignments
JSpiders_Percentages assignments 1
JSpiders-Ratios assignments
JSpiders Numbers assignment 1
JSpiders BTR Uco bank clericalcadreexam2008e
JSpiders BTR Oriental bank of commerce clerical sample question paper all ...
JSpiders BTR Cw emocktest
JSPiders Common written exam (cwe) for various public sector banks in india s...

Recently uploaded (20)

PDF
AI in Product Development-omnex systems
PDF
System and Network Administration Chapter 2
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
System and Network Administraation Chapter 3
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
top salesforce developer skills in 2025.pdf
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
ai tools demonstartion for schools and inter college
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Design an Analysis of Algorithms I-SECS-1021-03
AI in Product Development-omnex systems
System and Network Administration Chapter 2
Reimagine Home Health with the Power of Agentic AI​
Odoo POS Development Services by CandidRoot Solutions
System and Network Administraation Chapter 3
Upgrade and Innovation Strategies for SAP ERP Customers
top salesforce developer skills in 2025.pdf
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Understanding Forklifts - TECH EHS Solution
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
ai tools demonstartion for schools and inter college
CHAPTER 2 - PM Management and IT Context
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Design an Analysis of Algorithms I-SECS-1021-03

JSpiders - Wrapper classes

  • 2. • Java is not pure object oriented. • Any language which makes use of primitive type of data such languages are not object oriented. • Few purely object oriented languages are Ex: Scala, Smalltalk, Eiffel ..etc • The primitive data types are not objects, they do not belong to any class. • Sometimes, it is required to convert data types into objects in Java language. • A data type can be converted into an object and then used with the help of Wrapper Classes.
  • 3. • A wrapper class wraps (encloses) around a data type and gives it an object appearance. • Wherever, the data type is required as an object, Wrapper class object can be used. • Wrapper classes include methods to unwrap the object and give back the data type.
  • 4. • It can be compared with a chocolate. The manufacturer wraps the chocolate with some foil or paper to prevent from pollution. The user takes the chocolate, removes and throws the wrapper and eats it.
  • 5. To wrap (or to convert) each primitive data type, there comes a wrapper class. Eight wrapper classes exist in java.lang package that represent 8 data types. Following list gives.
  • 7. • All wrapper classes are final classes. • All Wrapper classes implements comparable type. • All wrapper classes overrides 3 object class methods 1.toString() 2.hashCode() 3.equals(Object obj)
  • 8. Conversion of primitive data to object type is known as Boxing. EX: int k = 100; Integer it1 = new Integer(k); double d = 3.3; Double dt2= new Double(d); Conversion of Object type of data to Primitive type is called as Un-Boxing. EX: int m = it1.intValue(); System.out.println(m); // prints 100 double n = dt2.doubleValue(); System.out.println(n); // prints 3.3
  • 9. Boxing and Un-Boxing Can be done implicitly by compiler, it is known as Auto Boxing and Auto Un-Boxing. Integer a1=30; Auto Boxing int l= a1; Auto Un-Boxing
  • 10. Wrapper Classes In Collection FrameWorks • Wrapper Classes are used in collection framework. • In Collection we can add only Object type of data. • If primitive data added in Collection Framework then auto boxing and auto un-boxing both happens Implicitly. Ex: ArrayList a1 = new ArrayList(); a1.add(12); a1.add(2356); a1.add(4.5); • Here First auto boxing happens and then up-casting to Object class happens.
  • 11. Parsing Technique • Conversion of String type of data to Number format is called as Parsing • For Parsing we make use of parseX() methods which are present in Wrapper classes. Ex: String str = “1234”; int i = Integer.parseInt(str); System.out.println(i); // 1234 • Parsing has to be done carefully, else we may get Exception. • In previous example if String value is “1234g” ,in this case during parsing the value doesn’t match with Integer hence we get NumberFormatException.