JV Java

Java: Variables & Types

What you will learn

How Java declares variables with explicit types, the difference between primitives and reference types, and how type checking works at compile time.

Java is statically typed: the compiler checks types before the program ever runs. Every variable must declare what kind of data it will hold.

String name = "Alice";
int age = 25;
double height = 5.6;
boolean isStudent = true;

Primitives vs. reference types

Primitives store actual values directly in memory. Reference types store a memory address pointing to an object.

Type Category Size Default Example
int primitive 4 bytes 0 42
double primitive 8 bytes 0.0 3.14
boolean primitive JVM-dependent false true
char primitive 2 bytes (Unicode) \u0000 'A'
String reference object null "hello"
arrays reference object null new int[3]

Quick check below!