Algorithms and OOD (CSC 207 2014S) : Labs

Reference Values


Summary: We consider a few basic issues with reference values in Java.

Prerequisite Knowledge: Java basics. Objects in Java. Memory layout.

Preparation

Open the reading on reference values in Java in a new window or tab.

Create a new Eclipse project for this lab. I'd suggest a name like lab-reference-values.

Exercises

Exercise 1: Exploring the Reading

Create a new main class, Experiments, that replicates the various examples from the “Implications” section of the reading. For example, you might start your main method with the following code.

import java.io.PrintWriter;

public class Experiments
{

  public static void main(String[] args)
    throws Exception
  {
    PrintWriter pen = new PrintWriter(System.out, true);

    // First example: int values.

    int i = 2;
    int j = i;

    pen.println("Initial values");
    pen.println("i = " + i);
    pen.println("j = " + j);

    i += 5;

    pen.println("After incrementing i by 5");
    pen.println("i = " + i);
    pen.println("j = " + j);

    // We're done.  Clean up.
    pen.close();
  } // main
} // class Experiments

For Those With Extra Time

If you find that you have extra time (and you should), start working on the next lab.

Copyright (c) 2013-14 Samuel A. Rebelsky.

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.