Saturday, 3 January 2015

Java integer data types

Integer data types in Java are quite similar to C/C++. There are four integer types in Java as mentioned above. Java has one additional integer data type "byte".

All the integers are signed values in Java i.e. they can hold positive as well as negative values.

We choose the data type depending on the range of values to be stored.

The range of values for different integer data types is as follows:


Integer Data type Size Range
byte 1 byte / 8 bits -128 to -127
short 2 bytes / 16 bits -32768 to 32767
int 4 bytes / 32 bits -2147483648 to 2147483647
long 8 bytes / 64 bits -9223372036854775808 to 9223372036854775807

No comments:

Post a Comment