‫Instructor: Hi.
‫Within this lecture we are going
‫to start working on variables.
‫So, if you haven't heard the term variables before,
‫you're gonna learn it because you are going to need it
‫in every kind of programming language that you
‫will ever learn from this point on.
‫Okay? So, why do we need variables
‫and what are variables anyhow?
‫So, it's spelled like this, variables,
‫and beware of the two slashes that I have put over here
‫in order to take a note.
‫You can do the same thing as well.
‫And as you can see, I cannot write like this.
‫I'll get an error because it's not a word.
‫It's not a comment. It's not a code.
‫It's just a comment when you put two slashes in front of it.
‫Okay? So, what is a variable?
‫It's kind of an object to save values.
‫For example, remember, we have done something like this.
‫We have done five minus applied by two, I believe.
‫Now, I'm doing 10 plus 20, or 10 multiplied by 20,
‫and we get 200 out of it, right?
‫So, maybe I want to store those values
‫in variables, in some objects.
‫So, why do we want that?
‫For example, we may want to use it more
‫than once or maybe we don't even know what the number
‫that we are going to be multiplying is going to be,
‫like, for example, the age of the user.
‫So, suppose that age of the user is 20
‫and I'm going to multiply the age of the user by 10.
‫So, I can create a variable like this.
‫So, this variable is an integer type.
‫So, of course, there are multiple types
‫of variables and this is an integer.
‫Integer means a whole number. It's a number, okay?
‫It doesn't have a decimal.
‫It's just a number like one or two or five or 20.
‫So, in order to create a variable,
‫all you have to do is just write "int" or the type
‫of the variable and the name of the variable, okay?
‫I could have called this anything, not only age,
‫but I could have changed that if I wanted
‫to create an in integer.
‫And then, with an equal sign, you just give the value.
‫For example, once I do that, I can just delete the 20
‫and I can write "age" over here,
‫and Android Studio will know to multiply 10 by 20
‫when I run this.
‫As you can see, we still get the 200 out of this equation
‫because age now represents 20.
‫Now, I can use age in any other line as well.
‫Like, I can divide the age by five. I will get four.
‫So, as you can see, once I define a variable,
‫I can use it in multiple places, so it's an advantage,
‫and maybe I'm getting this value from internet.
‫Maybe I'm getting this value
‫from user via text field or something.
‫So, let me create something like X is five, Y is 10, okay?
‫And let's try to do Y divided by X.
‫So, can I do that? Of course I can.
‫As you can see,
‫we still have the result of two 'cause I'm dividing 10
‫by five over here.
‫So, let me try to do that, 11 divided by five.
‫What will I get? I still get two.
‫So, it's a little bit odd, do you think?
‫Because 11 divided by five is not a whole number.
‫So, let me do this with calculator.
‫If I divide 11 by five, I will get 2.2.
‫I should get that in here as well, right?
‫But, remember what I said about integer.
‫Integer is a whole number. It doesn't have any decimals.
‫So, when I divide an integer by integer,
‫exactly what's gonna happen
‫is to create another integer, right?
‫So, if I want to get something with decimals,
‫then I would work with double, or float.
‫So, these are variables as well.
‫Like, I can just say something like double Z
‫is equal to 5.0.
‫So, this is still five, but with 0.0. Okay?
‫So, let me create another, like, 11.0.
‫So, these are numbers as well and these are 11
‫and five as well,
‫but rather than just creating them, like integers,
‫I have created them as doubles.
‫So now, if I divide A by zet, what will I get as a result?
‫So, let me try it and see.
‫Let me run it from here, or right-clicking to domain,
‫and as you can see, we have 2.2.
‫Because the result of this equation is also a double,
‫I'm actually dividing a double by a double
‫and I'm getting the decimals like this.
‫So, you will come across in situations where you will need
‫to work on doubles because you will have,
‫you will need some kind of decimals,
‫but also, you will come across with situations
‫where you will need to work with integers
‫because the result, or the number itself,
‫would have to be integers or longs.
‫Okay? And these are all just numbers, right?
‫So, maybe you get confused at this.
‫What is a long? What is a float?
‫So, let me show you.
‫As you can see,
‫if you can just search for "int, float, double Java,"
‫you will come across with a table like this.
‫So, we have this number types in Java, like integers,
‫long, float, doubles, okay?
‫And these are all just numbers,
‫but they have different capacities like sizes,
‫32 bits, 64 bits.
‫As you can see, you can store much larger values
‫with doubles rather than floats and much larger values
‫with longs rather than integers,
‫and if you are looking for a very big number to work with,
‫then go for long and double and if you're working
‫with small numbers, you can go for float and integers.
‫Don't be confused by them.
‫We're going to do a lot
‫of examples during the lectures, okay?
‫I'm just showing you this as an example
‫so that you won't get confused
‫about integers or floats or longs or doubles.
‫These are just numbers
‫and we have different number types, that's all.
‫So let's, for example, try to do something like this.
‫Let's create a long and call this "My Long,"
‫with camel keys of course,
‫and I'm going to give 10 as a value.
‫Of course, you can print this out.
‫You can do whatever you may want to do with it,
‫like dividing it by five,
‫and you will still get two as a result.
‫Over here, it won't change the outcome of the situation.
‫Of course, we can do this with float as well, like 10.0,
‫but in case you get an error like this over here,
‫it means that looking for float, but you gave me doubled.
‫So, you have to be as explicit as possible over here,
‫which is why they invented something like this.
‫If you put F at the end of the value,
‫it means that it's a float.
‫If you don't put it, it's a double. Okay?
‫So now, under Android Studio actually understand
‫this is a double.
‫So, we're not going to spend so much time over here.
‫All you have to understand,
‫these are just numbers and there are some,
‫several types in Java.
‫Let's continue within the next lecture.