Welcome to DrJava.  Working directory is C:\Users\dgerman
> int[] a = { 1, 2, 3, 2, 5, 1}
> a
{ 1, 2, 3, 2, 5, 1 }
> int[] b = a
> a[3]
2
> b[3]
2
> b[3] = 1001
1001
> a
{ 1, 2, 3, 1001, 5, 1 }


Notice that we copy the reference during the assignment. 

The exact same thing happens when we pass a as an argument to a method.

* mahazuga: Mary Ann
* serepate: Serena
  hgarciah: Henri
  balbakr: Bakr
* ruifan: Rui
* mzelenin: Matthew
* jnp2: Jay
* zeyang: Zejun
* zhang486: Jingyun
  yiwecao: Yiwei
* rthammon: Ryan
* wang686: Jiaxing
* dweissma: Andrew
* kevcao: Kevin
  ssalmero: Salmeron, Santiago (TA)
* luo23: Yawen
* runxzhao: Runxia
* dgerman: German, Dan-Adrian (Primary Instructor)
  creba: Chris

The first experiment: 

public class One {
  public static void main(String[] args) {
    System.out.println("One's main here.");  
  }
}

public class Two {
  public static void main(String[] args) {
    System.out.println("Two's main here."); 
    // call One's main
    // String[] a = new String[10]; 
    One.main(null); // new String[0]); // args); // a);
  }
}

public class Two {
  public static void main(String[] args) {
    System.out.println("Two: " + java.util.Arrays.toString( args )); 
    One.main(args); 
    System.out.println("Two: " + java.util.Arrays.toString( args )); 
  }
}

A slightly more complex experiment: 

public class One {
  public static void main(String[] args) {
    System.out.println("One: " + java.util.Arrays.toString( args )); 
    args[2] = "Tuesday"; 
    System.out.println("One: " + java.util.Arrays.toString( args ));   }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman
> run Two My friend is happy now.
Two: [My, friend, is, happy, now.]
One: [My, friend, is, happy, now.]
One: [My, friend, Tuesday, happy, now.]
Two: [My, friend, Tuesday, happy, now.]


Another more ambitious experiment: 

public class Two {
  public static void main(String[] args) {
    System.out.println("Two: " + java.util.Arrays.toString( args )); 
    One.main(args); 
    System.out.println("Two: " + java.util.Arrays.toString( args )); 
  }
}

public class One {
  public static void main(String[] args) {
    System.out.println("One: " + java.util.Arrays.toString( args )); 
    args[2] = "Tuesday"; 
    System.out.println("One: " + java.util.Arrays.toString( args )); 
    args = new String[] { "I", "am", "stumped." }; // will we see this in Two's main?
    System.out.println("One: " + java.util.Arrays.toString( args ));   }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman
> run Two My friend is happy now.
Two: [My, friend, is, happy, now.]
One: [My, friend, is, happy, now.]
One: [My, friend, Tuesday, happy, now.]
One: [I, am, stumped.]
Two: [My, friend, Tuesday, happy, now.]


Call by value means the valye is copied. 

Two's main gets an array and the address to that array is sent to One's main. 

One's main makes a copy of it. 

And later is changes it. But it changes a copy. 

So Two's main never sees the change. 

The only way One's main can change what Two's main is working with is:

  (a) keep the address (copy) unchanged

  (b) go in and change the copy of the array

The fundamental unit of compilation in Java is the package. 

The current folder is an anonymous package you work with. 

JUnit

http://silo.cs.indiana.edu:8346/c212/milestones/ch08/section_7/

--

static methods 

call by value (and call by reference) 

All programs you will design/develop from now 7/5 12:33pm must have named stages. 

Everything you did with no stages: only add stages if you have time. 

Next we discussed Nim and I played with Serena:

Adrian       Serena      Pile size: 20      
                7           13
  3                         10
                4            6
  2                          4
                2            2
  1                          1
              Lost                  
------------------------------------------- 
                         Pile size: 20      
                5           15 
  1                         14 
                7            7
  2                          5
                2            3
  1                          2
                1            1
Lost