Let's not look at box primitives if you recall we discuss them briefly while learning about switch fragments 2
not to learn more about them and see how they are useful in Java. 3
We have these eight primitive apps on each of them has an associated class called a box primitive the 4
box perimeter corresponding to an integer and you can see the rest here. 5
These boxes tomatoes are part of the job product line package. 6
So Boxborough model is simply a class and it is called as a box model as it and causes a primitive value 7
. 8
And let's see what that means. 9
As you can see from these examples each box perimeter was created by passing a corresponding primitive 10
value boot's constructor in the first example an instance is created by passing an integral. 11
Similarly in the second example a boolean that really is passed to create a boolean instance in the 12
third example. 13
We are creating a character instance when the example creates a double. 14
We can also pass a primitive as a string as shown in the first example where quantified was passed as 15
a string. 16
Not that all of them except upper class X substring as in front of the last example shows that the value 17
passed as a string must be valid in this case we are passing it as an English word under generates an 18
error at runtime abox perimeter is also referred to as a proper class as it wraps the perimeter. 19
No let's look at some uses of box primitives that are useful in converting strings to primitives. 20
Here's an example that shows how to convert a string into an int. 21
It's an extremely useful utility matter. 22
These classes also provide several useful public static views. 23
For example all numeric primitives. 24
How Markson min values. 25
And if you need to know the max Aardman value of a particular model then we can use a max underscore 26
value. 27
Aardman underscore value fill in the corresponding box perimeter box primitives. 28
Also provide several other useful utility methods for example character class has tons of methods that 29
perform boolean checks on input car perimeter. 30
One example is to check whether an input car is a letter or a digit. 31
Another interesting example is the boot binary string method from the integer on long classes. 32
It returns the binary representation of the input argument as a string. 33
You may never use it but it's just nice to know that there is such a method. 34
Next boat double and float classes have a method called ees none which remains true or false depending 35
on whether the argument passed is a non or not. 36
So basically baulks primitives provide some useful methods and fields related to each Mamadu. 37
That's their fundamental use but primitives are also useful in other contexts. 38
For example box primitives are useful in populating data structures like idlest and hash map. 39
This is because we cannot add primitives directly to such data structures. 40
Let's look at an example. 41
Here we are first creating an instance of idlest that is used to store elements like an array but it 42
need not be of fixed size. 43
Next we are adding a primitive undefined to the creator or ArrayList Partridge R5. 44
This would be a compiler error as do destructors like other list or Mr. object references so they don't 45
allow storing parameter variables are promotable it grows directly as shown in the next statement. 46
You would have to wrap the perimeter in a box Amodeo to store it in the ironist Angela 5:01 words. 47
It would be possible to add primitives credit structures like ironist and it is to be a feature called 48
arbo boxing which we will discuss next. 49
But even with this feature Behind the scenes the corresponding box model is what gets added next. 50
They are also used in genetics when defining something called parameterized types but let's not worry 51
about it for now as it will be clear when we get to generics. 52
Let's not look at few commonly used methods. 53
We will just look at methods in the integer class as other wrapper classes also have similar methods 54
Sarbox perimeter wraps up at him or do not want to extract the portmanteau out of the box Plimmer do 55
. 56
Then we can invoke the in value method. 57
That is it unwraps the box primmer to here variable i gets assigned the parameter up if. 58
Like I just mentioned other upper classes also have similar methods. 59
For example boolean class has boolean value character classes Carbajal and so on. 60
You can see that these matters are meaningfully named. 61
One example when we look at Int value are boolean value that terms end or boolean such suggest that 62
we are requesting to return the proper value as an end. 63
Or boolean primitive. 64
That's all we can remember these methods and value would return in Primitivo boolean value would return 65
a boolean perimeter. 66
You would read on a carpet Amatil unsworn next is about parsing strings that is in what would be a string 67
and you need to convert it either into a premier or a box or two. 68
One would use cases when double up in data integration software and you have to integrate data from 69
different partners. 70
This would typically involve communicating with Web services which expose data in the form of X-amount 71
objects on. 72
And you would have to parse their data using an appropriate parsing library. 73
For example if you're parsing some sort or document you may have to extract the artery which is represented 74
in an X someone aliment as shown here. 75
And this gives you would Fosset extract the Order ID using an X symbol parsing library like Jerome and 76
the extracted that ID would be in string format and you would have to convert it into an integer before 77
further processing. 78
So if you have to convert the string into a remedy and then you would use this static matter parsed 79
in once again like in the previous method in value here in in part and suggest that we are seeking an 80
end perimeter and the term parsed would always mean that we are parsing some kind of a string. 81
But to convert the string into a box primmer do you would use a static method value or Again similar 82
methods are available in other wrapper process Ghalibaf is a standard naming convention for methods 83
that create objects. 84
In this case we are creating an integer object such a method is referred to as a simple factory on the 85
naming conventions. 86
Listen we will also look at other names that can be used for such methods. 87
So value of means object creation. 88
Next if you want to convert the primitive and into a string then you would invoke the static string 89
method and pass the parameter as an argument. 90
So as a matter name suggests it simply convert something into a string. 91
We have seen how a box but a model could be created but passing a parameter to the constructor. 92
However Alternatively you can use this static value of matter. 93
So once again we are using a value of method as we are creating an object previously took string as 94
input. 95
But this time it is taking a parameter as input. 96
Not that performance wise. 97
Creating an object the other value of motard can be significantly better compared to creating it. 98
Are the constructor. 99
The reason for better performance is due to internal caching that in bigger crost us the values in the 100
range minus 128 to 127 are always. 101
There is indeed integer instances but these values are stored in memory. 102
So if we try to create an integer instance in this range using the value of method then the method would 103
simply return an instance from the cache that is it is not creating a new instance. 104
It is kind of similar to string one word string literals were getting gassed. 105
Let's quickly took all the source code of this matter just to get a free love. 106
How caching is done here. 107
OK here is the value of motard from the entire class and we are here in the group Code website and I 108
got here by googling for grep code space integer. 109
OK on the radio amateurs is taking a permit you are returning an integer instance which is a Boxborough 110
motto on the method itself is a static method. 111
So us we are checking if the input parameter is in between minus 128 and positive 137. 112
If that's the case then we are returning it pre-created embetter instance. 113
So we are not going to create a new integer instance. 114
OK so we are going to use the one from cache. 115
OK and if that's not the case. 116
If it is outside of this range then we are creating new integer instance or here. 117
Now so this is basically an R is simply an array of integer instances. 118
OK so let me just click on that or here. 119
Here is where the R is getting created. 120
So it's named as underage and it has integers India or instances and this is the size of the array over 121
here and it is being initialized within the static initializer. 122
OK this is where it is getting initialized. 123
OK so if you recall from our discussion on static initializers been needed one of the use cases was 124
we needed. 125
If we have if we cannot initialize in a single line. 126
So as you can see we need a first statement here so we have to use a static initializer for doing that 127
. 128
OK now this particular code gets in worked when the integer class is used for the very first time. 129
That's when it gets loaded into memory and that's when the static initializer block on this particular 130
statement. 131
Everything gets executed but that we will see in the JVM and another chapter. 132
While looking at clustering process. 133
OK so as you can see here we have this anti-Yoko the cache which is an array of indigo instances and 134
we are populating it here. 135
And that's about it. 136
So that's about Boxborough meadows and it is likely that you will use them quite a bit in your professional 137
life. 138
Thank you