When we talk about effective programming, it has to cover all the best aspects like what to store where instead of blindly creating variables here and there. This will help you to build scalable and performance effective application.
By saying that, you should be aware that which data type store what max values and what you should use.
Int Range : -2147483648 to 2147483647 (4 byte)
Long Range : -9223372036854775808 to 9223372036854775807 (8 byte)
Short Range : -32768 to 32767 ( 2 byte)
Byte Range : -128 to 127 (1 byte)
Float Range : 1.4E-45 to 3.4028235E38 (4 byte)
Double Range : 4.9E-324 to 1.7976931348623157E308 (8 byte)
Boolean Range: 1 bit (0 or 1)
Char : 2 byte
This will lead you to finalize which data type you can use based on your requirement. Mostly you would see that long would be preferred for scalable application so that if variable values goes long for some reason then it wont break your code and can be manageable. But still If you are using small counter or value where you are comfortable that this value will not goes beyond that then you can use other types like Person Age should be fit to byte as well because it hardly extends more than 127. This will save your memory size which is being created when you create any variable.
The same thing is with float and double which can be decide how accurate value you need after calculation after floating point and this also leads to size. Mostly JAVA uses double for fast and scalable solutions in its existing API wherever required.
In short based on byte and bit range you can finalize which datatype you should use.
Note: For a better representation you can use _ in values as this is new way of representation which is been supported after JAVA 8.
By saying that, you should be aware that which data type store what max values and what you should use.
Int Range : -2147483648 to 2147483647 (4 byte)
Long Range : -9223372036854775808 to 9223372036854775807 (8 byte)
Short Range : -32768 to 32767 ( 2 byte)
Byte Range : -128 to 127 (1 byte)
Float Range : 1.4E-45 to 3.4028235E38 (4 byte)
Double Range : 4.9E-324 to 1.7976931348623157E308 (8 byte)
Boolean Range: 1 bit (0 or 1)
Char : 2 byte
This will lead you to finalize which data type you can use based on your requirement. Mostly you would see that long would be preferred for scalable application so that if variable values goes long for some reason then it wont break your code and can be manageable. But still If you are using small counter or value where you are comfortable that this value will not goes beyond that then you can use other types like Person Age should be fit to byte as well because it hardly extends more than 127. This will save your memory size which is being created when you create any variable.
The same thing is with float and double which can be decide how accurate value you need after calculation after floating point and this also leads to size. Mostly JAVA uses double for fast and scalable solutions in its existing API wherever required.
In short based on byte and bit range you can finalize which datatype you should use.
Note: For a better representation you can use _ in values as this is new way of representation which is been supported after JAVA 8.