In every programming language storing of the data is crucial and data types play a vital role in storing the data.Java is no exception for this.Generally data types are divided into two types. There are numeric and character data type. Each and every data type have sub division in this.Let us learn each and every type in detail.
Numeric:Numeric data types include integers and floating numbers.Among integer there are four types.They are byte,int,short,long.The ranges and size of these data types is:
- byte:-128 to 127 and size is 1 byte.
- short:-32768 to 32767 and size is 2 bytes.
- int:-2148483648 to 2148483647 and size is 4 bytes.
- long:-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 and size is 16 bytes.
For real numbers there are two types of data types.They are float and double and size of these data types is 4 bytes and 8 bytes respectively.The main difference is the precision given by them.For floating point after decimal point we get 6 digits and for double we get 12 digits.
For characters there is only one datatype which is char.The main difference between char data type of c,c++ and java is the size of this datatype. In java the size is 2 bytes and in c,c++ it is 1 byte.The main advantage of the java char is when we assign any numeric value to this data type it is automatically converted into the corresponding character.
In addition to this datatypes java as one more datatype called as boolean.It takes only TRUE or FALSE as it’s input value.