In this tutorial we will learn about how to create variable to java data type and how to use it with practical step by step example.
If you want to follow along, click on video tutorial which are available in Hindi and English languages.
Java primitive Data type tutorial in English
If we want to use or declare integer, we type int then name of variable in this example point is name of variable which hold value which 5 and for assign we use =. since we store value in variable call point now we can use it. lets print out in console. we have main method and print in console we have system.out.println command and we use semicolon at the end .Now click on Green button to run program but first save before run and check in console. we can observe 5 in console. Integer uses 4 bytes of memory and can store whole number start form -2147483648 to 2147483647.
Short is another datatype of Java which can hold whole number from -32768to 32767 and use size of 2 bytes. To declare short we use short and created variable name price which hold value 15. for assign we use equal sign and we are printing value in console as we can observe in below picture.
Now here important things to know we can use same data type for many circumstances but if we know how much memory it uses we can use or choose data type wisely for an example if we want to store value as 25 . we can use byte , shorts, int, long but is it good idea ? check memory usage and select what data type is ideal to use. If you would like to lean more please click on below link