Data Types in Java
Data Types in Java
Every variable in java has a data type. Data types specify the size and type of
values that can be stored in an identifier. Java language is rich in its data
types. The variety of data types available allow the programmer to select the type
appropriate to the need of the application.
byte : It is 1 byte(8-bits) integer data type. Value range from -128 to 127.
Default value zero. example: byte b=10;
short : It is 2 bytes(16-bits) integer data type. Value range from -32768 to 32767.
Default value zero. example: short s=11;
int : It is 4 bytes(32-bits) integer data type. Value range from -2147483648 to
2147483647. Default value zero. example: int i=10;
long : It is 8 bytes(64-bits) integer data type. Value range from -
9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Default value zero.
example: long l=100012;
Example:
// short type
short s = 20;
System.out.println("s= " + s);
// int type
int i = 20;
System.out.println("i= " + i);
// long type
long l = 20;
System.out.println("l= " + l);
}
}
Output
b= 20
s= 20
i= 20
l= 20
Floating-Point Number: