Every program you write deals with data in some form. Java has several types of data it can work with, and this chapter covers some of the most important.
Primitives are data types whose state represents a number, a character, or a true/false indication.
Primitive types are not class types; they do not provide any behavior associated with the type-appropriate values they hold. Java has eight primitive types that should look familiar to you from other languages:
-
boolean
-
byte
-
char
-
double
-
float
-
int
-
long
-
short
Data types come into play when you need to declare variables to hold values that are important to your program. Variables can be either primitives or reference types. They are always declared within a class but a variable might be associated with the class as a whole or its scope might be limited to a method or a block of statements within a method.
boolean | either TRue or false |
char | 16-bit Unicode UTF-16 character (unsigned) |
byte | 8-bit integer (signed) |
short | 16-bit integer (signed) |
int | 32-bit integer (signed) |
long | 64-bit integer (signed) |
float | 32-bit floating-point (IEEE 754) |
double | 64-bit floating-point (IEEE 754) |