Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Welcome Back8:27 with Craig Dennis
Let's refresh our Java learnings using a new tool named jshell in our old friend Workspaces
[MUSIC] 0:00 Hello and welcome back. 0:04 I'm Craig and I'm a developer. 0:05 This course is going to build on top of what we learned together in Java basics. 0:07 If you haven't checked it out yet, 0:11 I recommend that you follow the link in the teacher's notes. 0:12 It's a prerequisite for 0:14 this course but you don't need to have any other programming experience. 0:15 And what we're going to learn in this course is relevant to many other 0:19 programming languages that you're going to encounter. 0:22 Don't forget that they're speaking trolls in the video player. 0:25 Feel free to speed me up or slow me down to your heart's content. 0:27 I won't mind at all. 0:30 In this course, we are going to be talking about objects. 0:32 Java is an object oriented programming language and 0:35 literally everything in Java is an object. 0:38 Well, except for the primitive types like ants and boolean. 0:41 But even those have wrapper types which are, objects. 0:44 So as you can imagine, understanding objects 0:48 is super critical to your foundational base of the Java language. 0:51 And I'm excited to explore them with you. 0:55 So first, we'll familiarize ourselves with the basics of objects. 0:57 How to use them, how to create them, and 1:01 then after we get a good grasp, we'll build an application using that. 1:02 The app that we're going to build is a console based version of the popular 1:07 game, Hangman. 1:09 Along the way will be expanding our Java toolset again learning new tricks 1:11 as we need them. 1:14 Just like we talked about in Java basics, there are gonna be a lot of new terms. 1:16 And remember you should feel like you need to understand everything fully. 1:20 Immerse yourself in the language and I will cover in detail 1:24 what I believe you need to know at this point of time in your learning. 1:27 We are going to be using work spaces again for this course. 1:30 So you can follow along in code without having to install 1:33 anything at all in your local machine. 1:35 We're also going to be making use of a tool that might be new to you. 1:38 It's called JShell, and it's the new REPL that Java just got in Java 9. 1:41 In case you haven't heard of the term REPL, or R-E-P-L, it stands for 1:46 Read-Eval-Print-Loop, and it allows you to interact with and explore the language. 1:50 I think you're gonna to love it. 1:54 Let's launch a workspace and check it out. 1:56 Okay, so welcome back to workspaces. 1:58 So down here in the console, if you just go ahead and type JShell. 2:00 It's going to start up, it's going to start the REPL up. 2:05 So again that's read a vowel print loop, check the teacher's notes for 2:08 more on jshell. 2:11 It's super powerful and it's up and 2:12 coming and let's use it right now it's just refresh ourselves and 2:13 what we've learned so far, it's an awesome tool you're going to love it. 2:16 So what this will let us do it'll let us create variables just like we know. 2:21 So we'll do string first name equals Craig. 2:24 And you'll see what it does there is it says that it set the variable 2:28 name to Craig. 2:31 It's kind of that's its style of output there. 2:32 So now we can access those variables like so. 2:34 So we'll say isCraig and let's see. 2:37 Let's do this firstName., to call the method, equals("Craig") right? 2:41 So remember that we we call the equals method on strings to check equality. 2:46 They're look at stored in the variable now there's a variable called is Craig and 2:50 you'll notice that I accessed first name. 2:54 So it's kind of in the scope of this this shell that we're working in here you 2:56 can also just go ahead and say firstName.equals("Bob). 3:00 And what that did is it created a new variable. 3:06 Now there's a variable called $3 you can say it is dollar three equal true and 3:09 it doesn't rank as we know. 3:13 So dollar three is a new variable name and now I made a dollar four called false. 3:14 So I just automatically creates these variables and 3:19 it starts with a dollar sign in the front. 3:21 It kinda just stores whatever is returned right. 3:23 So if I do first name equals ignore case remember that that was the one that 3:25 allowed us to check no matter if it was upper case or lower case so 3:29 if I say equals ignore the case. 3:33 Craig it's going to create a new there's dollar five it's untrue just going to 3:35 stores whatever is there. 3:38 So if you want to refresh your screen you can do a Ctrl + L. 3:40 And it will bring everything up to the top there we go. 3:44 So if you did the extra credit on Java Basics where we tried to validate input 3:48 you learned about the contains into lower case methods that exist on street, 3:51 let's take a look at them real quick. 3:56 So let's make a new string, let's say String someWords 3:57 equalas"This is a bunch of WORDS". 4:01 All right. 4:06 So we now have a variable called somewhere and so if I start typing. 4:07 So in and I press tab it's gonna look and it will search and 4:10 it will find that I have some words there so automatically did that and 4:13 it works for methods two so I did contains a tab and it was over. 4:17 So contains looks for A, the word, bunch there inside of some words. 4:22 Does it exist? 4:29 It sure does. 4:29 There it is, all right. 4:30 And if I press the up arrow, things will come back. 4:32 So then, I can use the backspace there and say does it contain this, 4:36 which it does, right. 4:39 There's this, so there's true. 4:40 And also, if I come and do, let's see if it has words in there. 4:43 So this is case sensitive. 4:49 So it doesn't contain words even though it is actually there. 4:51 So we could create a new variable, right. 4:54 We could say string loweredWords equals some Words and 4:58 remember this is toLowerCase. 5:03 Yep. And when there's multiple options, 5:06 there so it's gonna show us. 5:08 So toLowerCase is we want, so loweredWords we could then check if loweredWords, 5:09 Contains words and indeed it does. 5:17 But what if we did the method chaining, 5:22 remember this we could say someWords.toLowerCase and 5:26 instead of strong that variable, we can just access it right here. 5:29 It's called method change. 5:33 Remember, we don't even need to create it. 5:33 Cool, all right, so, we also did some work with integers or 5:38 whole numbers which were like this right. 5:41 So if we say int ageOfBob = 30. 5:44 And let's say that Mary. 5:47 She's 28. 5:53 And we could check and see, 5:55 I'm going to put parentheses around these, just so 5:58 if Bob is older or greater than the age of Mary. 6:04 And then again to parenthesis age of Bob is less than the age of Mary. 6:11 So we talk about numbers are greater than or less then. 6:20 And finally let's go ahead and remember that when you get 6:23 a number in maybe you get a number from a programs coming in you can purse it. 6:29 So let's say that somebody passed in the string 30, 6:34 you can get the number out with that. 6:37 There you go. 6:40 And finally, let's remember about Booleans. 6:40 So using conditional logic like and or ors and those look like this in Java. 6:44 So you say or with a with a double pipe. 6:50 So if we had say false or false, that's definitely going to be false, but 6:53 what if we put a true here? 6:56 Do you remember what happens? 6:57 So the way that it works is if any of these are true, it means that it's true. 6:58 And this is the case and or is so it's like is this true or is this true or 7:04 is this true and it is so there's that and then if we flip that around again. 7:08 I use the up arrow and 7:12 I'm going to move these to be ampersands remember how this works. 7:13 This is basically saying, are all of these true. 7:17 So is false and false and true. 7:20 So it's not, it's not true. 7:23 And actually, what's gonna happen is it's gonna shortcut the second that it 7:25 finds one that's false. 7:27 It's not even going to need to look at the rest of them. 7:28 So and again, 7:30 those could of course be expressions like the age of Bob an age of many thing. 7:31 Feel free to play around here until you feel refresh what we covered. 7:34 We'll spend quite a bit of time in here during this course and I'll show you 7:39 a couple more cool things that this awesome tool can do in upcoming videos. 7:41 Now to get out of here you press Ctrl + D. 7:45 Cool and then you can do clear and clear the screen. 7:49 Awesome, I feel refreshed. 7:52 That REPL is going to be super handy going forward, right. 7:53 Now before we get started, I just wanna remind you that during your learnings here 7:56 if anything at all isn't clear. 8:00 Or even if you're pondering something, head over to the community and 8:01 share your question with everyone. 8:05 By sharing your question, 8:06 it allows everyone to learn and if someone else is wondering that very same thing. 8:07 It'll be an answer when they come to search for it. 8:11 I can't stress this enough, the community is awesome and supportive and 8:13 I've been blown away by how quick answers appear. 8:17 I can't even keep up. 8:20 You all are so great. 8:21 All right, I think we're ready to dive into objects 8:22 right after you ace this refresh course. 8:25
You need to sign up for Treehouse in order to download course files.Sign up