8.2. Primitive Types

Java has two fundamental kinds of data types: primitive and reference. Primitive types are those simple types that are not “objects” (described in the previous chapter)—integers, characters, floating-point numbers, and the like. There are eight primitive types: boolean, char, byte, short, int, long, float, and double. A ninth type, void, is used only to indicate when a method does not return a value.

boolean This is a type with only two possible values: true and false. A boolean is an actual type, not merely a disguised int. For example:

boolean flag1 = false;
boolean flag2 = (6 < 7); // true
boolean flag3 = !true;   // false
boolean flag4 = 0;       // compiler error!

char This is a 16-bit unsigned integer value representing a Unicode ...

Get Core Web Programming, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.