In all the previous class examples, the fundamental building blocks of each class definition were ints or doubles. Think of int and double as elements like hydrogen or helium: as atoms of particular elements are the building blocks of all molecules, so are primitive types the building blocks of all classes.
int and double are both what we know as primitive types in Java. There is one other kind of type in Java, and that is the reference type. We will talk more about reference types later.
Typographically, primitive types are distinguished by the fact that they start with lowercase letters. Reference types, on the other hand, start (by convention) with uppercase letters.
There are eight primitive types in Java. Six of these types represent numbers. These are float and double for numbers that are not necessarily integers, and byte, short, int and long for integers. The different primitive types have different upper and lower bounds on the values they contain. These differences are summarized in the following tables.
Of these four integer types, the one that will most often do the trick is int. When you need to represent an integer, your first choice should be int, and you should only use one of the other types if you have a specific reason for so doing.
type min value max value byte -128 127 short -32768 32767 int -2147483648 2147483647 long -9223372036854775808 9223372036854775807
For floats and doubles, think of the numbers as being in scientific notation: something times 10 to the some exponent. When you consider the values that belong to these types, you think not only of the maximum and minimum numerical values they may assume, but how many digits of precision they provide.
type extreme exponents for the 10 significant digits float -38 to 38 6 or 7 double -308 to 308 15 or 16
There are two other primitive types.
type values boolean true, false char individual characters like 'A', '2', '$'