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