際際滷

際際滷Share a Scribd company logo
Wrapper Classes
Prepared By
Soni Axay R. (130240116056)
5th
IT
Guided By
Prof. Hiral Shastri
Sub Topics
 Introduction
 Primitives & Wrappers
 Use of Wrapper Classes
 Wrapper Object Creation
 MAX_VALUE Constant
 Examples
Introduction
 In Java, the term wrapper class commonly
refers to a set of Java classes that objectify
the primitive Java types.
 That is, for each primitive type, there is a
corresponding Java Wrapper class that represents
that type.
 e.g. the wrapper for the int type is the Integer
class.
Primitives & Wrappers
 Java has a wrapper class for each of the eight primitive data types:
Primitive
Type
Wrapper
Class
Primitive
Type
Wrapper
Class
boolean Boolean float Float
byte Byte int Integer
char Character long Long
double Double short Short
Use of the Wrapper Classes
 Javas primitive data types (boolean, int, etc.) are not
classes.
 Wrapper classes are used in situations where objects
are required, such as for elements of a Collection:
List<Integer> a = new
ArrayList<Integer>();
methodRequiringListOfIntegers(a);
Value => Object: Wrapper Object
Creation
 Wrapper.valueOf() takes a value
(or string) and returns an object
of that class:
Integer i1 = Integer.valueOf(42);
Integer i2 = Integer.valueOf(42);
Boolean b1 = Boolean .valueOf(true);
Boolean b2 = Boolean .valueOf(true);
Long n1 = Long.valueOf(42000000L);
Long n1 = Long.valueOf(42000000L);
Object => Value
 Each wrapper class Type has a method
typeValue to obtain the objects value:
Integer i1 = Integer.valueOf(42);
Boolean b1 = Boolean.valueOf(false);
System.out.println(i1.intValue());
System.out.println(b1.intValue());
=>
42
false
String => value
 The Wrapper class for each primitive type has
a method parseType() to parse a string
representation & return the literal value.
Integer.parseInt(42) => 42
Boolean.parseBoolean(true) => true
Double.parseDouble(2.71) => 2.71
//
 Common use: Parsing the arguments to a
