Welcome back in this video, we are going to get started with coddling cold, and the focus of this
video will be to, first of all, set up Android Studio so that we can use it in order to learn the
basics very easily.
And then we're going to learn the difference between Vol and VR.
These are super important keywords in Scotland development, and they are really the absolute basis
because you need to have a way to store information for a runtime of your application.
And in this case, we're storing, for example, the amount that something was clicked.
So we're storing it in this variable called times clicked.
But let's go ahead and create a separate project where we are going to not to have all of this boilerplate
code.
So the code, it just is created for us in order to get it even something running, let's really have
a very simplified version of it in Android Studio.
Therefore, let's go ahead and create a new project, and I'm going to create one with no activity.
And I'm going to call this one Scotland basics, Caitlin basics like so you can call it however you
want, and the package name is also not going to be very important in this case because we're not going
to publish this application.
It's really just for us to play around with calling.
The only thing that is important is that you selected Scotland here, which should be done by default.
And now let's create the project.
Now what will potentially happen is that this green stays open, and you don't even know that there
is a second screen open with the Scotland Basic, so you will find that there are two instances of Android
Studio.
OK, so let's go ahead and go into the app folder and then into Java.
And what's important here is that you have Android selected here at the top.
Otherwise the structure will look differently.
As you see here.
If I select Project, for example, of packages, everything looks very different.
So let's go to Android and then on there Java, let's go under you tutorials, Kotlin basics, or however
your package name was that you have selected, and let's create a new Kotlin class slash file.
I'm just going to create a file, not a class and nothing else, just a file that I'm going to call
basics.
OK.
So this creates this basic fact file for me, which is a cotton file.
The extension KP stands for called then and now.
Inside of it, you can see that it just has one line of code and that says Package you tutorials dot
cotton basics.
If it has any more code in here, you can just delete it.
What's important is that it is just a Kotlin file.
OK, now at this point, we can shut down this project part and we can get started with the code.
So I'm going to start with the main function, so I'm using fun- main and then brackets and then curly
brackets.
So this one just ends for function.
So we are creating a function, and this function is called main, which is a very special function.
It's not the general function, it's really a function that is the starting point of our application.
So if I were to create another function here, let's call it.
Hello.
You see that it has a different color.
That's because it doesn't use.
And second of all, I don't have this play button next to it.
So this play button is only going to be available for the main function because, as I said, it's the
entry or starting point for our application.
It doesn't exist for this Hello keyboard.
Now, inside of those brackets, I could add parameters, we're going to see what this means later on.
For now, it doesn't matter.
And then we have the curly brackets and they are important because they are the body of the function.
So what's inside of those curly brackets?
That's the body of the function, and that's where we can add the code that we want to be executed once
we run the code.
So if I run this now, nothing will happen because there's no code inside of the curly brackets.
So even though the Gradle build will run, there's really not anything to be displayed.
So you can see here no text, no nothing.
Let's change that by quickly adding a print statement.
So print is a very special method, and we can now enter something that it should say.
So I'm just going to say print, hello world.
So if I run this code again?
It will display Helloworld here.
You can see now it says Helloworld, this print method is just a code block that tells our I.D.
OK, I want to display something so it displays it onto the console, which is this part here at the
bottom.
So you see run, you can close this by either clicking on the run here or by clicking this hide button.
But then you can open it again by clicking on this run option here at the bottom.
And then you can, of course, make changes to your code.
So let's change it to, for example, Hello Dennis.
And run it again.
And there you are.
You see it says, hello, Dennis, now in our console, which is this part here at the bottom.
OK, so that's the print statement, and we're going to use print statements quite often because they
just allow us to see the value of something.
In this case, to something will be a variable.
So I'm just going to go ahead and create a variable and I'm going to give it the name, my name.
So the variable is going to be called my name.
And then I'm assigning Dennis to it.
All right.
So let's use my name instead of using Dennis here.
So instead of saying Dennis, I'm just going to say hello, empty space plus and then my name, by the
way, you can also see that we are using parentheses here.
So these parentheses that just say that this is a string.
OK, we're going to learn about the data types in the next couple of videos, but for now, we're just
focusing on variables.
So we see that we have this new variable called my name.
And then inside of it, we stored value.
So we assign with this equals sign, we store the value Dennis.
This allows us then to re-use this variable and use it in our print statement.
So what we're doing here is we're just saying hello and this space and then at the point after that,
we add the entry of my name.
OK, so let's run this and see what's going to happen, and you will see that there will be no change.
It will still say hello, Dennis.
So now that's changed it to, for example, Frank.
So my name is going to be frank.
Now, let's change it.
And here to bottom it will say Hello, Frank.
Now there is another thing that we can do with variable, and that is to assign a different value to
it so I can now go ahead and use my name and assign a new value to it.
So I could just say, instead of frank, it should say Heidi.
All right.
So now my name is not going to be frank, but my name is going to be Heidi at that point, because even
though it was assigned Frank at the beginning, it was overwritten later on.
And then when it was actually retrieved or used, it had the value of Heidi.
So let's run our project again, and we will see that now it says Hello, Heidi.
So that is pretty much what you can do with variables, you can store values in them and we're going
to see what kind of values you can store in them because currently we're just storing text in them,
right?
In this particular case, even names.
But of course, you could store other types of text in them as well.
And now we have used another keyword in the last video, which was vault, so we didn't use VAR, but
instead we used it.
Now the difference between VAR and Vault is that a VAR variable can be overwritten.
A VAR variable can not be overwritten, can only be set once.
So here we are, setting the value for that variable and it cannot be overwritten, which is why we
get an error here.
You see, we get a little problem.
We can hover over it and it will say a vault cannot be reassigned, so we cannot assign a new value
to a variable that is using the vault key word when it is created.
So that means that this line is not going to work.
Now we can get rid of it and then everything will be fine, but now we have the name of my name.
So we are writing a variable where we want to only be able to assign it once we don't want our code
at any point to be able to overwrite that value.
And that is what you would use to value keyword for.
And by the way, it's also more efficient in terms of processing power.
So if you know that you don't want to ever override value for a given variable that you are creating,
then use the keyword if you're not sure and you believe that you will have to override it at one point.
Then you use VAR.
Of course, you can start with volume.
And then when you realize I actually want to override the value or reassign a new value to this variable,
then you can change the declaration later on and change that to VAR.
And you can go ahead and just say, change the name here to Claudia, for example.
And let's run it real quick, and we'll see if we get.
Hello, Claudia.
OK, so that's basically the difference between VAR and Vault.
In the next video, we're going to look at the data types of numbers.