‫Hello my friends, and welcome back.
‫In this video we're going to learn about Kotlin variables.
‫Imagine you have a magical box.
‫This box can hold different kinds of things like letters, numbers and words.
‫A variable in programming is like this magical box.
‫It's a special container where you can keep different types of information, just like you put different
‫things in your magical box.
‫Let's take an example.
‫It's like writing your age on a piece of paper and putting it in this box.
‫This box is called age.
‫In this way I am keeping the value 25 inside this container named age for later use.
‫Let's move to Android Studio and start creating Kotlin variables.
‫In Kotlin, a variable is a named storage location in which you can store and manipulate data variables
‫can hold different types of information such as numbers, text, or more complex objects.
‫To create a variable in Kotlin, you need to specify its type, give it a name, and optionally assign
‫an initial value.
‫The first step in creating a variable is the variable declaration.
‫You declare a variable using var or val keyword, followed by the variable name and its type.
‫You declare a variable using the var or val keyword, followed by the variable name and its type.
‫The var keyword is used to declare a mutable variable, one that can change its value, and the val
‫is used for an immutable variable, one that can't change its value.
‫Once set, I'll create both types the var and val.
‫The first type is of type mutable variable, which is var.
‫So I use var keyword my age.
‫It's of type int equals to 25, and the second variable is immutable variable which is of type val.
‫So you can see the var keyword for mutable variables that can be changed, and the val keyword that
‫it is used for variables that are not able to be changed.
‫For example the pi in math and it's of type double equals to 3.14 15 nine.
‫We'll learn about these data types in the next videos.
‫The second step in creating the variables is to specify the type of this variable.
‫It's named as type inference.
‫In many cases, you can let Kotlin automatically infer the variable's type based on the assigned value,
‫so you don't need to specify it explicitly.
‫This is known as type inference.
‫So here I can remove this part, because Kotlin will automatically set the type of my age to integer
‫based on the value type that we set.
‫The third step in creating the variables is to assign the values to this variable.
‫Here I'm using the equals sign, which is the assignment operator in Kotlin, and I'm assigning 25 to
‫this variable.
‫I am putting 25 in a piece of paper inside this box called my age.
‫You can change the value of a mutable variable using the assignment operator.
‫However, you can't change the value of an immutable variable.
‫Now let's learn how to use these variables and get their values here.
‫Inside the println I remove.
‫Hello my friends and I'll use.
‫My age is and outside I'll use plus my age.
‫Later on we'll learn about this concatenation.
‫Now let's run our application.
‫Click on this green triangle and here we go.
‫This is the fixed part.
‫And this is the variable part which is my age.
‫So we are calling this package this box opening it getting the value and displaying it in the console.