This is the lecture at 9:30am. 

There's a difference between int and Integer. 

Both are types. 

In Java there are two kinds of types:

(a) primitive types: 

int, byte, long, short, char, boolean, double, float 

(b) non-primitive, reference, user-defined types 

String, Scanner, Integer, all array types ... 

A value of primitive type fits in a box of that type. 

int a = 3;

int b = 1 + 2; 

System.out.println( a == b ); // true 

String a = "something";

String b = "something";

System.out.println( a == b ); // true if a and b point to the exact same object false otherwise 

Let's comeup with an example:

class One {
  public static void main(String[] args) {
    { String a = "something"; 
      String b = "something";
      System.out.println( a == b ); 
    }
    { String a = new String("something");
      String b = new String("something"); 
      System.out.println( a == b );   
    }
    { Integer a = 2;
      int b = 5 - 3;
      System.out.println( a == b ); // true 
    }
    
    { Integer a = new Integer( 2 ); 
      Integer b = new Integer( 1 + 1 ); 
      int c = new Integer ( 2 ); 
      System.out.println( a == c ); // true 
      System.out.println( "is " + a + " == " + b + " ? Answer: " + ( a == b )); // false
      
    }
  }
}

Arrays: 

int[] a;
a = new int[10];
a[3] = 5; 


ArrayLists:

grow and shrink automatically as you add/remove values

they also are better at being printed

however you can only store non-primitive types/values in them

import java.util.*; 

class One {
  public static void main(String[] args) {
    ArrayList<Integer> a;
    a = new ArrayList<Integer>(); 
    System.out.println( a ); 
    a.add( 4 ); // the int value of 4 is converted automatically  
    a.add( -2 ); 
    a.add( 1 ); 
    System.out.println( a ); 
  }
}

int[][] a;
a = new int[4][5];
a[1][2] = -1;

Let's come up with an example:

import java.util.*; 

class One {
  public static void main(String[] args) {
    int size = Integer.parseInt( args[0] ); 
    boolean[][] a;
    a = new boolean[size][size];
    for (int i = 0; i < a.length; i++) {
      for (int j = 0; j < a[i].length; j++) {
        if (i == size/2 && j < 3 * size / 4 || 
            j == size/2 && i > size / 4 || 
            i + j == size/2 ) {
          a[i][j] = true; 
        }
      }
    }
        for (int line = 0; line < a.length; line++) { 
      // System.out.println ( Arrays.toString ( a[line] ) ); 
      for (int column = 0; column < a[line].length; column++) {
        if (a[line][column]) {
           System.out.print( "* " ); 
        } else { 
          System.out.print( "  "); 
        }
      }
      System.out.println(); 
    }

  }
}


Here's how we initialize and work with ArrayLists to do the same thing:

import java.util.*; 

class One {
  public static void main(String[] args) {

    int size = Integer.parseInt( args[0] );
    
    ArrayList<ArrayList<Boolean>> a; // boolean[][] a;
                                     // a = new boolean[size][size]; 
    a = new ArrayList<ArrayList<Boolean>>(); 
    System.out.println( a ); 
    for (int i = 0; i < size; i++) {
      ArrayList<Boolean> row = new ArrayList<Boolean>(); 
      for (int j = 0; j <size; j++) {
        row.add( false );  
      }
      a.add( row );  
    }
    System.out.println( a ); 
    
    for (ArrayList<Boolean> row : a)
      System.out.println( row ); 
  }
}

--