Two Steps with an Assignment Operator

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        
str = new String( "The Gingham Dog" );

Answer:

The new operator creates an object using the constructor String().

Two Steps with an Assignment Operator

Review: Two steps take place when an assignment operator is executed:

  1. The expression on the right of the = is evaluated.
  2. The result of evaluation is assigned to the variable on the left of the =.

When an object is constructed, these steps happen like this:

   
    String str;    // place to hold an object reference
    
    str =      new String( "The Gingham Dog" ); 
    --+--      ----------------+--------------
      |                        |
      |                        
      |                        1.  An object is created using the constructor. 
      |                            The Java system keeps track of
      |                            how to find the object (a reference to the object).       

      2. A reference to the object is stored in the variable str.

There are three things involved in this statement: the object, a reference to the object, and the variable.

QUESTION 5:

Say that you have a business card with your name on it.

Are the business card, your name, and the actual you different things?

Are a variable, a reference, and an object different things?