Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:01,236 --> 00:00:02,069
Alrighty, so let's go ahead
1
2
00:00:02,069 --> 00:00:03,358
and pick up where we left off.
2
3
00:00:03,358 --> 00:00:06,113
So, the previous video we simply retrieved those beans
3
4
00:00:06,113 --> 00:00:08,838
from a container for theCoach and alphaCoach,
4
5
00:00:08,838 --> 00:00:11,851
now let's go ahead and just do some more work here.
5
6
00:00:11,851 --> 00:00:14,308
So, the first thing I wanna do is check
6
7
00:00:14,308 --> 00:00:16,979
to see if these are the same beans.
7
8
00:00:16,979 --> 00:00:20,869
So, I'll simply set up a boolean variable result
8
9
00:00:20,869 --> 00:00:23,058
and I will actually compare these two.
9
10
00:00:23,058 --> 00:00:25,140
I'll compare their object references.
10
11
00:00:25,140 --> 00:00:28,497
So, I'll say theCoach equals equal alphaCoach
11
12
00:00:28,497 --> 00:00:29,712
and I'll put that in parens
12
13
00:00:29,712 --> 00:00:31,324
just to show you that I'm comparing
13
14
00:00:31,324 --> 00:00:33,674
these two items, I'm comparing our object reference
14
15
00:00:33,674 --> 00:00:36,766
to see if they are pointing to the same area of memory
15
16
00:00:36,766 --> 00:00:39,611
or if they're pointing to the same object.
16
17
00:00:39,611 --> 00:00:40,444
That's what we're doing here
17
18
00:00:40,444 --> 00:00:43,111
with this boolean result equals.
18
19
00:00:44,056 --> 00:00:48,162
Now let's go ahead and display the results here
19
20
00:00:48,162 --> 00:00:49,070
and so we can see, you know,
20
21
00:00:49,070 --> 00:00:50,121
exactly what's going on.
21
22
00:00:50,121 --> 00:00:53,797
So, let me set up my quick comment here
22
23
00:00:53,797 --> 00:00:55,086
to print out the results
23
24
00:00:55,086 --> 00:00:58,391
and I'll use my sysop print line
24
25
00:00:58,391 --> 00:01:00,144
and then inside of here
25
26
00:01:00,144 --> 00:01:03,894
I'll actually say pointing to the same object
26
27
00:01:05,194 --> 00:01:07,623
and then plus result
27
28
00:01:07,623 --> 00:01:09,648
and I put a backslash in at the beginning
28
29
00:01:09,648 --> 00:01:11,707
of that stream just to give me a character turn
29
30
00:01:11,707 --> 00:01:13,101
just so I can have some extra white space
30
31
00:01:13,101 --> 00:01:16,670
when I'm looking at the results here of my run.
31
32
00:01:16,670 --> 00:01:18,613
Alright, so that's the first one here.
32
33
00:01:18,613 --> 00:01:21,551
And then I also wanna actually print out
33
34
00:01:21,551 --> 00:01:25,048
the memory location for each one of these.
34
35
00:01:25,048 --> 00:01:28,798
So, I'll say the memory location for theCoach
35
36
00:01:33,895 --> 00:01:36,514
and then I'm just doing a plus theCoach
36
37
00:01:36,514 --> 00:01:37,928
and so by default,
37
38
00:01:37,928 --> 00:01:40,464
the default version of this display here,
38
39
00:01:40,464 --> 00:01:42,650
it'll call the two string method of this object,
39
40
00:01:42,650 --> 00:01:44,889
and the default implementation of the two strings,
40
41
00:01:44,889 --> 00:01:46,852
it'll simply be the class name
41
42
00:01:46,852 --> 00:01:49,200
and the internal memory address
42
43
00:01:49,200 --> 00:01:51,435
for that given object reference.
43
44
00:01:51,435 --> 00:01:55,996
So, I'll do a similar thing here for alphaCoach.
44
45
00:01:55,996 --> 00:01:57,080
Alright, that looks okay,
45
46
00:01:57,080 --> 00:01:58,512
and I'll add an extra character turn
46
47
00:01:58,512 --> 00:02:01,512
just to make the output look pretty.
47
48
00:02:02,773 --> 00:02:05,127
And also I'll be nice, add a Spring container
48
49
00:02:05,127 --> 00:02:07,377
and I'll close the context.
49
50
00:02:09,939 --> 00:02:10,778
Alright, so that's kind of it.
50
51
00:02:10,778 --> 00:02:13,324
So, you know, we already read in the config up top,
51
52
00:02:13,324 --> 00:02:16,114
then we retrieved the bean from the container,
52
53
00:02:16,114 --> 00:02:17,834
we moved down and we just checked the result
53
54
00:02:17,834 --> 00:02:19,178
to see if they were the same,
54
55
00:02:19,178 --> 00:02:20,381
and then we print out the result
55
56
00:02:20,381 --> 00:02:22,428
and we also print out the memory location
56
57
00:02:22,428 --> 00:02:24,761
for theCoach and alphaCoach.
57
58
00:02:27,436 --> 00:02:29,352
Oh actually, let me fix that quick typo here.
58
59
00:02:29,352 --> 00:02:33,076
So, pointing, I put a colon space right there
59
60
00:02:33,076 --> 00:02:34,710
on line 22 just to make my output
60
61
00:02:34,710 --> 00:02:36,205
look a little bit prettier.
61
62
00:02:36,205 --> 00:02:39,122
Alright, so run as Java application
62
63
00:02:40,803 --> 00:02:42,595
and good stuff here.
63
64
00:02:42,595 --> 00:02:44,761
Alright, let's check out this output.
64
65
00:02:44,761 --> 00:02:46,778
Okay, great, so first off
65
66
00:02:46,778 --> 00:02:49,084
it says, you know, loading XML bean definitions
66
67
00:02:49,084 --> 00:02:52,452
from this file, beanScope-applicationContext,
67
68
00:02:52,452 --> 00:02:54,274
so that's our new file that we just created
68
69
00:02:54,274 --> 00:02:57,045
and so we are reading that file which is good,
69
70
00:02:57,045 --> 00:03:01,203
and then here's the print out of the results
70
71
00:03:01,203 --> 00:03:04,028
pointing to the same object is true,
71
72
00:03:04,028 --> 00:03:07,685
and also we have the memory location for theCoach
72
73
00:03:07,685 --> 00:03:09,782
which is 5e85
73
74
00:03:09,782 --> 00:03:12,918
and also the memory location for alphaCoach 5e85,
74
75
00:03:12,918 --> 00:03:15,447
so basically those numbers are the same,
75
76
00:03:15,447 --> 00:03:19,392
so it's actually printing to the same area of memory
76
77
00:03:19,392 --> 00:03:20,521
for both of these objects.
77
78
00:03:20,521 --> 00:03:21,938
So, that's great.
78
79
00:03:24,069 --> 00:03:25,924
Now let's go ahead and switch this up.
79
80
00:03:25,924 --> 00:03:28,920
Let's test this with scope equals prototype.
80
81
00:03:28,920 --> 00:03:32,034
So, scope equals prototype means that it'll actually create
81
82
00:03:32,034 --> 00:03:35,155
a new object every time we request it.
82
83
00:03:35,155 --> 00:03:37,596
So, here I'll say scope equals prototype
83
84
00:03:37,596 --> 00:03:39,179
in the config file.
84
85
00:03:42,041 --> 00:03:42,914
Alright, so this looks good,
85
86
00:03:42,914 --> 00:03:43,844
so let's go equals prototype,
86
87
00:03:43,844 --> 00:03:46,997
so I'm gonna create a new object for each request.
87
88
00:03:46,997 --> 00:03:48,891
Let's go ahead and save this file
88
89
00:03:48,891 --> 00:03:50,662
and now all we need to do is go back
89
90
00:03:50,662 --> 00:03:53,338
to the bean scope demo app
90
91
00:03:53,338 --> 00:03:54,272
and then just run it.
91
92
00:03:54,272 --> 00:03:56,530
No changes here, everything here stays the same.
92
93
00:03:56,530 --> 00:03:59,447
Just right click and choose run as.
93
94
00:04:02,370 --> 00:04:05,672
Alright, so looking at the output.
94
95
00:04:05,672 --> 00:04:08,312
Okay, now, okay, reading from that config
95
96
00:04:08,312 --> 00:04:10,289
beanScope-appContext,
96
97
00:04:10,289 --> 00:04:13,188
now it says pointing to the same object is false.
97
98
00:04:13,188 --> 00:04:15,717
Whoa, yeah, 'cause it's a prototype, right?
98
99
00:04:15,717 --> 00:04:17,961
So that means that they create a new object
99
100
00:04:17,961 --> 00:04:19,931
for each reference, alright?
100
101
00:04:19,931 --> 00:04:23,289
So, theCoach has one memory address
101
102
00:04:23,289 --> 00:04:26,731
and then alphaCoach has a different memory address,
102
103
00:04:26,731 --> 00:04:29,181
so these are two separate objects,
103
104
00:04:29,181 --> 00:04:31,708
two separate areas of memory
104
105
00:04:31,708 --> 00:04:36,070
because again, right, we using the prototype scope.
105
106
00:04:36,070 --> 00:04:37,777
Alright, so nice little example here
106
107
00:04:37,777 --> 00:04:39,103
of making use of singleton scope
107
108
00:04:39,103 --> 00:04:40,606
and prototype scope
108
109
00:04:40,606 --> 00:04:42,062
and here you're able to see the output,
109
110
00:04:42,062 --> 00:04:43,672
see the results and so on.
110
111
00:04:43,672 --> 00:04:47,894
So, you should feel very comfortable now with bean scopes.
111
112
00:04:47,894 --> 00:04:49,928
So again, the default is singleton
112
113
00:04:49,928 --> 00:04:51,502
and it's only one instance
113
114
00:04:51,502 --> 00:04:54,175
and then you can also specify prototype scope
114
115
00:04:54,175 --> 00:04:56,830
which will create a new one for each request.
115
116
00:04:56,830 --> 00:04:58,088
Alright, you're ready,
116
117
00:04:58,088 --> 00:05:00,663
you're ready for a Spring job interview.
117
118
00:05:00,663 --> 00:05:02,257
Alright, cool, good stuff.
118
119
00:05:02,257 --> 00:05:05,007
So, I'll see you the next video.
9557
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.