Java Primitive and Reference Types

lecture
java
primitive-data-types
type-conversion

Introduced in 2026-02-26-course-overview-and-java-basics (Lecture 1, Week 1).

Two categories of types

Java distinguishes two sorts of types:

  1. Primitive types — built-in, fixed representations.
  2. Reference types — everything else (i.e. classes), including String, arrays, and any user-defined class.

Primitive types

Type Size Stores
boolean not specified true or false
byte 1 byte / 8 bits whole numbers from -128 to 127
short 2 bytes / 16 bits whole numbers from -32,768 to 32,767
int 4 bytes / 32 bits whole numbers from -2,147,483,648 to 2,147,483,647
long 8 bytes / 64 bits whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float 4 bytes / 32 bits fractional numbers, accurate to 6-7 decimal places
double 8 bytes / 64 bits fractional numbers, accurate to 15 decimal places
char 2 bytes / 16 bits a single character/letter

Reference types

Reference types are everything that isn’t primitive — classes, including String and arrays. A variable of a reference type stores a reference to an object, not the object’s data directly (see 2026-02-26-java-basics-part-02-collections-and-strings for the stack/heap consequences of this, and how it changes the meaning of =, ==, and !=).

Collections (Stack, List, Set, Map) can only store objects/reference types — see java-collections-framework for the wrapper classes (Boolean, Byte, Character, Double, Float, Integer, Long, Short) Java provides so primitives can be stored in them.