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 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.