Welcome back.
In the last week, we created our first variables and we used immutable variables.
And we also saw what an immutable 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 code does.
And they are really great to not only understand what code does, but they are also great in order to
know what would you need to do.
So, for example, if you had 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 To-Do 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.
Fight mode to do element 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 slashes, we can also create multi-line comments by by using a slash
and then a asterisk.
OK?
And with.
That's it 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 multi-line comment to be precise.
Multi 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 but every variable is of a specific type and type inference as a concept that allows us to
just assign a value to a variable and Kotlin 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 31 to it, then this my h variable will be
of type.
String will be of type event.
So.
This is an event, and this year is a string.
All right, it's are used for whole numbers and they require a certain amount of space in our memory.
For example, an 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 this type called short, the type called end and
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 byte is just eight bits, requires a bits in the memory, a short requires 16 bits
in 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 it 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 bytes dropped 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 byte should be of type byte.
How do you do that?
Well, I can do that by using the colon and afterwards to type.
But of course, if I use a byte type, I can not use a long number because note will say.
The integer literal does not conform to the expected Typekit.
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 byte 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 bar.
This is a short isn't.
This isn't long, but we don't need to do that.
You saw it here.
I just assigned a value 31 and that will automatically assign the right data type.
And usually, if you don't explicitly say that you want to have a byte or short, it will just assign
an integer.
Cotton will just assume that this is an integer.
How do you know that?
Well, you can just enter my h, 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 Typekit, 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 who are my age 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 flawed variable, which I called
my flawed, 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, okay, 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 Scotland, 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 flood comes into play.
But most of the time, stubble will be your way to go.
All right.
So these are the number types, but there are other types as well.