Data Types

Java is a statically typed language, meaning every variable must have a declared type, and that type can never change. Java's types fall into two broad categories: primitive types and reference types.

The Eight Primitive Types

Primitive types hold simple values directly in memory — they are not objects. Java defines exactly eight of them:

TypeSizeRange / Example
byte8-bit-128 to 127
short16-bit-32,768 to 32,767
int32-bit-2,147,483,648 to 2,147,483,647
long64-bit-9.2 quintillion to 9.2 quintillion
float32-bitSingle-precision decimal, e.g. 3.14f
double64-bitDouble-precision decimal, e.g. 3.14159
char16-bitA single character, e.g. 'A'
boolean1 bit (conceptually)true or false
byte smallNumber = 100;
long population = 8000000000L;
float temperature = 36.6f;
char grade = 'A';
boolean isPassed = true;

Primitive vs Reference Types

A primitive type stores its actual value directly. A reference type stores a reference (an address) pointing to an object elsewhere in memory. Classes, arrays, and interfaces are all reference types.

String is the most common example of a reference type — even though it's used constantly like a primitive, it's actually an object under the hood:

String greeting = "Hello";
Note: Notice String starts with a capital letter, unlike primitive types (int, double, etc.) which are always lowercase. That capitalization is your visual clue that something is a class, not a primitive.

Default Values

Instance and static fields are automatically given a default value if you don't initialize them yourself. Local variables inside methods do not get a default — you must assign one before using them.

TypeDefault value
byte, short, int, long0
float, double0.0
char' ' (null character)
booleanfalse
Reference types (e.g. String)null

Literal Suffixes

Some literal values need a suffix to tell the compiler exactly which type you mean, since numeric literals default to int or double:

SuffixMeaningExample
LMarks a literal as long8000000000L
fMarks a literal as float36.6f
dMarks a literal as double (optional — it's the default)36.6d
Tip: Without the L suffix, a large whole number literal is treated as int first and may not fit, causing a compile error even when assigning it to a long variable.
Next steps: Head to Operators to start doing things with these values — math, comparisons, and logic.