Java Presentation On Wrapper Class
Java Presentation On Wrapper Class
... }
Contents
Introduction
Summarized table
How to create wrapper class object
Points to remember
Example program
01 { ..
Introduction
< What is Wrapper Class and its purpose >
} ..
What is Wrapper classes?
➔ Representing Primitives as objects ➔ Provide utility methods for primitives.
➔ Each primitive type in Java has a ➔ Primitives are not objects -> so no method can be
corresponding wrapper class. invoked
➔ Defined in java.lang package. ➔ Wrapper class defines lot of utility methods that
➔ Wrap(encapsulate) single immutable
does common conversion jobs
primitive value.
} ..
Summarized Table
*
How to create Wrapper Class Object
{
Using Class Using valueOf()
}
constructor method
1. Using wrapper class constructor
valueOf(String s)
NOTE: this method throws a runtime exception (NumberFormatException) when string passes
inappropriate arg.
Ex: Integer.valueOf(“hundred”) //error
Cont…
{
How to get primitive values from the wrapper objects?
..
typeValue()
Primitive
} ..
How to get String object from wrapper objects?
SYNTAX:
public String toString()
} ..
{ ..
Points to
Remember
} ..
Points to remember
★ Java.lang package provides grp of classes to
represent primitives as objects-> wrapper
classes.
★ Cannot be sub-classed
★ 2 ways of constructing wrapper class
Pass string argument
Pass primitive as argument.
★ Wrapper objects are immutable.
{ ..
Example Program…
} ..
{ ..
} ..
Thanks!
CREDITS: This presentation template was created by Slidesgo, and includes
icons by Flaticon, and infographics & images by Freepik