Menu
Topics Index
...
`


Datatypes > Primtive Dataypes >
Siva Nookala - 26 Sep 2016
The integer data types are used to store whole numbers like 2, 3, 267, -1245, 0, 8382923 etc. Integers do not contain decimal points, so 3.14 and 4221.76 are not valid integers. Java supports four integer types depending upon the sizes - byte, short, int and long

The four integer types in the order of size are:
Type Size Range Inclusive Samples
byte 8-bits or 1 byte -128 to +127, including zero no. of legs, no. of wickets in match, no. of children, no. of sisters
short 16-bits or 2 bytes -32,768 to +32,767 face book friends, height in centimeters, number of runs in a match, total runs of a cricketer
int 32-bits or 4 bytes -2,147,483,648 to +2,147,483,647 roads length in kms, population of a state, number of engineering students in a year
long 64-bits or 8 bytes -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 population of the world, distance to sun in kilo meters, hair count, mobile number
  • Depending upon the requirement we should choose the appropriate data type
  • The size allowed is calculated using the number of bytes. For eg for byte the size is 8-bits, so the range allowed is 2 power 8 which is 256. This 256 is split into half to support both negative and positive numbers. That is reason the size is -128 to +127. The positive side is +127 instead of +128, because zero is also included in the range.
Integer Data Types

0
Wrong
Score more than 2 points

© meritcampus 2016 - 2017

All Rights Reserved.