Link to lesson

Basics of Java

Reference vs. Primitive Types

Reference Types: Objects/classes, spelled in CamelCase, things like Strings or arrays

  • Stores address of data on stack, data is on heap
  • Pass by reference

Primitive Types: A value that is an byte, short, int, long, double, boolean, float, or char

  • On the stack therefore point directly to content
  • Pass by value

Stack vs. Heap

Stack: Type of data structure, LIFO, manages temporary variables in functions and stuff

  • Has variables of primitive types and also references to objects
  • Primitive types stored directly, reference types store address

Heap: Type of data structure, dynamic memory allocation

  • Stores data from reference types

Stack Memory (LIFO)

Stores method calls and local variables

Heap Memory

Stores objects and arrays