Page 68 - CA_Blue( J )_Class9
P. 68
• byte: It is an 8-bit signed integer. It can store values between -128 and 127 (both extreme values are included).
By default it contains 0.
It is used to save memory in large arrays because a byte is 4 times smaller than an integer. It can also be used
in place of "int" data type.
Example: byte a = 10, byte b = -20.
• short: The short data type is a 16-bit signed integer or 2 bytes. This is greater than byte in terms of size and
less than integer. Its range is -32,768 to 32767. By default it contains 0.
Example: short s = 10000, short r = -5000.
31
• int: The int data type is a 32-bit signed integer or 4 bytes, which has a minimum value of -2 and a maximum
value of (2 ) . The latest version of Java can use the int data type to represent an unsigned 32-bit integer,
31 -1
32 -1
which has a minimum value of 0 and a maximum value of (2 ) . By default it contains 0.
Example: int a = 100000, int b = -200000.
63
• long: The long data type is a 64-bit integer or 8 bytes. The signed long has a minimum value of -2 and a
63 -1
maximum value of (2 ) . The latest version of Java can use the long data type to represent an unsigned 64-bit
64
long, which has a minimum value of 0 and a maximum value of 2 -1. By default it contains 0L.
Example: long a = 100000L, long b = -200000L.
Type Size Default value Example
byte 1 byte 0 byte b=10;
short 2 bytes 0 short s=1234;
int 4 bytes 0 int i = 123456;
long 8 bytes 0L long d=123456L;
Float Type
Floating point types represents numbers with a fractional part, containing one or more decimals such 3.4f or 56.2.
There are two types: float and double.
• float: The float data type is a single-precision 32-bit IEEE 754 floating point or 4 bytes. The float data type can
store fractional numbers from 3.4e−038 to 3.4e+038, i.e., values up to 7 decimal digits. Note that you should
end the value with an "f".
Example: float a=4.64f, float b=34.6789f
• double: The double data type is a double-precision 64-bit IEEE 754 floating point or 8 bytes. For decimal
values, this data type is generally the default choice. The double data type can store fractional numbers from
1.7e−308 to 1.7e+308, i.e., values up to 16 decimal digits. Note that you may end the value with a "d".
Type Size Default value Example
float 4 bytes 0.0f float a=10.67f;
double 8 bytes 0.0 or 0.0d double b=1234.87674;
Note: The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical standard for floating-point
arithmetic established in 1985 by the Institute of Electrical and Electronics Engineers (IEEE).
Char Type
It stores character constants in the memory. The char data type is a single 16-bit Unicode character. It assumes a
size of 2 bytes, but basically it can hold only a single character because char stores Unicode character sets. It has a
minimum value of ‘\u0000’ (or 0) and a maximum value of ‘\uffff’ (65,535).
66 Touchpad Computer Applications-IX

