Page 331 - Computer_Science_F5
P. 331
Computer Science Data types
Java is a statically typed and also a strongly typed language. in Java, each type of data
(such as integer, character, hexadecimal) is predefined as part of the programming
language and all constants or variables defined within a given program must be
described with one of the data types. Data types represent the different values to
FOR ONLINE READING ONLY
be stored in the variable. In Java, there are two categories of data types, namely:
primitive data types and non-primitive data types.
Data Type
Primitive Non-Primitive String
Array
Boolean Numeric Etc
Integral
Character
Integer Floating-point
Boolean Char Byte Short Int Long Float Double
Figure 5.5: Data types
The primitive types
Java defines eight primitive types of data: byte, short, int, long, char, float, double,
and boolean. The primitive types are also commonly referred to as simple types and
they are grouped into the following four groups:
(i) Integers - This group includes byte, short, int, and long. All of these are signed,
positive and negative values. The width and ranges of these integer types vary
widely, as shown in Table 5.5:
Table 5.5: Integers
Name Width in bits Range
Long 64 -9, 223, 372, 036,854,775,808 to 9,223,372,036,854,775,807
Int 32 -2,147,483,648 to 2,147,483,647
Short 16 -32,768 to 32,767
byte 8 -128 to 127
322
for Advanced Secondary Schools
Computer Science Form 5.indd 322 23/07/2024 12:34

