1 00:00:00,000 --> 00:00:04,732 [MUSIC] 2 00:00:04,732 --> 00:00:05,980 Hello and welcome back. 3 00:00:05,980 --> 00:00:07,620 I'm Craig and I'm a developer. 4 00:00:07,620 --> 00:00:11,480 This course is going to build on top of what we learned together in Java basics. 5 00:00:11,480 --> 00:00:12,580 If you haven't checked it out yet, 6 00:00:12,580 --> 00:00:14,870 I recommend that you follow the link in the teacher's notes. 7 00:00:14,870 --> 00:00:15,720 It's a prerequisite for 8 00:00:15,720 --> 00:00:19,730 this course but you don't need to have any other programming experience. 9 00:00:19,730 --> 00:00:22,330 And what we're going to learn in this course is relevant to many other 10 00:00:22,330 --> 00:00:24,330 programming languages that you're going to encounter. 11 00:00:25,340 --> 00:00:27,610 Don't forget that they're speaking trolls in the video player. 12 00:00:27,610 --> 00:00:30,910 Feel free to speed me up or slow me down to your heart's content. 13 00:00:30,910 --> 00:00:32,545 I won't mind at all. 14 00:00:32,545 --> 00:00:35,726 In this course, we are going to be talking about objects. 15 00:00:35,726 --> 00:00:38,529 Java is an object oriented programming language and 16 00:00:38,529 --> 00:00:41,470 literally everything in Java is an object. 17 00:00:41,470 --> 00:00:44,290 Well, except for the primitive types like ants and boolean. 18 00:00:44,290 --> 00:00:48,710 But even those have wrapper types which are, objects. 19 00:00:48,710 --> 00:00:51,360 So as you can imagine, understanding objects 20 00:00:51,360 --> 00:00:55,470 is super critical to your foundational base of the Java language. 21 00:00:55,470 --> 00:00:57,800 And I'm excited to explore them with you. 22 00:00:57,800 --> 00:01:01,230 So first, we'll familiarize ourselves with the basics of objects. 23 00:01:01,230 --> 00:01:02,790 How to use them, how to create them, and 24 00:01:02,790 --> 00:01:07,070 then after we get a good grasp, we'll build an application using that. 25 00:01:07,070 --> 00:01:09,940 The app that we're going to build is a console based version of the popular 26 00:01:09,940 --> 00:01:11,540 game, Hangman. 27 00:01:11,540 --> 00:01:14,790 Along the way will be expanding our Java toolset again learning new tricks 28 00:01:14,790 --> 00:01:15,420 as we need them. 29 00:01:16,540 --> 00:01:20,810 Just like we talked about in Java basics, there are gonna be a lot of new terms. 30 00:01:20,810 --> 00:01:24,340 And remember you should feel like you need to understand everything fully. 31 00:01:24,340 --> 00:01:27,300 Immerse yourself in the language and I will cover in detail 32 00:01:27,300 --> 00:01:30,880 what I believe you need to know at this point of time in your learning. 33 00:01:30,880 --> 00:01:33,230 We are going to be using work spaces again for this course. 34 00:01:33,230 --> 00:01:35,960 So you can follow along in code without having to install 35 00:01:35,960 --> 00:01:38,000 anything at all in your local machine. 36 00:01:38,000 --> 00:01:41,170 We're also going to be making use of a tool that might be new to you. 37 00:01:41,170 --> 00:01:44,964 It's called JShell, and it's the new REPL that Java just got in Java 9. 38 00:01:46,090 --> 00:01:50,120 In case you haven't heard of the term REPL, or R-E-P-L, it stands for 39 00:01:50,120 --> 00:01:54,990 Read-Eval-Print-Loop, and it allows you to interact with and explore the language. 40 00:01:54,990 --> 00:01:56,100 I think you're gonna to love it. 41 00:01:56,100 --> 00:01:58,370 Let's launch a workspace and check it out. 42 00:01:58,370 --> 00:02:00,420 Okay, so welcome back to workspaces. 43 00:02:00,420 --> 00:02:05,060 So down here in the console, if you just go ahead and type JShell. 44 00:02:05,060 --> 00:02:08,200 It's going to start up, it's going to start the REPL up. 45 00:02:08,200 --> 00:02:11,320 So again that's read a vowel print loop, check the teacher's notes for 46 00:02:11,320 --> 00:02:12,140 more on jshell. 47 00:02:12,140 --> 00:02:13,680 It's super powerful and it's up and 48 00:02:13,680 --> 00:02:16,970 coming and let's use it right now it's just refresh ourselves and 49 00:02:16,970 --> 00:02:21,200 what we've learned so far, it's an awesome tool you're going to love it. 50 00:02:21,200 --> 00:02:24,730 So what this will let us do it'll let us create variables just like we know. 51 00:02:24,730 --> 00:02:27,310 So we'll do string first name equals Craig. 52 00:02:28,680 --> 00:02:31,780 And you'll see what it does there is it says that it set the variable 53 00:02:31,780 --> 00:02:32,540 name to Craig. 54 00:02:32,540 --> 00:02:34,800 It's kind of that's its style of output there. 55 00:02:34,800 --> 00:02:37,800 So now we can access those variables like so. 56 00:02:37,800 --> 00:02:41,070 So we'll say isCraig and let's see. 57 00:02:41,070 --> 00:02:46,580 Let's do this firstName., to call the method, equals("Craig") right? 58 00:02:46,580 --> 00:02:50,750 So remember that we we call the equals method on strings to check equality. 59 00:02:50,750 --> 00:02:54,220 They're look at stored in the variable now there's a variable called is Craig and 60 00:02:54,220 --> 00:02:56,170 you'll notice that I accessed first name. 61 00:02:56,170 --> 00:03:00,220 So it's kind of in the scope of this this shell that we're working in here you 62 00:03:00,220 --> 00:03:04,575 can also just go ahead and say firstName.equals("Bob). 63 00:03:06,640 --> 00:03:09,120 And what that did is it created a new variable. 64 00:03:09,120 --> 00:03:13,510 Now there's a variable called $3 you can say it is dollar three equal true and 65 00:03:13,510 --> 00:03:14,570 it doesn't rank as we know. 66 00:03:14,570 --> 00:03:19,080 So dollar three is a new variable name and now I made a dollar four called false. 67 00:03:19,080 --> 00:03:21,290 So I just automatically creates these variables and 68 00:03:21,290 --> 00:03:23,460 it starts with a dollar sign in the front. 69 00:03:23,460 --> 00:03:25,410 It kinda just stores whatever is returned right. 70 00:03:25,410 --> 00:03:29,520 So if I do first name equals ignore case remember that that was the one that 71 00:03:29,520 --> 00:03:33,680 allowed us to check no matter if it was upper case or lower case so 72 00:03:33,680 --> 00:03:35,530 if I say equals ignore the case. 73 00:03:35,530 --> 00:03:38,900 Craig it's going to create a new there's dollar five it's untrue just going to 74 00:03:38,900 --> 00:03:40,010 stores whatever is there. 75 00:03:40,010 --> 00:03:44,280 So if you want to refresh your screen you can do a Ctrl + L. 76 00:03:44,280 --> 00:03:48,390 And it will bring everything up to the top there we go. 77 00:03:48,390 --> 00:03:51,760 So if you did the extra credit on Java Basics where we tried to validate input 78 00:03:51,760 --> 00:03:56,010 you learned about the contains into lower case methods that exist on street, 79 00:03:56,010 --> 00:03:57,390 let's take a look at them real quick. 80 00:03:57,390 --> 00:04:01,002 So let's make a new string, let's say String someWords 81 00:04:01,002 --> 00:04:05,050 equalas"This is a bunch of WORDS". 82 00:04:06,830 --> 00:04:07,520 All right. 83 00:04:07,520 --> 00:04:10,250 So we now have a variable called somewhere and so if I start typing. 84 00:04:10,250 --> 00:04:13,800 So in and I press tab it's gonna look and it will search and 85 00:04:13,800 --> 00:04:17,530 it will find that I have some words there so automatically did that and 86 00:04:17,530 --> 00:04:22,100 it works for methods two so I did contains a tab and it was over. 87 00:04:22,100 --> 00:04:27,940 So contains looks for A, the word, bunch there inside of some words. 88 00:04:29,090 --> 00:04:29,720 Does it exist? 89 00:04:29,720 --> 00:04:30,360 It sure does. 90 00:04:30,360 --> 00:04:32,410 There it is, all right. 91 00:04:32,410 --> 00:04:36,210 And if I press the up arrow, things will come back. 92 00:04:36,210 --> 00:04:39,520 So then, I can use the backspace there and say does it contain this, 93 00:04:39,520 --> 00:04:40,320 which it does, right. 94 00:04:40,320 --> 00:04:43,050 There's this, so there's true. 95 00:04:43,050 --> 00:04:49,270 And also, if I come and do, let's see if it has words in there. 96 00:04:49,270 --> 00:04:51,720 So this is case sensitive. 97 00:04:51,720 --> 00:04:54,610 So it doesn't contain words even though it is actually there. 98 00:04:54,610 --> 00:04:58,533 So we could create a new variable, right. 99 00:04:58,533 --> 00:05:03,353 We could say string loweredWords equals some Words and 100 00:05:03,353 --> 00:05:06,860 remember this is toLowerCase. 101 00:05:06,860 --> 00:05:08,500 Yep. And when there's multiple options, 102 00:05:08,500 --> 00:05:09,420 there so it's gonna show us. 103 00:05:09,420 --> 00:05:15,854 So toLowerCase is we want, so loweredWords we could then check if loweredWords, 104 00:05:17,516 --> 00:05:22,960 Contains words and indeed it does. 105 00:05:22,960 --> 00:05:26,170 But what if we did the method chaining, 106 00:05:26,170 --> 00:05:29,390 remember this we could say someWords.toLowerCase and 107 00:05:29,390 --> 00:05:33,030 instead of strong that variable, we can just access it right here. 108 00:05:33,030 --> 00:05:33,960 It's called method change. 109 00:05:33,960 --> 00:05:35,681 Remember, we don't even need to create it. 110 00:05:38,536 --> 00:05:41,760 Cool, all right, so, we also did some work with integers or 111 00:05:41,760 --> 00:05:44,050 whole numbers which were like this right. 112 00:05:44,050 --> 00:05:47,660 So if we say int ageOfBob = 30. 113 00:05:47,660 --> 00:05:52,700 And let's say that Mary. 114 00:05:53,770 --> 00:05:55,700 She's 28. 115 00:05:55,700 --> 00:05:58,557 And we could check and see, 116 00:05:58,557 --> 00:06:04,024 I'm going to put parentheses around these, just so 117 00:06:04,024 --> 00:06:08,885 if Bob is older or greater than the age of Mary. 118 00:06:11,522 --> 00:06:20,200 And then again to parenthesis age of Bob is less than the age of Mary. 119 00:06:20,200 --> 00:06:23,290 So we talk about numbers are greater than or less then. 120 00:06:23,290 --> 00:06:29,190 And finally let's go ahead and remember that when you get 121 00:06:29,190 --> 00:06:34,430 a number in maybe you get a number from a programs coming in you can purse it. 122 00:06:34,430 --> 00:06:37,180 So let's say that somebody passed in the string 30, 123 00:06:37,180 --> 00:06:40,050 you can get the number out with that. 124 00:06:40,050 --> 00:06:40,875 There you go. 125 00:06:40,875 --> 00:06:44,625 And finally, let's remember about Booleans. 126 00:06:44,625 --> 00:06:50,465 So using conditional logic like and or ors and those look like this in Java. 127 00:06:50,465 --> 00:06:53,185 So you say or with a with a double pipe. 128 00:06:53,185 --> 00:06:56,905 So if we had say false or false, that's definitely going to be false, but 129 00:06:56,905 --> 00:06:57,715 what if we put a true here? 130 00:06:57,715 --> 00:06:58,935 Do you remember what happens? 131 00:06:58,935 --> 00:07:04,320 So the way that it works is if any of these are true, it means that it's true. 132 00:07:04,320 --> 00:07:08,290 And this is the case and or is so it's like is this true or is this true or 133 00:07:08,290 --> 00:07:12,250 is this true and it is so there's that and then if we flip that around again. 134 00:07:12,250 --> 00:07:13,730 I use the up arrow and 135 00:07:13,730 --> 00:07:16,460 I'm going to move these to be ampersands remember how this works. 136 00:07:17,830 --> 00:07:20,390 This is basically saying, are all of these true. 137 00:07:20,390 --> 00:07:23,480 So is false and false and true. 138 00:07:23,480 --> 00:07:25,100 So it's not, it's not true. 139 00:07:25,100 --> 00:07:27,830 And actually, what's gonna happen is it's gonna shortcut the second that it 140 00:07:27,830 --> 00:07:28,760 finds one that's false. 141 00:07:28,760 --> 00:07:30,710 It's not even going to need to look at the rest of them. 142 00:07:30,710 --> 00:07:31,440 So and again, 143 00:07:31,440 --> 00:07:34,950 those could of course be expressions like the age of Bob an age of many thing. 144 00:07:34,950 --> 00:07:39,010 Feel free to play around here until you feel refresh what we covered. 145 00:07:39,010 --> 00:07:41,590 We'll spend quite a bit of time in here during this course and I'll show you 146 00:07:41,590 --> 00:07:45,180 a couple more cool things that this awesome tool can do in upcoming videos. 147 00:07:45,180 --> 00:07:49,250 Now to get out of here you press Ctrl + D. 148 00:07:49,250 --> 00:07:50,850 Cool and then you can do clear and clear the screen. 149 00:07:52,230 --> 00:07:53,700 Awesome, I feel refreshed. 150 00:07:53,700 --> 00:07:56,910 That REPL is going to be super handy going forward, right. 151 00:07:56,910 --> 00:08:00,410 Now before we get started, I just wanna remind you that during your learnings here 152 00:08:00,410 --> 00:08:01,980 if anything at all isn't clear. 153 00:08:01,980 --> 00:08:05,170 Or even if you're pondering something, head over to the community and 154 00:08:05,170 --> 00:08:06,820 share your question with everyone. 155 00:08:06,820 --> 00:08:07,810 By sharing your question, 156 00:08:07,810 --> 00:08:11,650 it allows everyone to learn and if someone else is wondering that very same thing. 157 00:08:11,650 --> 00:08:13,700 It'll be an answer when they come to search for it. 158 00:08:13,700 --> 00:08:17,530 I can't stress this enough, the community is awesome and supportive and 159 00:08:17,530 --> 00:08:20,270 I've been blown away by how quick answers appear. 160 00:08:20,270 --> 00:08:21,290 I can't even keep up. 161 00:08:21,290 --> 00:08:22,920 You all are so great. 162 00:08:22,920 --> 00:08:25,630 All right, I think we're ready to dive into objects 163 00:08:25,630 --> 00:08:26,783 right after you ace this refresh course.