||The integer type, with range -2,147,483,648 . . . 2,147,483,647||4 bytes
||The type describing a single
byte, with range -128 . . . 127
||The short integer type, with
range -32768 . . . 32767
||The long integer type, with range -9,223,372,036,854,775,808 . . . 9,223,372,036,854,775,807||8 bytes
floating-point type, with a range of about ±10308 and
about 15 significant decimal digits
||The single-precision floating-point type, with a range of about ±1038 and about 7 significant decimal digits||4 bytes
||The character type, representing
code units in the Unicode encoding scheme
||The type with the two truth
values false and true
|The larger number of bytes a data types uses, the larger the value a variable of that type can hold; but also, the longer it takes for the computer to perform operations on variables of that type...|
|Every integer type has a range of values|
int x; x = 2147483647; x = x + 3; // Should be 2147483650 // But this value is // outside the int range !!! // Instead, x is -2147483646 !!!
long x; x = 2147483647; x = x + 3; // No overflow...
The problem just gets alleviated (delayed...)
Try changing the assignment in the test program to:
x = 9223372036854775807L;
(you need an "L" at the end to denote a
and you will see the overflow problem again...
Floating point numbers
in a computer
represent a value
In other words, the value of a number represented by a floating point number is always an approximation
double f = 4.35; System.out.println(f); // Prints 4.35 System.out.println(100*f); // Prints 434.99999999999994
These programs use specially written packages of software.
In Java, there is a class called BigDecimal that allow you to manipulate very large decimal numbers without loss of precision
If you want to learn more on this, read Advanced Topic 4.1 on page 107 in your book.