Set 21: Passing by Reference and by Value

Skill 21.1 Differentiate between primitive and reference data types
Skill 21.1 Concepts

Primitive data types are the most basic data types available within the Java language. There are 8: boolean, byte, char, short, int, long, float, and double . These types serve as the building blocks of data manipulation in Java. Such types serve only one purpose — containing pure, simple values of a kind.

We have already explored and used int, double, Boolean, and char data types. Below are a few more,

Primitive data types always store a value

Reference data types are objects and do not store values, but instead point to a reference (or location) in the memory. Objects include arrays and Strings; they also include classes.

The video below provides further explanation,

Skill 21.1: Exercise 1
Skill 21.2 Interpret the outcome of passing primitive and reference data types
Skill 21.2 Concepts

The above example illustrates how different data types are handled in memory. When passing different data types to a method in a program, you should be mindful of how they are stored in the memory to avoid unexpected results.

The below example is illustrative,

Skill 21.2: Exercise 1