program:
Each Number Wrapper has a
MAX_VALUE constant:
byteObj = new Byte(Byte.MAX_VALUE);
shortObj = new Short(Short.MAX_VALUE);
intObj = new Integer(Integer.MAX_VALUE);
longObj = new Long(Long.MAX_VALUE);
floatObj = new Float(Float.MAX_VALUE);
doubleObj = new
Double(Double.MAX_VALUE);
printNumValues("MAXIMUM NUMBER
VALUES:");
MAX values (output from previous
slide):
=>
Byte:127
Short:32767
Integer:2147483647
Long:9223372036854775807
Float:3.4028235E38
Double:1.7976931348623157E308
Integer
Convert Integer to Java
String object
1.public油class油IntegerToStringExample油{
2.油
3.油油public油static油void油main(String[]油args)油{
4.油油油油Integer油intObj油=油new油Integer(10);
5.油油油
6.油油油油//use toString method of Integer class to conver Integer into String.
7.油油油油String油str油=油intObj.toString();
8.油油油油System.out.println("Integer油converted油to油String油as油"油+油str);
9.油油}
10.}
11.油
12./*
13.Output of the program would be
14.Integer converted to String as 10
15.*/
Float
Convert Java Float Object
to String Object Example
1.油
2.油油public油static油void油main(String[]油args)油{
3.油
4.油
5.油油油油Float油fObj油=油new油Float(10.25);
6.public油class油JavaFloatToStringExample油{
7.油油油油//use toString method of Float class to convert Float into String.
8.油油油油String油str油=油fObj.toString();
9.油油油油System.out.println("Float油converted油to油String油as油"油+油str);
10.油油}
11.}
12.油
13./*
14.Output of the program would be
15.Float converted to String as 10.25
Byte
Convert Byte object to
String object
油
1.public油class油ByteToStringExample油{
2.油
3.油油public油static油void油main(String[]油args)油{
4.油油油油Byte油bObj油=油new油Byte("10");
5.油油油
6.油油油油//use toString method of Byte class to convert Byte into String.
7.油油油油String油str油=油bObj.toString();
8.油油油油System.out.println("Byte油converted油to油String油as油"油+油str);
9.油油}
10.}
11.油
12.Output of the program would be
13.Byte converted to String as 10
Long
Convert Long object to
String object
1. public油class油LongToStringExample油{
2. 油
3. 油油public油static油void油main(String[]油args)油{
4. 油油油油Long油lObj油=油new油Long(10);
5. 油油油
6. 油油油油//use toString method of Long class to convert Long into String.
7. 油油油油String油str油=油lObj.toString();
8. 油油油油System.out.println("Long油converted油to油String油as油"油+油str);
9. 油油}
10. }
11. 油
12. /*
13. Output of the program would be
14. Long converted to String as 10
Short
Convert Short object to
String object
1. public油class油ShortToStringExample油{
2. 油
3. 油油public油static油void油main(String[]油args)油{
4. 油油油油short油s油=油10;
5. 油油油油Short油sObj油=油new油Short(s);
6. 油油油
7. 油油油油//use toString method of Short class to convert Short into String.
8. 油油油油String油str油=油sObj.toString();
9. 油油油油System.out.println("Short油converted油to油String油as油"油+油str);
10. 油油}
11. }
12. 油
13. /*
14. Output of the program would be
15. Short converted to String as 10
16. */
Thank You

More Related Content

What's hot (20)

ODP
Python Modules
Nitin Reddy Katkam
PPTX
Strings in Java
Abhilash Nair
PPT
Searching algorithms
Trupti Agrawal
PPTX
String in java
Ideal Eyes Business College
PPTX
Python Functions
Mohammed Sikander
PPTX
Data Structures in Python
Devashish Kumar
PDF
Constructors and Destructors
Dr Sukhpal Singh Gill
PPTX
Collections and its types in C# (with examples)
Aijaz Ali Abro
PPTX
Stack data structure
Tech_MX
PPTX
Java string handling
Salman Khan
PPTX
Exception handling
PhD Research Scholar
PPTX
Arrays in java
Arzath Areeff
PPTX
Functions in python
colorsof
PDF
Constructor and Destructor
Kamal Acharya
PPT
stack presentation
Shivalik college of engineering
PDF
Tuples in Python
DPS Ranipur Haridwar UK
PPT
C# Exceptions Handling
sharqiyem
PPTX
Java swing
Apurbo Datta
PPTX
JAVA AWT
shanmuga rajan
PPTX
OOPS IN C++
Amritsinghmehra
Python Modules
Nitin Reddy Katkam
Strings in Java
Abhilash Nair
Searching algorithms
Trupti Agrawal
Python Functions
Mohammed Sikander
Data Structures in Python
Devashish Kumar
Constructors and Destructors
Dr Sukhpal Singh Gill
Collections and its types in C# (with examples)
Aijaz Ali Abro
Stack data structure
Tech_MX
Java string handling
Salman Khan
Exception handling
PhD Research Scholar
Arrays in java
Arzath Areeff
Functions in python
colorsof
Constructor and Destructor
Kamal Acharya
stack presentation
Shivalik college of engineering
Tuples in Python
DPS Ranipur Haridwar UK
C# Exceptions Handling
sharqiyem
Java swing
Apurbo Datta
JAVA AWT
shanmuga rajan
OOPS IN C++
Amritsinghmehra

Similar to Wrapper class (130240116056) (20)

PPTX
DAY_1.3.pptx
ishasharma835109
PPTX
Java tutorial part 3
Mumbai Academisc
PPTX
L9 wrapper classes
teach4uin
PDF
Wrapper classes
Ravi_Kant_Sahu
PPTX
________JAVA___wrapper___classes___.pptx
gnyanadeepa
PPTX
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
VivekSharma34623
PDF
Wrapper classes
simarsimmygrewal
DOCX
Fundamental classes in java
Garuda Trainings
PDF
Java Day-4
People Strategists
PPTX
03 and 04 .Operators, Expressions, working with the console and conditional s...
Intro C# Book
PPTX
Java Unit 2(Part 1)
Dr. SURBHI SAROHA
PPT
wrapper class.ppt
Peace80
PPTX
01 Java Language And OOP PART I
Hari Christian
PDF
Lecture 5.pdf
SakhilejasonMsibi
PPT
wrapper classes
Rajesh Roky
PPTX
Ch 2 Library Classes.pptx
KavitaHegde4
PDF
Ch 2 Library Classes.pdf
KavitaHegde4
PPT
Primitive Wrappers
Bharat17485
PPTX
Chapter i(introduction to java)
Chhom Karath
PDF
Built-in Classes in JAVA
Mahmoud Ali Ibrahim
DAY_1.3.pptx
ishasharma835109
Java tutorial part 3
Mumbai Academisc
L9 wrapper classes
teach4uin
Wrapper classes
Ravi_Kant_Sahu
________JAVA___wrapper___classes___.pptx
gnyanadeepa
vectors.(join ALL INDIA POLYTECHNIC (AICTE)).pptx
VivekSharma34623
Wrapper classes
simarsimmygrewal
Fundamental classes in java
Garuda Trainings
Java Day-4
People Strategists
03 and 04 .Operators, Expressions, working with the console and conditional s...
Intro C# Book
Java Unit 2(Part 1)
Dr. SURBHI SAROHA
wrapper class.ppt
Peace80
01 Java Language And OOP PART I
Hari Christian
Lecture 5.pdf
SakhilejasonMsibi
wrapper classes
Rajesh Roky
Ch 2 Library Classes.pptx
KavitaHegde4
Ch 2 Library Classes.pdf
KavitaHegde4
Primitive Wrappers
Bharat17485
Chapter i(introduction to java)
Chhom Karath
Built-in Classes in JAVA
Mahmoud Ali Ibrahim
Ad

Recently uploaded (20)

PPTX
Introduction to Python Programming Language
merlinjohnsy
PDF
lesson4-occupationalsafetyandhealthohsstandards-240812020130-1a7246d0.pdf
arvingallosa3
PPTX
Kel.3_A_Review_on_Internet_of_Things_for_Defense_v3.pptx
Endang Saefullah
PPTX
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
PPT
惆惘悋愕悸 忰悋 惘悸 惠惺 悴惡 愃惘惡 悋愕惆悋
忰惆 惶惶 惠惠悸
PPTX
Mobile database systems 20254545645.pptx
herosh1968
PPTX
Introduction to File Transfer Protocol with commands in FTP
BeulahS2
PPTX
CST413 KTU S7 CSE Machine Learning Neural Networks and Support Vector Machine...
resming1
PPTX
Stability of IBR Dominated Grids - IEEE PEDG 2025 - short.pptx
ssuser307730
PDF
Designing for Tomorrow Architectures Role in the Sustainability Movement
BIM Services
PDF
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
PDF
Plant Control_EST_85520-01_en_AllChanges_20220127.pdf
DarshanaChathuranga4
PPTX
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
AsadShad4
PPTX
LECTURE 7 COMPUTATIONS OF LEVELING DATA APRIL 2025.pptx
rr22001247
PDF
June 2025 Top 10 Sites -Electrical and Electronics Engineering: An Internatio...
elelijjournal653
PPTX
MATERIAL SCIENCE LECTURE NOTES FOR DIPLOMA STUDENTS
SAMEER VISHWAKARMA
PPTX
Precooling and Refrigerated storage.pptx
ThongamSunita
PDF
PRIZ Academy - Process functional modelling
PRIZ Guru
PDF
惠惘惘 惺 悋惠忰 悋惆悋 惠惆 悋悋悄 忰 悴悋忰.pdf
忰惆 惶惶 惠惠悸
PPTX
How to Un-Obsolete Your Legacy Keypad Design
Epec Engineered Technologies
Introduction to Python Programming Language
merlinjohnsy
lesson4-occupationalsafetyandhealthohsstandards-240812020130-1a7246d0.pdf
arvingallosa3
Kel.3_A_Review_on_Internet_of_Things_for_Defense_v3.pptx
Endang Saefullah
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
惆惘悋愕悸 忰悋 惘悸 惠惺 悴惡 愃惘惡 悋愕惆悋
忰惆 惶惶 惠惠悸
Mobile database systems 20254545645.pptx
herosh1968
Introduction to File Transfer Protocol with commands in FTP
BeulahS2
CST413 KTU S7 CSE Machine Learning Neural Networks and Support Vector Machine...
resming1
Stability of IBR Dominated Grids - IEEE PEDG 2025 - short.pptx
ssuser307730
Designing for Tomorrow Architectures Role in the Sustainability Movement
BIM Services
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
Plant Control_EST_85520-01_en_AllChanges_20220127.pdf
DarshanaChathuranga4
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
AsadShad4
LECTURE 7 COMPUTATIONS OF LEVELING DATA APRIL 2025.pptx
rr22001247
June 2025 Top 10 Sites -Electrical and Electronics Engineering: An Internatio...
elelijjournal653
MATERIAL SCIENCE LECTURE NOTES FOR DIPLOMA STUDENTS
SAMEER VISHWAKARMA
Precooling and Refrigerated storage.pptx
ThongamSunita
PRIZ Academy - Process functional modelling
PRIZ Guru
惠惘惘 惺 悋惠忰 悋惆悋 惠惆 悋悋悄 忰 悴悋忰.pdf
忰惆 惶惶 惠惠悸
How to Un-Obsolete Your Legacy Keypad Design
Epec Engineered Technologies
Ad

Wrapper class (130240116056)

  • 1. Wrapper Classes Prepared By Soni Axay R. (130240116056) 5th IT Guided By Prof. Hiral Shastri
  • 2. Sub Topics Introduction Primitives & Wrappers Use of Wrapper Classes Wrapper Object Creation MAX_VALUE Constant Examples
  • 3. Introduction In Java, the term wrapper class commonly refers to a set of Java classes that objectify the primitive Java types. That is, for each primitive type, there is a corresponding Java Wrapper class that represents that type. e.g. the wrapper for the int type is the Integer class.
  • 4. Primitives & Wrappers Java has a wrapper class for each of the eight primitive data types: Primitive Type Wrapper Class Primitive Type Wrapper Class boolean Boolean float Float byte Byte int Integer char Character long Long double Double short Short
  • 5. Use of the Wrapper Classes Javas primitive data types (boolean, int, etc.) are not classes. Wrapper classes are used in situations where objects are required, such as for elements of a Collection: List<Integer> a = new ArrayList<Integer>(); methodRequiringListOfIntegers(a);
  • 6. Value => Object: Wrapper Object Creation Wrapper.valueOf() takes a value (or string) and returns an object of that class: Integer i1 = Integer.valueOf(42); Integer i2 = Integer.valueOf(42); Boolean b1 = Boolean .valueOf(true); Boolean b2 = Boolean .valueOf(true); Long n1 = Long.valueOf(42000000L); Long n1 = Long.valueOf(42000000L);
  • 7. Object => Value Each wrapper class Type has a method typeValue to obtain the objects value: Integer i1 = Integer.valueOf(42); Boolean b1 = Boolean.valueOf(false); System.out.println(i1.intValue()); System.out.println(b1.intValue()); => 42 false
  • 8. String => value The Wrapper class for each primitive type has a method parseType() to parse a string representation & return the literal value. Integer.parseInt(42) => 42 Boolean.parseBoolean(true) => true Double.parseDouble(2.71) => 2.71 // Common use: Parsing the arguments to a program:
  • 9. Each Number Wrapper has a MAX_VALUE constant: byteObj = new Byte(Byte.MAX_VALUE); shortObj = new Short(Short.MAX_VALUE); intObj = new Integer(Integer.MAX_VALUE); longObj = new Long(Long.MAX_VALUE); floatObj = new Float(Float.MAX_VALUE); doubleObj = new Double(Double.MAX_VALUE); printNumValues("MAXIMUM NUMBER VALUES:");
  • 10. MAX values (output from previous slide): => Byte:127 Short:32767 Integer:2147483647 Long:9223372036854775807 Float:3.4028235E38 Double:1.7976931348623157E308
  • 12. Convert Integer to Java String object 1.public油class油IntegerToStringExample油{ 2.油 3.油油public油static油void油main(String[]油args)油{ 4.油油油油Integer油intObj油=油new油Integer(10); 5.油油油 6.油油油油//use toString method of Integer class to conver Integer into String. 7.油油油油String油str油=油intObj.toString(); 8.油油油油System.out.println("Integer油converted油to油String油as油"油+油str); 9.油油} 10.} 11.油 12./* 13.Output of the program would be 14.Integer converted to String as 10 15.*/
  • 13. Float
  • 14. Convert Java Float Object to String Object Example 1.油 2.油油public油static油void油main(String[]油args)油{ 3.油 4.油 5.油油油油Float油fObj油=油new油Float(10.25); 6.public油class油JavaFloatToStringExample油{ 7.油油油油//use toString method of Float class to convert Float into String. 8.油油油油String油str油=油fObj.toString(); 9.油油油油System.out.println("Float油converted油to油String油as油"油+油str); 10.油油} 11.} 12.油 13./* 14.Output of the program would be 15.Float converted to String as 10.25
  • 15. Byte
  • 16. Convert Byte object to String object 油 1.public油class油ByteToStringExample油{ 2.油 3.油油public油static油void油main(String[]油args)油{ 4.油油油油Byte油bObj油=油new油Byte("10"); 5.油油油 6.油油油油//use toString method of Byte class to convert Byte into String. 7.油油油油String油str油=油bObj.toString(); 8.油油油油System.out.println("Byte油converted油to油String油as油"油+油str); 9.油油} 10.} 11.油 12.Output of the program would be 13.Byte converted to String as 10
  • 17. Long
  • 18. Convert Long object to String object 1. public油class油LongToStringExample油{ 2. 油 3. 油油public油static油void油main(String[]油args)油{ 4. 油油油油Long油lObj油=油new油Long(10); 5. 油油油 6. 油油油油//use toString method of Long class to convert Long into String. 7. 油油油油String油str油=油lObj.toString(); 8. 油油油油System.out.println("Long油converted油to油String油as油"油+油str); 9. 油油} 10. } 11. 油 12. /* 13. Output of the program would be 14. Long converted to String as 10
  • 19. Short
  • 20. Convert Short object to String object 1. public油class油ShortToStringExample油{ 2. 油 3. 油油public油static油void油main(String[]油args)油{ 4. 油油油油short油s油=油10; 5. 油油油油Short油sObj油=油new油Short(s); 6. 油油油 7. 油油油油//use toString method of Short class to convert Short into String. 8. 油油油油String油str油=油sObj.toString(); 9. 油油油油System.out.println("Short油converted油to油String油as油"油+油str); 10. 油油} 11. } 12. 油 13. /* 14. Output of the program would be 15. Short converted to String as 10 16. */