Primitive Types and Literal Values

Java defines eight primitive types. Variables that are declared as primitive types are not references to objects. They are only placeholders to store primitive values. The eight primitive types are byte, short, int, long, float, double, char, and boolean. The byte, short, int, and long types represent 8-, 16-, 32-, and 64-bit signed integer values. The char type represents an unsigned 16-bit value. The float and double types represent 32-and 64-bit floating-point values. The ranges of the primitive types are shown in Table 2.1.

Table 2.1. Ranges of Numeric Types
TypeRange
booleantrue and false
byte-(27) to 27 - 1
char0 to 216 - 1
short-(215) to 215 - 1
int-(231) to 231 - 1
long-(263) to 263 - 1
float
 Float.MIN_VALUE ...

Get Sun Certification Training Guide (310-025, 310-027): Java™ 2 Programmer and Developer Exams now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.