1 00:00:00,000 --> 00:00:04,808 [MUSIC] 2 00:00:04,808 --> 00:00:05,896 Hello, and welcome back. 3 00:00:05,896 --> 00:00:07,610 I'm Craig and I'm a developer. 4 00:00:07,610 --> 00:00:11,460 This course is going to build on top of what we learned together in Java basics. 5 00:00:11,460 --> 00:00:12,583 If you haven't checked it out yet, 6 00:00:12,583 --> 00:00:14,850 I recommend that you follow the link in the teacher's notes. 7 00:00:14,850 --> 00:00:16,780 It's a prerequisite for this course, but 8 00:00:16,780 --> 00:00:19,710 you don't need to have any other programming experience. 9 00:00:19,710 --> 00:00:22,238 And what we're going to learn in this course is relevant to many other 10 00:00:22,238 --> 00:00:25,290 programming languages that you're going to encounter. 11 00:00:25,290 --> 00:00:27,590 Don't forget that there are speed controls on the video player. 12 00:00:27,590 --> 00:00:30,652 Feel free to speed me up or slow me down to your heart's contempt, 13 00:00:30,652 --> 00:00:32,630 I won't mind at all. 14 00:00:32,630 --> 00:00:35,940 In this course, we're going to be talking about objects. 15 00:00:35,940 --> 00:00:38,498 Java is an object oriented programming language, 16 00:00:38,498 --> 00:00:41,440 and literally everything in Java is an object. 17 00:00:41,440 --> 00:00:45,246 Well, except for the primitive types like int and Boolean, but 18 00:00:45,246 --> 00:00:48,690 even those have wrapper types which are objects. 19 00:00:48,690 --> 00:00:52,803 So as you can imagine, understanding objects is super critical to your 20 00:00:52,803 --> 00:00:55,450 foundational base of the Java language. 21 00:00:55,450 --> 00:00:57,760 And I'm excited to explore them with you. 22 00:00:57,760 --> 00:01:01,187 So first we'll familiarize ourselves with the basics of objects. 23 00:01:01,187 --> 00:01:04,787 How to use them, how to create them, and then after we get a good grasp, 24 00:01:04,787 --> 00:01:06,980 we'll build an application using them. 25 00:01:06,980 --> 00:01:09,393 Along the way we'll be expanding our Java toolset, again, 26 00:01:09,393 --> 00:01:10,870 learning new tricks as we need them. 27 00:01:11,980 --> 00:01:16,260 Just like we talked about in Java basics, there are gonna be a lot of new terms. 28 00:01:16,260 --> 00:01:19,780 And remember, you should feel like you need to understand everything fully. 29 00:01:19,780 --> 00:01:23,217 Immerse yourself in the language, and I will cover in detail what I believe you 30 00:01:23,217 --> 00:01:26,290 need to know at this point of time in your learning. 31 00:01:26,290 --> 00:01:28,680 We're going to be using workspaces again for this course. 32 00:01:28,680 --> 00:01:29,804 So you can follow along and 33 00:01:29,804 --> 00:01:33,440 code without having to install anything at all on your local machine. 34 00:01:33,440 --> 00:01:36,620 We're also going to be making use of a tool that might be new to you. 35 00:01:36,620 --> 00:01:41,437 It's called JShell, and it's the new REPL that Java just got in Java 9. 36 00:01:41,437 --> 00:01:45,147 In case you haven't heard of the term REPL or R-E-P-L, 37 00:01:45,147 --> 00:01:47,428 it stands for read eval print loop. 38 00:01:47,428 --> 00:01:49,931 And it allows you to interact with and explore the language, 39 00:01:49,931 --> 00:01:51,540 I think you're gonna love it. 40 00:01:51,540 --> 00:01:53,820 Let's launch a workspace and check it out. 41 00:01:53,820 --> 00:01:55,870 Okay, so welcome back to workspaces. 42 00:01:55,870 --> 00:02:00,057 So down here in the console, if you just go ahead and type jshell, 43 00:02:00,057 --> 00:02:03,650 it's going to start up, it's gonna start the REPL up. 44 00:02:03,650 --> 00:02:05,770 So again, that's read eval print loop. 45 00:02:05,770 --> 00:02:07,590 Check the teacher's notes for more on JShell. 46 00:02:07,590 --> 00:02:09,892 It's super powerful, and it's up and coming, and 47 00:02:09,892 --> 00:02:14,200 let's use it right now to just refresh ourselves on what we've learned so far. 48 00:02:14,200 --> 00:02:16,310 It's an awesome tool, you're gonna love it. 49 00:02:16,310 --> 00:02:20,170 So what this will let us do, is it'll let us create variables just like we know. 50 00:02:20,170 --> 00:02:24,269 So we'll do a string, firstName = "Craig". 51 00:02:24,269 --> 00:02:27,441 And you'll see what it does there, is it says that it's set the variable 52 00:02:27,441 --> 00:02:30,250 name to Craig, it's kind of that's its style of output there. 53 00:02:30,250 --> 00:02:33,210 So now we can access those variables like so. 54 00:02:33,210 --> 00:02:37,936 So we'll say, isCraig, and let's do this firstName.to 55 00:02:37,936 --> 00:02:42,010 call the method, equals("Craig"), right? 56 00:02:42,010 --> 00:02:46,183 So remember that, we call the equals method on strings to check equality, and 57 00:02:46,183 --> 00:02:48,180 then it's stored in the variable. 58 00:02:48,180 --> 00:02:51,620 Now there's a variable called isCraig, and you'll notice that I accessed firstName. 59 00:02:51,620 --> 00:02:54,389 So it's kinda in the scope of this shell that we're working on here, 60 00:02:54,389 --> 00:02:55,630 pretty cool, right? 61 00:02:55,630 --> 00:03:02,090 You can also just go ahead and say, firstName.equals(" Bob"), all right? 62 00:03:02,090 --> 00:03:04,539 And what that did, is it created a new variable. 63 00:03:04,539 --> 00:03:08,315 Now there's a variable called $3, and we can say it is $3 == true, and 64 00:03:08,315 --> 00:03:10,087 it doesn't, right, cuz we know. 65 00:03:10,087 --> 00:03:14,520 So $3 is a new variable name, and now it made a $4 called false. 66 00:03:14,520 --> 00:03:17,301 So it just automatically creates these variables, and 67 00:03:17,301 --> 00:03:18,847 it starts with $ in the front. 68 00:03:18,847 --> 00:03:22,265 It kind of just stores whatever is returned, right, so if I do firstName, 69 00:03:22,265 --> 00:03:23,857 let's see, equalsIgnoreCase. 70 00:03:23,857 --> 00:03:26,712 Remember that that was the one that allowed us to check, 71 00:03:26,712 --> 00:03:28,980 no matter if it was uppercase or lowercase. 72 00:03:28,980 --> 00:03:32,915 So if I say, equalsIgnoreCase("CRAIG"), it's gonna create a new, this $5 and 73 00:03:32,915 --> 00:03:35,430 it's in true, just kinda stores whatever is there. 74 00:03:35,430 --> 00:03:39,656 So if you wanna refresh your screen, you can do a Ctrl + L, 75 00:03:39,656 --> 00:03:43,732 and it will bring everything up to the top, there we go. 76 00:03:43,732 --> 00:03:47,752 So if you did the extra credit on Java basics, where we tried to validate input, 77 00:03:47,752 --> 00:03:51,719 you learned about the contains and toLowercase methods that exist on string. 78 00:03:51,719 --> 00:03:52,830 Let's take a look at them real quick. 79 00:03:52,830 --> 00:03:57,651 So let's make a new string, let's say string 80 00:03:57,651 --> 00:04:02,849 Some words = This is a bunch of WORDS, all right. 81 00:04:02,849 --> 00:04:04,746 So we now have a variable called someWords. 82 00:04:04,746 --> 00:04:08,597 And so, if I start typing S-O-M and I press tab, it's gonna look, and 83 00:04:08,597 --> 00:04:11,900 it will search, and it will find that I have someWords there. 84 00:04:11,900 --> 00:04:14,873 So it'll automatically do that, and it works for methods too, so 85 00:04:14,873 --> 00:04:17,594 I'll do contains, and I'll do tab and I'll pop this over. 86 00:04:17,594 --> 00:04:24,530 So contains looks for the word bunch there, inside of some words. 87 00:04:24,530 --> 00:04:25,176 Does it exist? 88 00:04:25,176 --> 00:04:27,180 It sure does, there it is, all right? 89 00:04:27,180 --> 00:04:31,660 And we can also, if I press the up arrow, things will come back. 90 00:04:31,660 --> 00:04:34,996 So then I can use the backspace there and say, does it contain this? 91 00:04:34,996 --> 00:04:37,030 Which it does, right, there's this. 92 00:04:37,030 --> 00:04:41,344 So there's true, and then also if I come and do, 93 00:04:41,344 --> 00:04:44,670 let's see if it has words in there. 94 00:04:44,670 --> 00:04:46,580 So this is case sensitive, right, so 95 00:04:46,580 --> 00:04:50,050 it doesn't contain words even though it is actually there. 96 00:04:50,050 --> 00:04:55,330 So, we could create a new variable, right, we could say, 97 00:04:55,330 --> 00:05:02,212 String loweredwords = someWords, and remember this is toLowerCase(). 98 00:05:02,212 --> 00:05:04,124 Yep, and when there's multiple options there, so 99 00:05:04,124 --> 00:05:07,350 it's gonna show us the toLowerCase(), that's what we want. 100 00:05:07,350 --> 00:05:14,799 So loweredWords, we could then check if loweredWords contains words. 101 00:05:16,844 --> 00:05:21,700 And indeed it does, but what if we did the method chaining? 102 00:05:21,700 --> 00:05:24,870 And remember this, we could say someWords.toLowercase(), and 103 00:05:24,870 --> 00:05:28,480 instead of storing that variable, we can just access it right here. 104 00:05:28,480 --> 00:05:31,078 It's called method chain, remember we don't even need to create it. 105 00:05:34,133 --> 00:05:37,167 Cool, all right, so we also did some work with integers, or 106 00:05:37,167 --> 00:05:39,439 whole numbers which were like this, right? 107 00:05:39,439 --> 00:05:44,759 So if we say int ageofBob= 30, and 108 00:05:44,759 --> 00:05:50,087 let's say that Mary, she's 28. 109 00:05:52,265 --> 00:05:58,951 And we could check and see, I'm gonna put parentheses around these, 110 00:05:58,951 --> 00:06:04,291 just so, if Bob is older or greater than the age of Mary. 111 00:06:07,060 --> 00:06:15,469 And I'm gonna do parentheses (ageofBob is less than the age of Mary), right? 112 00:06:15,469 --> 00:06:18,740 I mean, that's how we talk about numbers are greater than or less than. 113 00:06:18,740 --> 00:06:23,679 And finally, let's go ahead and, remember when you get a number in, 114 00:06:23,679 --> 00:06:29,860 maybe you're getting in a number from a program's coming in, you can parse it. 115 00:06:29,860 --> 00:06:32,970 So let's say that somebody parsed in the string 30, 116 00:06:32,970 --> 00:06:36,320 you can get the number out with that, there we go. 117 00:06:36,320 --> 00:06:40,070 And finally, let's remember about Booleans. 118 00:06:40,070 --> 00:06:43,562 So using conditional logic like AND or ORS, and 119 00:06:43,562 --> 00:06:48,630 those look like this in Java, so you say, OR with a double pipe. 120 00:06:48,630 --> 00:06:52,216 So if we had say, false or false, that's definitely going to be false. 121 00:06:52,216 --> 00:06:54,370 But what if we put a true here, remember what happens? 122 00:06:54,370 --> 00:06:59,770 So the way that it works is, if any of these are true, it means that it's true. 123 00:06:59,770 --> 00:07:03,298 And this is the case in OR, so it's like, is this true, or is this true, or 124 00:07:03,298 --> 00:07:05,590 is this true and it is, so there's that. 125 00:07:05,590 --> 00:07:09,276 And then if we flip that around, and again I use the up arrow, and 126 00:07:09,276 --> 00:07:13,255 I'm gonna remove these to be ampersands, remember how this works. 127 00:07:13,255 --> 00:07:15,760 This is basically saying, are all of these true? 128 00:07:15,760 --> 00:07:20,503 So is false and false and true, so it's not true. 129 00:07:20,503 --> 00:07:22,640 And actually what's gonna happen, is it's gonna shortcut. 130 00:07:22,640 --> 00:07:24,080 The second that it finds when it's false, 131 00:07:24,080 --> 00:07:26,150 it's not even gonna need to look at the rest of them. 132 00:07:26,150 --> 00:07:29,112 So, and again, those could of course be expressions like the age of Bob and 133 00:07:29,112 --> 00:07:30,390 age of many things. 134 00:07:30,390 --> 00:07:34,460 So, feel free to play around here until you feel refreshed on what we covered. 135 00:07:34,460 --> 00:07:36,635 We'll spend quite a bit of time in here during this course. 136 00:07:36,635 --> 00:07:39,454 And I'll show you a couple more cool things that this awesome tool can do in 137 00:07:39,454 --> 00:07:40,630 upcoming videos. 138 00:07:40,630 --> 00:07:43,701 Now to get out of here, you press Ctrl + D, cool and 139 00:07:43,701 --> 00:07:46,280 then you can do clear and clear the screen. 140 00:07:47,670 --> 00:07:49,047 Awesome, I feel refreshed, 141 00:07:49,047 --> 00:07:52,350 that REPL is going to be super handy going forward, right? 142 00:07:52,350 --> 00:07:54,629 Now before we get started, I just wanna remind you that, 143 00:07:54,629 --> 00:07:55,827 during your learnings here. 144 00:07:55,827 --> 00:07:58,995 If anything at all isn't clear, or even if you're pondering something, 145 00:07:58,995 --> 00:08:02,270 head over to the community and share your question with everyone. 146 00:08:02,270 --> 00:08:04,750 By sharing your question, it allows everyone to learn. 147 00:08:04,750 --> 00:08:06,686 And if someone else is wondering that very same thing, 148 00:08:06,686 --> 00:08:09,000 it'll be answered when they come to search for it. 149 00:08:09,000 --> 00:08:12,974 I can't stress this enough, the community is awesome and supportive, and 150 00:08:12,974 --> 00:08:15,653 I've been blown away by how quick answers appear. 151 00:08:15,653 --> 00:08:18,360 I can't even keep up, you all are so great. 152 00:08:18,360 --> 00:08:18,877 All right, 153 00:08:18,877 --> 00:08:22,570 I think we're ready to dive into objects, right after you ace this refresher quiz.