Welcome back.
In the last year, we created our first variables and we used immutable variables, and we also saw
what an mutable variable is, how immutable variable.
Now, what I'm using here is a comment.
So this here is a comment.
This is code that will not be considered by the compiler.
So it will not have any influence onto our application or our program.
It's just a comment that helps me to understand what my code does.
And it also helps other developers to understand what the code does.
And they are really great to not only understand what code does, but they are also great in order to
know what you need to do.
So, for example, if you add to do, then, you know, OK, at this point I will need to add a functionality,
add new functionality, for example.
And this is great because then you can go to your Tudou window here at the bottom and you can very quickly
find this.
So let's say I go to a different document.
And I go to my.
Main activity and now in my to do, I can simply.
Find my to do aliment and directly goes over to this spot, and this is amazing because it really helps
me to navigate through my files.
In this case, it's super easy because I only have two documents, but once I have many different documents,
this will come in very handy.
Other than comments with just two Slasher's, we can also create multiline comments by by using a slash
and then a asterisk and with.
That automatically creates the closing comment or the ending comment, which is an asterisk with a slash,
so everything in between here will be a comment.
This is a comment.
So this is a multiline comment, to be precise.
Morti line comment.
All right, so just so you know how you can create comments and what they do so they don't have any
impact onto our program on the execution time, on the compiling time, none of that is just for us
as a developer.
All right.
Now let's have a look at other variable types.
I told you that Caitlin is a typed language.
This means that every variable is of a specific type and type.
Inference is a concept that allows us to just assign a value to a variable and Scotland will know of
which type that variable will be.
So, for example, it knows that this is of type string.
If I create another variable, let's say my H and I assign thirty one to it, then this my age variable
will be of type string will be of type int so.
This is an end and this year as a string, all right, agents are used for holding numbers and they
require a certain amount of space in our memory.
For example, in Integer requires 32 bits of memory if we want to use other types, they're available
as well.
So I'm just going to paste in some other types in here.
For example, there is this type called byte.
Then there's this type called short, the type called end and to type called long.
And all of them are integer types and integer types are whole numbers and each of them requires a different
amount of space.
So for example, a bite is just eight bits, requires eight bits in a memory, a short require 16 bits
of memory and 32 bits and long 64 bits.
Now here it says the value is out of range.
So this value is too long for even a long value.
So if you have a very long number, this could be used, for example, for a Social Security number
or for a credit card number.
Then you could use a long and here actually it doesn't fit like this anymore.
So I stood like that.
And then we have a super long number here.
Now, you might wonder why is this bites short and where are all of these coming from?
Well, they come from me answering them.
So here I explicitly say this variable called my bite should be of type bite.
How do I do that?
Well, I can't do that by using the colon and afterwards the type.
But of course, if I use a bite type, I can not use a long number because it will say.
The integer literal does not conform to the expected type, but this means that the value that I entered
here is so long that it's usually an integer, but we are trying to store it in a bit variable.
And that doesn't work because an integer needs a lot more space than a bite.
So we need to make sure that the value that we assign here is correct.
Now, at the same time, we don't need to do that.
You see, I do that here.
I say this is a buy.
This is a short design.
And this is a long.
But we don't need to do that.
You saw it here.
I just assigned a value thirty one.
And that will automatically assigned the right data type.
And usually if you don't explicitly say that you want to have a bite or a short, it will just assign
an editor.
Cotton will just assume that this is an integer.
How do I know that?
Well, you can just enter my age and you can see here on the right hand side that it is an integer,
so.
Scotland did the magic for us, and it automatically assigned to type it, which is called or does approach
here is called type inference.
So it just inferred to type based on whatever value we assign to it.
Of course, if we do so, then we have to assign a value to it.
So I cannot just create via my H without assigning a value to it.
I need to assign a value to it.
There are a bunch of other types as well, so these are the integer types that we looked at.
Now let's look at the floating point number types.
So there are types which are required for floating point numbers.
For example, the floating point number types float, which is a 32 bit.
Data type and double, which is a 64 bit data type.
Now here I'm assigning one three or thirteen point thirty seven to my float variable, which I called
my float, but it's still complaining.
So what's wrong here?
Well, if I assign a floating point value, it usually assumes that I want to assign a double, as you
can see here.
But if I explicitly only want to use a float, which has a lower range, so which just can't be as long
as that of a number, then I have to explicitly state that by adding an F at the end this F stands for
float.
So I'm just saying, OK, this variable should be of type float or this value that I'm assigning here.
So if I should get rid of this, for example, and I now check my float, you will see that it is a
float.
All right.
So if I get rid of this F and I check what my float is, you can see now it's a double.
And that has to do with me assigning this F to it and explicitly stating that it should be a float.
So if you really need to save space, you can use floats if the numbers are not going to be huge, but
if you need flexibility, long numbers or you just don't care about space, then you can use doubles.
And generally speaking, doubles are preferred by Cottan, or they will be most of the time use if you
don't explicitly state that it's going to be a float.
Using floats is important, for example, when you develop video games and you want to calculate the
physics, then having as fast as possible calculations will be more important than having super duper
precision.
So that's where float comes into play.
But most of the time, stubbled will be your way to go.
All right.
So these are the no types, but there are other types as well.