Learn KOTLIN - Number DATATYPES - int, float, double, long

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up youtube this is dennis panita for tutorials.u slash android in this video we're going to look at data types and the ones that are used for numbers specifically like in float long and double and they are really important to store numbers basically inside of variables and if you haven't checked out the variables lecture definitely watch that youtube video first to understand what variables are before jumping into what data types are because you just need to understand that first so if you think that's a cool idea and you enjoyed this video hit the like button at the subscribe button and also check out the entire playlist if you missed out any of the videos so now let's get started [Music] welcome back in the last video we created our first variables and we used immutable variables and we also saw what an immutable variable is how mu 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 on to 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 you need to do so for example if you add to do then you know okay 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 find my 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 and with that 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 on to our program on the execution time on the compiling time none of that it's just for us as a developer all right now let's have a look at other variable types i told you that kotlin 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 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 age variable will be of type string will be of type int so this is an int and this year is a string all right ins are used for whole numbers and they require a certain amount of space in our memory for example an integer requires bits of memory if we want to use other types they are available as well quick pause so you're learning something about android in this video and i hope you enjoy it if you want to learn everything that you need to know to become a real android developer then definitely check out my android master class because in this course you're going to build a bunch of great applications along your journey to becoming an android developer first you're going to learn the kotlin basics then you're going to learn to build one app after another and while you do that you get a bunch of demos which will really dig deep into the concepts as well as presentations which will help you to understand what you're learning so don't miss out and get the course right now you can find the link in the description below so i'm just gonna 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 int 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 8 bits requires 8 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 a long and here actually it doesn't fit like this anymore so let's do it like that and then we have a super long number here now you might wonder where is this byte short and where are all of these coming from well they come from me entering them so here i explicitly say this variable called mybyte should be of type byte how do i do that well i can do that by using the colon and afterwards the type but of course if i use a byte type i can not use a long number because now it will say the integer literal does not conform to the expected type byte 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 byte 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 byte this is a short doesn't it 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 a short it will just assign an integer kotlin 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 kotlin did the magic for us and it automatically assigned the type int which is called or this approach here call is called type inference so it just inferred the type based on whatever value we assigned to it of course if we do so then we have to assign a value to it so i cannot just create var myh 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 1 3 or 13.37 to my float variable which i call 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 we 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 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 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 kotlin or they will be most of the time used 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 stubble will be your way to go alright so these are the number types but there are other types as well
Info
Channel: tutorialsEU - Android
Views: 45
Rating: undefined out of 5
Keywords: Android tutorial, android tutorial for beginners, android how to, Denis Panjuta android, Tutorials, Tutorial, Programming, Course, Learn, Step by step, guide, development, programmer, video course, video tutorial, learn how to, how to, Udemy, Denis Panjuta, kotlin, data types in kotlin, kotlin data types, kotlin tutorial, kotlin tutorial for beginners, gate exam, kotlin programming, float, double, long, computer science engineering, kotlin programming language, neso academy, freecodecamp
Id: Qa_fLzLOv4Q
Channel Id: undefined
Length: 10min 15sec (615 seconds)
Published: Mon Dec 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.