All language subtitles for 11. Injecting Literal Values - Write Some Code

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese Download
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 1 00:00:01,027 --> 00:00:03,049 All right, so let's dive into Eclipse. 2 2 00:00:03,049 --> 00:00:04,927 Let's go ahead and write some code. 3 3 00:00:04,927 --> 00:00:07,195 Again, looking at our development process, 4 4 00:00:07,195 --> 00:00:10,538 the first step we need to do is create the setter methods 5 5 00:00:10,538 --> 00:00:12,871 in the class for injections. 6 6 00:00:16,652 --> 00:00:18,483 All right, so let's go ahead and open up the file here 7 7 00:00:18,483 --> 00:00:20,316 for our Cricket Coach. 8 8 00:00:22,590 --> 00:00:25,182 Expand the window here. 9 9 00:00:25,182 --> 00:00:27,460 line:15% Again, remember the first thing we really need to do is 10 10 00:00:27,460 --> 00:00:29,286 line:15% set up these private fields here 11 11 00:00:29,286 --> 00:00:31,273 line:15% for emailAddress and team. 12 12 00:00:31,273 --> 00:00:35,273 line:15% I'll just write a quick comment here for myself, 13 13 00:00:36,992 --> 00:00:41,622 line:15% and then I'll go ahead and answer these private fields here, 14 14 00:00:41,622 --> 00:00:45,205 so I have this private String emailAddress, 15 15 00:00:46,121 --> 00:00:49,118 and then I have a private String team. 16 16 00:00:49,118 --> 00:00:50,743 These are just the fields that we're gonna use 17 17 00:00:50,743 --> 00:00:52,262 to actually assign the data 18 18 00:00:52,262 --> 00:00:54,514 once it's injected to our application, 19 19 00:00:54,514 --> 00:00:56,087 but that's basically what we have here. 20 20 00:00:56,087 --> 00:00:58,587 This looks pretty good so far. 21 21 00:01:01,630 --> 00:01:03,900 line:15% Now, the next thing I need to do is actually generate 22 22 00:01:03,900 --> 00:01:06,545 line:15% or create the setter methods here in our class 23 23 00:01:06,545 --> 00:01:08,031 for injections 24 24 00:01:08,031 --> 00:01:09,385 so I'll actually make use of Eclipse 25 25 00:01:09,385 --> 00:01:11,795 to generate this for me. 26 26 00:01:11,795 --> 00:01:12,909 Here I'll do a right-click, 27 27 00:01:12,909 --> 00:01:14,027 I choose Source, 28 28 00:01:14,027 --> 00:01:17,527 and I choose Generate Getters and Setters. 29 29 00:01:20,709 --> 00:01:22,107 Here in this dialogue, 30 30 00:01:22,107 --> 00:01:23,896 you tell Eclipse what you want, 31 31 00:01:23,896 --> 00:01:26,660 so we'll check the box here for emailAddress and for team. 32 32 00:01:26,660 --> 00:01:28,054 Then we can expand it, 33 33 00:01:28,054 --> 00:01:29,626 and we can see that Eclipse will create 34 34 00:01:29,626 --> 00:01:33,021 the getter and setter methods for each one of these fields. 35 35 00:01:33,021 --> 00:01:34,688 Now, you don't really need the getter methods. 36 36 00:01:34,688 --> 00:01:36,398 You only need the setters, 37 37 00:01:36,398 --> 00:01:37,716 but I'll go ahead and use both of them 38 38 00:01:37,716 --> 00:01:39,873 because we'll actually wanna print out the values 39 39 00:01:39,873 --> 00:01:42,234 in our little test program. 40 40 00:01:42,234 --> 00:01:44,620 All right, so here we go. We have this all set up. 41 41 00:01:44,620 --> 00:01:46,565 We have our methods here 42 42 00:01:46,565 --> 00:01:49,242 for getEmailAddress and setEmailAddress, 43 43 00:01:49,242 --> 00:01:50,828 and getTeam and setTeam. 44 44 00:01:50,828 --> 00:01:53,612 These are of course generated by Eclipse, 45 45 00:01:53,612 --> 00:01:55,362 so thank you Eclipse! 46 46 00:01:57,649 --> 00:01:59,641 All righty, now what I'd like to do is add 47 47 00:01:59,641 --> 00:02:01,831 some little diagnostic methods here, 48 48 00:02:01,831 --> 00:02:05,072 or diagnostic messages here in our setters, 49 49 00:02:05,072 --> 00:02:07,592 so I'm just gonna copy line 36 50 50 00:02:07,592 --> 00:02:10,824 that we had from our setFortuneService method. 51 51 00:02:10,824 --> 00:02:12,343 I'll just copy that line. 52 52 00:02:12,343 --> 00:02:13,750 Right-click, choose Copy 53 53 00:02:13,750 --> 00:02:16,112 or you can use the keyboard if you'd like. 54 54 00:02:16,112 --> 00:02:20,386 Then I'll just move up to this setter for emailAddress, 55 55 00:02:20,386 --> 00:02:23,053 and I'll just paste it in there. 56 56 00:02:25,560 --> 00:02:28,144 All right, and I need to simply just update the description, 57 57 00:02:28,144 --> 00:02:31,888 so I just copy emailAddress and then put it there. 58 58 00:02:31,888 --> 00:02:34,221 I just wanna make sure that this message is correct, 59 59 00:02:34,221 --> 00:02:36,456 so it says, "CricketCoach: 60 60 00:02:36,456 --> 00:02:39,918 "inside setter method for setEmailAddress". 61 61 00:02:39,918 --> 00:02:41,099 Okay, good. So this is good. 62 62 00:02:41,099 --> 00:02:43,805 Now, let's just go ahead and copy/paste this line 63 63 00:02:43,805 --> 00:02:47,203 and do a similar thing here for when we set the team 64 64 00:02:47,203 --> 00:02:50,482 because again, I'm adding these little messages here 65 65 00:02:50,482 --> 00:02:53,892 just so I can see how Spring is working behind the scenes 66 66 00:02:53,892 --> 00:02:56,838 when they call these appropriate methods. 67 67 00:02:56,838 --> 00:03:00,260 I just added a setter method here, or a message, 68 68 00:03:00,260 --> 00:03:01,233 for setTeam. 69 69 00:03:01,233 --> 00:03:02,987 Mainly just diagnostics for us, 70 70 00:03:02,987 --> 00:03:06,404 you know, mainly a training purpose here. 71 71 00:03:11,628 --> 00:03:12,827 All right, so I just highlighted. 72 72 00:03:12,827 --> 00:03:14,934 These are the methods that we have here. 73 73 00:03:14,934 --> 00:03:17,056 Primarily, Spring's, they would call the setter methods 74 74 00:03:17,056 --> 00:03:20,261 when they inject those values into your class. 75 75 00:03:20,261 --> 00:03:23,565 We have the getter methods just so we can display them later 76 76 00:03:23,565 --> 00:03:25,950 in one of our test programs. 77 77 00:03:25,950 --> 00:03:27,714 line:15% All right, so this looks good. 78 78 00:03:27,714 --> 00:03:31,204 line:15% Now, let's go ahead and move over to step two. 79 79 00:03:31,204 --> 00:03:34,252 line:15% In step two, basically we need to configure the injection 80 80 00:03:34,252 --> 00:03:36,807 line:15% in our Spring configuration file. 81 81 00:03:36,807 --> 00:03:40,187 line:15% Again, I'm moving down here to this myCricketCoach 82 82 00:03:40,187 --> 00:03:43,422 line:15% that we already have from the previous videos 83 83 00:03:43,422 --> 00:03:45,990 line:15% where we injected the fortuneService. 84 84 00:03:45,990 --> 00:03:49,750 line:15% Now, I'm gonna inject those other two values here 85 85 00:03:49,750 --> 00:03:51,964 for the property emailAddress 86 86 00:03:51,964 --> 00:03:54,214 and also the property team. 87 87 00:03:59,606 --> 00:04:02,762 All right, so here I give a property name=, 88 88 00:04:02,762 --> 00:04:07,045 and I give the actual property, so it's "emailAddress". 89 89 00:04:07,045 --> 00:04:10,161 Make sure you spell it correct and use the correct case. 90 90 00:04:10,161 --> 00:04:12,210 Then value=, 91 91 00:04:12,210 --> 00:04:13,543 and note here we give value, 92 92 00:04:13,543 --> 00:04:15,937 so that's the actual value that we're placing here. 93 93 00:04:15,937 --> 00:04:17,442 Not ref, but it's a value. 94 94 00:04:17,442 --> 00:04:19,057 It's a literal value. 95 95 00:04:19,057 --> 00:04:22,307 We'll say, "thebestcoach@luv2code.com", 96 96 00:04:23,493 --> 00:04:25,589 so that takes care of emailAddress. 97 97 00:04:25,589 --> 00:04:29,396 Now, let's repeat the process here for property of team, 98 98 00:04:29,396 --> 00:04:31,063 so name="team". 99 99 00:04:36,255 --> 00:04:38,505 The value="Sunrisers". 100 100 00:04:42,085 --> 00:04:43,279 That looks pretty good. 101 101 00:04:43,279 --> 00:04:45,697 Now, remember here when we make use of these properties, 102 102 00:04:45,697 --> 00:04:47,433 they're gonna call the appropriate setter method, 103 103 00:04:47,433 --> 00:04:49,601 so since we have property name emailAddress, 104 104 00:04:49,601 --> 00:04:51,634 Spring's gonna call setEmailAddress 105 105 00:04:51,634 --> 00:04:53,697 and also property name="team", 106 106 00:04:53,697 --> 00:04:55,535 Spring will call setTeam 107 107 00:04:55,535 --> 00:04:56,916 and it'll pass in those values, 108 108 00:04:56,916 --> 00:04:59,240 or inject those values. 109 109 00:04:59,240 --> 00:05:00,613 All right, so this looks pretty good. 110 110 00:05:00,613 --> 00:05:04,912 line:15% Let's go ahead and update our demo application, 111 111 00:05:04,912 --> 00:05:08,245 line:15% so I'm gonna open up SetterDemoApp.java. 112 112 00:05:11,386 --> 00:05:12,758 line:15% Then I'll just move down to the bottom. 113 113 00:05:12,758 --> 00:05:13,991 line:15% This is what we had from before 114 114 00:05:13,991 --> 00:05:16,135 line:15% in some of the previous videos. 115 115 00:05:16,135 --> 00:05:17,463 What I wanna do now is call 116 116 00:05:17,463 --> 00:05:19,701 some of those new methods that we have 117 117 00:05:19,701 --> 00:05:21,706 just to see those new values 118 118 00:05:21,706 --> 00:05:25,123 that we injected into the item cell here. 119 119 00:05:29,270 --> 00:05:31,224 We'll just simply do a System.out.println, 120 120 00:05:31,224 --> 00:05:33,355 and we'll print out the coach's email address, 121 121 00:05:33,355 --> 00:05:35,522 so we say getEmailAddress. 122 122 00:05:37,276 --> 00:05:40,041 Then we do a similar thing here for team 123 123 00:05:40,041 --> 00:05:42,717 so we can print out the actual team name. 124 124 00:05:42,717 --> 00:05:46,384 Sysout.out.println(theCoach 125 125 00:05:47,765 --> 00:05:50,583 .getTeam). There we go, cool. 126 126 00:05:50,583 --> 00:05:51,730 All right, so this is it. 127 127 00:05:51,730 --> 00:05:53,703 That's basically our demo app. 128 128 00:05:53,703 --> 00:05:56,958 It's making a call to those methods 129 129 00:05:56,958 --> 00:06:00,127 and all of these values were injected already 130 130 00:06:00,127 --> 00:06:01,954 by Spring behind the scenes, 131 131 00:06:01,954 --> 00:06:05,274 so everything should just work out as desired. 132 132 00:06:05,274 --> 00:06:07,746 Let's go ahead and save this. 133 133 00:06:07,746 --> 00:06:09,863 Let's just do a right-click and choose Run As 134 134 00:06:09,863 --> 00:06:11,196 Job Application. 135 135 00:06:16,443 --> 00:06:18,877 It's gonna bean and up in the Console, and oh, wow! 136 136 00:06:18,877 --> 00:06:21,654 A lot of good stuff here, let's check this out. 137 137 00:06:21,654 --> 00:06:24,933 It's reading information from the config file, 138 138 00:06:24,933 --> 00:06:27,316 it's calling that no-arg constructor, 139 139 00:06:27,316 --> 00:06:28,974 and then it goes through and it's 140 140 00:06:28,974 --> 00:06:30,736 making calls to those setter methods. 141 141 00:06:30,736 --> 00:06:32,219 These are the little 142 142 00:06:32,219 --> 00:06:35,450 diagnostic messages that we added to our code. 143 143 00:06:35,450 --> 00:06:36,781 We're confirming that, hey, 144 144 00:06:36,781 --> 00:06:39,725 Spring is actually calling those methods there. 145 145 00:06:39,725 --> 00:06:42,948 This is some of our previous stuff of fast bowling and so on 146 146 00:06:42,948 --> 00:06:44,678 but now, the new part here is 147 147 00:06:44,678 --> 00:06:47,031 the actual coach's email address 148 148 00:06:47,031 --> 00:06:49,975 and their actual team name, the Sunrisers. 149 149 00:06:49,975 --> 00:06:51,307 This looks really good, 150 150 00:06:51,307 --> 00:06:53,702 so this kinda works out as desired. 151 151 00:06:53,702 --> 00:06:57,413 We're injecting literal values here into our coach object, 152 152 00:06:57,413 --> 00:06:58,413 so good job. 13151

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.