Data Types
Various data types used in Java are byte, short, int, long, char, float, double and boolean.
byte
This is in fact smallest integer type of data type. Its width is of 8-bits with the range -128 to 127. The variable can be declared as byte type as
byte i,j;
short
This data type is also used for defining the signed numerical variables with a width of 16-bits and having a range from -32,768 to 32,767. The variable can be declared as short as short a,b;
int
This is the most commonly used data type for defining the numerical data. The width of this data type is 32-bit having a range 2,147,483,648 to 2,147,483,647. The declaration can be int p,q;
long
Sometimes when int is not sufficient for declaring some data then long is used. The range of long is really very long and it is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. The declaration can be
long x,y;
float
To represent the real number(i.e. number that may have decimal point) float data type can be used. The width is 32-bit and range of this data type is 1.4e-045 to 3.4e+038.
double
To represent the real numbers of large range the double data type is used. Its width is 64-bit having the range 4.9e-324 to 1.8e+308.
Char
This data type is used to represent the character type of data. The width of this data type is 16-bit and its range is 0 to 65,536.
Let us see one simple Java program which makes use of various data types.
boolean
Boolean is a simple data type which denotes a value to be either true or false.