Advertisement



< Prev
Next >



Primitive Data Types and Sizes





In Java, each variable has a specific data type, where a data type tells us the size, range and the type of a value that can be stored in a variable. In Java, there are about eight primitive data types, such as - byte, short, int, long, char, float, double, boolean.




Primitive data types are categorized into 4 parts



Note: For many of us who like the reasoning behind equations, we will use a formula to calculate a minimum range and a maximum range of values, that can be stored for the data types like byte, char, int and long.


  1. Minimum Range- It is the minimum value that can be stored in a data type.
  2. Maximum Range- It is the maximum value that can be stored in a data type.



The minimum range is calculated by -2(bits-1) and for the maximum range, it is 2(bits-1)-1, while bits = size of a data type.

For example - The size of a byte data type is 8 bits. And, as per formula above, the minimum range of value that can be stored in a variable declared as the byte data type is -27(-128), while the maximum range of value is 27-1(127). Hence, the range of values for the byte data type is -128 to 127.




Understanding primitive data types


Let's see each primitive data type in Java, one-by-one.






< Prev
Next >
< First Java Program
Class Access Modifiers >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement