Java Essentials - Wrapper classes in java
11K views
Oct 24, 2024
Java Essentials - Wrapper classes in java
View Video Transcript
0:00
In this video we are discussing wrapper classes in Java
0:05
Now what is a wrapper class? So sometimes we want to convert the primitive data type, let it be I&T, car, long, double
0:13
So these are the primitive data types. So whenever you are converting this primitive data types to the class or the class to the
0:20
primitive data types, then we are using this wrapper classes in our Java
0:25
So whenever primitive data types will be converted to the respective classes, it is known as
0:29
boxing and whenever the classes will be converted to the respective primitive data types
0:35
it will be known as unboxing. So let us go for further discussion on this topic
0:41
So what are the wrapper classes? Rapper classes in Java is a mechanism that can convert
0:47
primitive data types to the objects and objects to the primitive data types. That means we are
0:54
converting the primitive data types, let it be I-N-T, let it be C-H-A-R, let it be float, FLO
0:59
OAT so there is a primitive data type to the respective objects and from objects to
1:04
the primitive data types so both sides of convert conversions can take place in
1:09
case of wrapper classes the wrapper classes are like the integer you see the i is capital for I INT is a primitive data type character C capital for Carr so car is a primitive
1:22
data type. Long, you can find that L is capital for long, here L is in the lower case
1:28
there is a primitive data type, etc. When a primitive data type is converted to the wrapper class
1:34
object, then it is known as boxing, and when the wrapper class object, and when the wrapper class object
1:39
is converted to the primitive data type it is known as unboxing so boxing and
1:45
unboxing these two terms are very important and related to the wrapper class
1:49
operations so there are some basic functions are there in the wrapper classes
1:54
so let me discuss something on them so xxx value so here we have written this
2:00
xxx actually it will get replaced by so either i nt or say c hr card or say f l
2:07
a t float so float value i nt value car value in this way so that's why in a generic way we have written xxx value
2:14
function so these functions are used to get the values from the wrapper class
2:19
objects the xxx will be replaced by either i t or float or car etc next we having the two string so that means it is used to convert a variable value like integer or float to a string so in that was it is for the conversion to the string
2:37
in this case in case we that another function is there there is a parse xxx you can find that
2:43
this x is capital and are written in the lower case later so pars xxx function so parse i nt
2:51
parse float so these are used to convert a string input to a primitive type like
2:57
your I and T or float etc then we're having there are some other functions in
3:02
the wrapper classes which will be discussed in the demonstration which is
3:06
following next please watch the demonstration they will be discussing our concept on this wrapper class using a Java code in this demonstration we shall
3:16
discuss on the wrapper class within the class that is a wrapper class here we have
3:21
defining one variable within the main function that is the i nt val is equal to 10 that
3:27
means this val is one integer variable i nt res so we have defined one another integer
3:34
variable r s res and which is uninitialized now this particular val has been
3:39
passed as the input argument to the integer constructor and integer here is nothing but one wrapper class so creating one integer type object using INT so integer integer integer is equal to new integer
3:53
value you can find that this value has been passed as the input argument to the
3:58
constructor integer and it is actually helping it to define one object under the wrapper
4:05
class integer here so race is equal to integer dot in in value that means here this the value which is there within this integer
4:15
integer wrapper class object will be assigned to this race and rest is going to get
4:20
printed so val was having the value ten and this particular val has been
4:25
wrapped within this wrapper class object that is the integer and from this
4:29
integer we are trying to get the value now so the respective method is I in it
4:34
value so respective method is in it value and that is returning the respective
4:39
value there which is getting assigned onto the integer variable RES and RAS is
4:44
getting printed so let me go for the execution you can find that the the value
4:49
of RAS is 10 here so it has got printed up to this level next integer my
4:55
I and t is equal to 50 that means automatically it is converting
#Java (Programming Language)