‫Hello, my friends, and welcome back.
‫In this video, we're going to talk about Java variables.
‫Imagine you have a special box called a variable.
‫This box can hold different things like numbers or words.
‫So I'm going to store these numbers or these words into this box.
‫In Java, variables are used to store information that you want to use later in your program.
‫Let's take another example.
‫Let's say you want to remember your age.
‫You can create a variable called age.
‫This box is called age.
‫So think about a variable is an empty box.
‫So this variable is called age.
‫And this box is called age.
‫And put your age inside it.
‫It's like writing your age, for example, 25 on a piece of paper and putting it inside this box.
‫So the variable now is called age and the value of your age is 25.
‫So this variable, this box contains a value 25.
‫And the name of this variable is called age.
‫Let's jump into Android studio and see how we can create variables in Java.
‫Now let's create our very first variable in Java starting by int age equal to 25.
‫I'll continue with the age example here.
‫INT is a keyword in Java.
‫That means the variable will hold a whole number.
‫You can also use other keywords for different types of information, like string for words, double
‫for numbers with decimal points.
‫We'll learn about data types later on in the next videos.
‫But now concentrate with me on how to create variables and the syntax of creating them again.
‫INT is the data type of the variable age is the name of the variable.
‫Equal sign is for assigning the variable to its value.
‫And of course, don't miss that semicolon.
‫So I am creating a variable, a box called age.
‫I am inserting inside it 25.
‫So I'm putting writing on a piece of paper number 25 and putting it inside this box called Age and this
‫box is labeled as an integer so it accepts only numbers.
‫Think about this for variables in Java.
‫As mentioned before, in Java, variables are used to store information that you want to use later in
‫your program.
‫If you notice, the name of the variable is in gray.
‫Now, if I hover the mouse, I can get the message.
‫Variable age is never used.
‫This is from Android Studio telling you that this age variable is never used.
‫How to use the variable.
‫Print this variable now.
‫So system dot out dot print.
‫And here I am creating a new string called my age.
‫And in order to call and make concatenation between the string and the variable of type int, we use
‫the plus sign.
‫Later on we'll talk about the operators in details, but now focus with me on how to use these variables.
‫The age I am calling it.
‫You can see the age is turned into white, so I'm using this variable.
‫If I run this program, click on this and we can see that the message my age is 25 appears on the screen
‫and the input and the look.
‫So this is how we create variables, how to store the values inside these variables and how to call
‫the variables and get the value inside these boxes.
‫Of course, you can update the value of these boxes and these variables.
‫So for example, age equal to three.
‫I am updating it.
‫I'm creating it with 25.
‫Then I can create it with three.
‫Let's run.
‫And you can see that the message is my age, equal to 30.
‫So I am updating here.
‫In this example and in this video, we'll learn how to create variables and how to use them in Java.