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

The Problem

A class is just a blueprint — it defines what an entity looks like but has no concrete existence. To actually execute behavior and hold data, the program needs live instances that exist at runtime, each with its own unique state. Without objects, the program would be a collection of static methods with no persistent data.

Core Idea

An object is a basic unit of Object-Oriented Programming that represents real-life entities. It is a runtime instance of a class. An object mainly consists of three things: state (attributes/fields representing properties), behavior (methods defining what the object can do), and identity (a unique name or reference that enables interaction with other objects).

How It Works

When new ClassName() executes, the JVM allocates memory on the heap for the object’s fields (with default values), then calls the constructor to initialize them. A reference to this memory location is returned as the object’s identity. Multiple reference variables can point to the same object. Objects interact by invoking methods on each other’s references — this is how a Java program performs its work.

Visual Explanation

java_object ClassDef Class: Dog (fields + methods) Object Object: Tommy (Instance of Dog) ClassDef->Object instantiated from AnotherObj Object: Max (Another Instance) ClassDef->AnotherObj instantiated from State State (Attributes) name = "Tommy" breed = "Labrador" age = 3 Object->State Behavior Behavior (Methods) bark() eat() sleep() Object->Behavior Identity Identity (Reference) heap address: 0x4F2A variable: Dog tommy Object->Identity

Semantic Network

semantic_object THIS Object CLASS Class THIS--CLASS built from OBJCLASS Object Class THIS--OBJCLASS related OOP OOP in Java THIS--OOP related METHODS Methods THIS--METHODS builds into

Key Properties

  • State: The fields/attributes that hold the object’s data (what it knows)
  • Behavior: The methods that operate on the object’s data (what it does)
  • Identity: The unique reference that distinguishes this object from others
  • Heap allocation: All objects live on the heap, managed by the garbage collector
  • Reference semantics: Variables hold references (pointers) to objects, not the objects themselves

Connections

  • Built from: Java Class — objects are runtime instances of a class blueprint
  • Builds into: Java Methods — objects interact by invoking methods on each other
  • Related: Java Object Class — every object inherits from java.lang.Object
  • Contrasts with: Java Data Types — primitives store values directly; objects use reference semantics

Edge Cases & Gotchas

  • null reference: An object variable set to null points to no object — calling methods on it throws NullPointerException
  • Object identity vs equality: == compares references (identity); .equals() compares content (equality by default uses == unless overridden)
  • Mutable vs immutable objects: Object state can be mutable (changeable) or immutable (unchangeable after construction)
  • Object lifespan: Objects become eligible for garbage collection when no reachable references point to them