Java Programming Tutorial 6 - Variables

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back everybody in the previous videos we created this app that would ask someone for their name get their user input and then print out their name so that is where we are so far in our Java programming but we really need to understand some more of the basic concepts in order for us to build more complex applications so with that we're gonna dive in I just wanted to first give a special shout out and thank you to our sponsor pram pram is a website that allows you to do peer-to-peer interviewing to prepare for technical interviews and data structures and algorithms data science and more definitely a really sweet app because you get to interview people as well as get interviewed so you get to see both the the interviewer and the inner or interviewee and point of view and I use this app to really help me prepare for a C++ interview but you can also use Java and all kinds of other programming languages go check that out I'll leave a link for you guys in the description as a developer it will definitely change your life okay so moving on what are we going to be talking about today well so far we have all this code here and I think as we eventually build more complex applications will start modulating our code making it more like small individual pieces versus just putting everything inside of this main method it's not really the best practice so the main method is more just like this place to start but eventually you're going to break out into your own methods and just keep everything real organized but as we're going through some of the concepts of Java we're not going to necessarily break out into all these methods just because I want to go through some really simple examples and just talk about the basic fundamental concepts of Java so with that we're gonna be talking about variables so we've created variables so here you can see we created the scanner variable it's of type scanner and we then use this scanner variable later when we want to get a new line so we get next line so that's an example use of a variable but there is a lot more stuff we can do with variables the point of a variable is it allows us to store information in some name so then we can easily refer back to it later another example we went through earlier is that we can create a string variable like so this is a string in this example we call this string constructor which will return us a string and we assign it to this variable named string so anytime we want to reference it we can just do let's say we want a print line we can just reference that string variable here and when we execute this all right so it says this is a string so it's printing the string variable right here and we're referencing this by name so rather than taking this here and putting that inside of this print line like this which is okay you can do that that is just not as clear and simple as using variables once we start getting into more complex coding so one thing I wanted to mention is that variables can be used in what's known as an expression so an expression is basically just when you combine values so for example I could say string plus and then put a smiley face for example and I'm going to get rid of all this stuff here and now you can see that this expression is evaluated so we have the first variable string which is label which has this value and then we're basically concatenated which is the technical word of combining two strings or concatenating it's it's hard word to say this smiley face to this original string so this thing here this is known as an expression so just for some new vocabulary we have a variable which stores some value and then we have an expression which evaluates to a value so so far you understand how to create objects we created this string object and then you know how to use the variable name inside of an expression so what about this plus sign this is known as an operator and what an operator does is it will work on operands to produce a value so the operators make the expression possible so if M except no sense basically the plus symbol is going to take one piece of data known as an operand and do something with it with another piece of data and operand so two operands being worked on together by this thing called an operator so the other term is operand and this is the the thing I don't know how to define this or the the things the operator works on as we start making some sweet apps we're gonna find that hey building these strings this way is like a huge pain in the butt like dude I have to type string like three times and four times if we're using it in the string it's just really complicated so Java has created a more simple way to create strings and the way this works is you just type string you still need that data type and then you give it a name shoot I don't know what to name it easier and then all you have to do is just put the value of the string in quotes Wow it's so much easier these ultimately work the same way there's nothing different about them it's just the way we define them is just a little bit different in the syntax because we're using a shorthand version here so now I want to talk about what kind of things can we assign to a string in this scenario we're assigning what's known as a literal so that's another word for you guys in case you haven't figured out if you're new to programming there's a lot of vocabulary and honestly that's just one of the biggest barriers if you just learn the vocabulary you'll be good to go alright so let's go up here we can have literals which is just the value so for example here's a value you know here's another value that is in contrast to a variable which we talked about so this is a variable it's not a literal so anytime we just put the value just like that that is known as a literal it's literally just a value literally it's it's really simple so you can assign a literal to a variable that's what we're doing in this case we're assigning this string literal to easier but we can also use expressions to assign to variables so for example I can come in here and put a plus sign after our string literal and I but it smiley face you know gotta love them smiley faces we can save that and then what we can do is we can print out that string right there easier and now let's run this sucker boom there we go so what we just did is we combined a string literal with another string literal and when we combine two literals that is known as an expression would expressions do they evaluate to a value so the ultimate value was just one string wow that was easy not only can you use multiple literals in an expression but you can also use variables here so for example I could say string just like that okay so now we're combining this literal here with the string variable up here so if everything goes right it should say wow that was easy this is a string let's check it out yep and it works now for each one of the things we've talked about in this video there is a lot of information on so for example this operator well we can go in a lot of depth on operators there's all different types of operators expressions we can talk about you know how expressions are evaluated you know we could talk about variables and the different types of variables there's a whole lot more information that you can learn about this but personally I just think it's helpful if you learn the basics and kind of get like you know the the thousand foot view before learning like all the super itty gritty details so what we're gonna do now is we're going to go into the next video and we're gonna be talking about what do I want to talk about today I think we're gonna talk about something cool so yeah definitely go check it out also check out the links in the description all the link to a blog as well as the Java crash course and a link to the sponsor so thanks guys if you've enjoyed this content please be sure to subscribe it would definitely mean a lot to me alright peace out [Music]
Info
Channel: Caleb Curry
Views: 92,452
Rating: 4.9510045 out of 5
Keywords: Java, programming, java programming, tutorial, tutorial 6, variables, java tutorial, java tutorial for beginners, programming tutorial, code, coding, how to, caleb, curry, calebthevideomaker2
Id: 7wWvSn_qiBc
Channel Id: undefined
Length: 8min 51sec (531 seconds)
Published: Tue Nov 27 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.