Java Programming Tutorial - 5 - Variables

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up guys is Bucky welcome to your fifth java tutorial and in this story I'm going to talking to you guys about something called a variable now what variable in Java is is pretty much like a placeholder for something else now if you remember from math class back in like seventh grade or whatever whenever you had a variable and it was usually named something like X you could have it set to a value like 73 and then whenever you use X in a program or a calculation or something X will take the value of 73 and that's pretty much the same exact thing a variable does in Java you assign something called a variable name to value then whenever you use the variable people know that it's not really the variable but actually stands for that value so let's go ahead and make one of these in Java now to make one of these in Java the first thing that you need to do is tell Java what kind of variable you're going to be working with and there's a bunch of different kinds of variables you can work with in Java you can use integers like 3 you can use integers with decimal points like 3.14 you can use letters like s you can use strings of characters like Bucky and so once you have that decided you need to have a way to tell Java what kind of variable you're working with so it doesn't get confused so we're we're going to be working with today is something called a double now what a double is is it's a little bit above it's a keyword that tells Java all right you're going to be working with a number but this number can have a decimal point as well so um after you tell Java what kind of variable you want to work with you got to give it a name so let's go ahead and say we're going to be working with a variable called double and we're going to name it tuna now after you have a variable called tuna you need to give a value so go ahead and write 2 none which is a variable name and then go ahead and press equals now what equals is here is something called the assignment operator and what it does is assign a value to tuna so what that we are we're going to assign it let's go ahead and write five point 28 my favorite number five point 28 so here's what we did so far we told Java that we're going to be working with a variable called tuna and then it's going to be a double meaning that has um numbers on both the left and right hand side of the decimal point again an integer is only a whole number like eight ten negative four and a double has a fraction like five point two eight eight point one eight so again we told that tuna is double it has a fraction next we said all right what's the value of tuna well here's the name here's the assignment operator and here's the value tuna equals five point two eight now we have a variable that has the value of five point two eight that we can throw into any Java program so let's go ahead and do that and how we do that is just like we did before just print it out on a screen so let's go ahead and erase system on the type of write system dot out dot print and in your parameters instead of typing a string of text like this is a strength all we have to do is type the word or the name of the variable such as tuna and that would print tuna out on the screen don't believe me let me show you guys let's go ahead and run this and as you can see down in our little run box it has the variable five point two eight so that is how you write variables out on the screen using Java in another cool thing that you can do with these variables is unless order I'll show you guys how to write strings of text on the screen you can also combine these variables with strings of text so let's say we want to write a system got out print line and get out of here Hoss and in our print line we're going to say I want then go ahead and press space actually this brings me to another point which I will say right now there's two different things system out and print and system out and print line so let me show you guys what those do right now system dot out dot print line and let's go ahead so what's this thing right now I want five point two eight what do you want five point two eight movies I want five point two eight movies makes no sense but just deal with it now let me show you guys what this does and I'll show you guys why it does it let's go ahead and run this and it says okay we printed three things but only is on one line I want five point two eight movies and let me show you guys why this is there's two different print statements that you guys learn so far a system out print what you see in the first two lines and a system out print line what you see in the next line well a print statement does a basic print with no line is it says are a Java we want to print this but we want to stay on the same line and it says all right so just stay on the same line stay on the same line and then after this move to the next line so after you have print line what it would do is move the cursor to the next line so if you printed anything after this it would show up on the next line don't believe me let me show you guys system.out.print and it can even have a basic print stay memory here and let's have apples let me go ahead and run this and as you can see this one moves to the new line so that's the difference between the print statement in the print line statement any time you use a print statement it stays on the same line that you're printing on such as here so this whole thing's on the entire line as soon as you have a print line statement one does is when it gets the end of printing it it moves to a new line so that's the difference between a print statement and a print line statement and again that's your quick tutorial on how to use variables again this is called declaring a variable this is called assigning a variable value again this is the name of the variable and this is the value this is the assignment operator right here and anytime you want to use a variable to print out on your screen just write system.out.print and then write the name of the variable right there and it'll print out on your screen so again that's a quick tutorial on variables and how to use variables in Java so thank you guys for watching make sure to subscribe to my channel I don't forget to check out my next tutorial and again thank you and I'll see you next time
Info
Channel: thenewboston
Views: 1,882,879
Rating: 4.9615216 out of 5
Keywords: install, download, jdk, se, ee, java, development, kit, new, beginner, tutorials, eclipse
Id: gtQJXzi3Yns
Channel Id: undefined
Length: 7min 24sec (444 seconds)
Published: Sat May 02 2009
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.