Two Kinds of 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        

Answer:

A variable of a primitive type contains the actual data, not information on where the data is.

Two Kinds of Variables

An object reference does not contain the actual data, just a way to find it. There are two kinds of variables in Java:

 Characteristics
primitive variableContains the actual data.
reference variableContains information on how to find the object.

Here is the example program again:

class EgString
{

  public static void main ( String[] args )
  {
    String str;
    
    str = new String( "The Gingham Dog" );

    System.out.println( str );
  }
}

When the statement

System.out.println( str );

is executed, the reference in str is used to find the object and to get the data to be printed.

QUESTION 7:

Does using str in the above statement change the information it contains?