== Looks only at Variables

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

In the new program, did the == operator look at the contents of the object?

Answer:

No. The == operator looks only at the variables.

== Looks only at Variables

For primitive types, also, the == operator looks only at the variables. For example:

int x = 32;
int y = 48;

if ( x == y ) System.out.println("They are equal.");

Only the contents of the variables x and y are examined. But with primitive types, the contents of a variable is the data, so with primitive types == looks at data.

With reference types, == looks at the contents of the variables, but now the variables contain object references.

QUESTION 19:

(Thought Question: ) Could two different objects contain equivalent data?