Java Tutorial

Data Types in Java

Data types are used for representing the data in main memory of the computer.

Data Types

In JAVA, we have eight data types which are organized in four groups. They are integer category data types, float category data types, character category data types and Boolean category data types.

Integer category data types:

These are used to represent integer data. This category of data type contains four data types which are given in the following table:

S.noData Typessize(bites)Range
1Byte1+127 to -128
2Short2+32767 to -32768
3Int4+2147483647 to -2147483648
4Long8±9.223*1018

Whatever the data type we use that should not exceed predefined value.

Note:

Range of any data type = (A)number of bits occupied by a data type Where, A = number of bits available in the language which is understand by computer i.e., 2 bits.

For example:

Range of byte = 28
= 1 to 256
= 0 to 255 
= 0 to (255/2) 
= (127.5 - 0.5 = +127) (127.5 + 0.5 = -128)

Float category data types:

Float category data types are used for representing the data in the form of scale, precision i.e., these category data types are used for representing float values. This category contains two data types; they are given in the following table:

S.noData Typessize(bites)RangeNumber of Decimal places
1Float4+2147483647 to -21474836488
2Double8±9.223*101016

Whenever we take any decimal constant directly in a JAVA program it is by default treated as highest data type in float category i.e., double.

Character category data types:

A character is an identifier which is enclosed within single quotes.

In JAVA to represent character data, we use a data type called char. This data type takes two bytes since it follows UNICODE character set. Char Data Types

S.noData Typessize(bites)RangeNumber of Decimal places
1Char2+32767 to -327688

JAVA is available in 18 international languages and it is following UNICODE character set.

UNICODE character set is one which contains all the characters which are available in 18 international languages and it contains 65536 characters.

Boolean category data types:

Boolean category data type is used for representing logical values i.e., TRUE or FALSE values.

To represent logical values we use a keyword called Boolean.

This data type takes 0 bytes of memory space.

Note:

All keywords in JAVA must be written in small letters only.