Page 332 - Computer_Science_F5
P. 332
(ii) Floating-point numbers – They are also known as real numbers. This group
includes float and double, which represent single- and double-precision numbers,
respectively. The width and ranges of them are shown in Table 5.6:
Table 5.6: Floating-point datatypes Chapter Five: Object oriented programming with Java
FOR ONLINE READING ONLY
Name Width in bits Range
double 64 4.9e – 324 to 1.8e+308
float 32 1.4e – 045 to 3.4e + 038
Double uses 64 bits for storage. It provides a wider range and greater precision
compared to float. Float uses 32 bits for storage. It offers a smaller range and less
precision compared to double.
(iii) Characters - This group includes char, which represents symbols in a character
set, like letters and numbers. Char is a 16-bit type. The range of a char is 0 to 65,536.
In this case, there are no negative chars.
(iv) Boolean - This group includes boolean. It can have only one of two possible
values, true or false.
Variables, operators and constants
Variables
A variable is the holder that can hold the value while the java program is executed. A
variable is assigned with a datatype. It is name of reserved area allocated in memory.
In other words, it is a name of memory location. There are three types of variables
in java: local, instance and static. A variable provides us with named storage that our
programs can manipulate. Each variable in Java has a specific type, which determines
the size and layout of the variable’s memory; the range of values that can be stored
within that memory; and the set of operations that can be applied to the variable.
(a) Variable declaration in Java
Before using any variable, it must be declared. The following statement expresses
the basic form of a variable declaration –
datatype variable [ = value][, variable [ = value] ...] ;
Here, data type is one of Java’s data types and the variable is the name of the variable.
To declare more than one variable of the specified type, use a comma-separated list.
For, example:
int a, b, c; // Declaration of variables a, b, and c.
int a = 20, b = 30; // initialisation
byte B = 22; // Declaration initialises a byte type variable B.
323
Student’s Book Form Five
Computer Science Form 5.indd 323 23/07/2024 12:34

