• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

The Problem

Every value in a program occupies memory, and the compiler needs to know how much space to allocate and how to interpret the bits. Without a type system, the same 32 bits could represent an integer, a floating-point number, or four characters — leading to errors, portability issues, and unpredictable behavior across platforms.

Core Idea

Java has eight primitive data types: byte, short, int, long, float, double, boolean, and char. Each has a fixed size and range that is platform-independent, guaranteeing the same behavior on any JVM. All other types are reference types (objects and arrays).

How It Works

When a variable of a primitive type is declared, the JVM allocates exactly the specified number of bytes for it (e.g., 4 bytes for int). Primitives are stored directly on the stack (for local variables) or inline in objects (for fields). They are passed by value — a copy is made. Operations on primitives map directly to CPU instructions, making them faster than objects.

Visual Explanation

java_data_types Primitives Java Primitive Types Int byte (8-bit) short (16-bit) int (32-bit) long (64-bit) Primitives->Int integral types Float float (32-bit) double (64-bit) Primitives->Float floating point Char char (16-bit) Unicode Primitives->Char text Bool boolean (true/false) Primitives->Bool logical

Semantic Network

semantic_java_types THIS Data Types WRAP Wrapper Classes THIS--WRAP builds into VAR Variables THIS--VAR builds into OP Operators THIS--OP builds into MEM Memory Management THIS--MEM related

Key Properties

  • Fixed sizes across all platforms: int is always 32 bits, long always 64 bits
  • Signed integers: byte, short, int, long are all signed (no unsigned primitives until Java 8)
  • IEEE 754 floats: float and double follow the IEEE 754 standard
  • char is unsigned 16-bit: Represents Unicode code units, not ASCII

Connections

Edge Cases & Gotchas

  • No unsigned primitives for byte, short, int, long until Java 8 introduced unsigned API methods
  • char != byte: char is 16-bit Unicode, not a single byte
  • Floating-point precision: float has ~7 decimal digits, double has ~15 — rounding errors are common
  • Division by zero: Integer types throw ArithmeticException; floating-point returns Infinity or NaN