Skip to Content
Java Pocket Guide, 4th Edition
book

Java Pocket Guide, 4th Edition

by Robert Liguori, Patricia Liguori
August 2017
Intermediate to advanced content levelIntermediate to advanced
290 pages
4h 10m
English
O'Reilly Media, Inc.
Content preview from Java Pocket Guide, 4th Edition

Chapter 3. Fundamental Types

Fundamental types include the Java primitive types and their corresponding wrapper classes/reference types. There is provision for automatic conversion between these primitive and reference types through autoboxing and unboxing. Numeric promotion is applied to primitive types where appropriate.

Primitive Types

There are eight primitive types in Java: each is a reserved keyword. They describe variables that contain single values of the appropriate format and size (see Table 3-1). Primitive types are always the specified precision, regardless of the underlying hardware precisions (e.g., 32- or 64-bit).

Table 3-1. Primitive types
Type Detail Storage Range

boolean

true or false

1 bit

Not applicable

char

Unicode character

2 bytes

\u0000 to \uFFFF

byte

Integer

1 byte

–128 to 127

short

Integer

2 bytes

–32768 to 32767

int

Integer

4 bytes

–2147483648 to 2147483647

long

Integer

8 bytes

–263 to 263 –1

float

Floating point

4 bytes

1.4e–45 to 3.4e+38

double

Floating point

8 bytes

5e–324 to 1.8e+308

Tip

Primitive types byte, short, int, long, float, and double are all signed. Type char is unsigned.

Literals for Primitive Types

All primitive types except boolean can accept character, decimal, hexadecimal, octal, and Unicode literal formats, as well as character escape sequences. Where appropriate, the literal value is automatically cast or converted. Remember that bits are lost during truncation. The following is a list of primitive assignment ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java 8 Pocket Guide

Java 8 Pocket Guide

Robert Liguori, Patricia Liguori
Java 11 Cookbook - Second Edition

Java 11 Cookbook - Second Edition

Nick Samoylov, Mohamed Sanaulla

Publisher Resources

ISBN: 9781491938683Errata Page