Do you remember the big-bang in C211? 

(define initial empty)

(define (render world)
  (empty-scene 400 400))

(define (nothing world)
  world)

(define (meh world x y event)
   world)

(big-bang initial
          (to-draw render)
          (on-tick nothing)
          (on-mouse meh))

Can we do as much in Java? 

Let's start as follows:

import java.util.Scanner; 

public class One {
  public static void main(String[] args) {
    Scanner a = new Scanner(System.in); 
    System.out.println( a ); 
  }
}

This prints:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run One
java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match valid=false][need input=false][source closed=false][skipped=false][group separator=\,][decimal separator=\.][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\Q?\E][infinity string=\Q?\E]


This doesn't look like the big-bang. 

import javax.swing.JFrame; 

public class One {
  public static void main(String[] args) {
    JFrame frame = new JFrame(); 
    System.out.println( frame ); 
  }
}

This produces:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run One
javax.swing.JFrame[frame0,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,title=,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,0x0,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]


I modify this to: 

import javax.swing.JFrame; 

public class One {
  public static void main(String[] args) {
    JFrame frame = new JFrame(); 
    // System.out.println( frame ); 
    frame.setVisible(true); 
  }
}

I modify it further to:

import javax.swing.JFrame; 

public class One {
  public static void main(String[] args) {
    JFrame frame = new JFrame("World"); 
    // System.out.println( frame ); 
    frame.setVisible(true); 
    frame.setSize(400, 400); 
  }
}

Now it looks like the other one in DrRacket. 

I hope I convinced you that this abstraction

    javax.swing.JFrame

is meaningful. 

Let's see how this kind of abstractions get written. 

Java programs are made out of classes. 

A class is a container. 

It contains: methods (functions, procedures) and variables.

These methods and variables are called members. 

Members can be static and non-static. 

Static members are available as soon as the class is available. 

They should be accessed through the class. 

Here's One a class that has everything in it:

public class One {
  public int x; 
  public static int y;
  public int fun(int x, int y) {
    int answer = x + y; 
    return answer; 
  }
  public static int nuf(int x, int y) {
    int answer;
    answer = x + y; 
    return answer;
  }
}

Here's how I work with static members from One:

public class Two {
  public static void main(String[] args) {
    System.out.println( One.y ); // prints 0 (zero)
    One.y = 5; 
    System.out.println( One.y ); // prints 5
    System.out.println( One.nuf(5, -2) ); // prints 3
    
  }
}

To get to work with instance (non-static) members you need to 
do some work first. All instance members belong to a blueprint.
You can instantiate that blueprint and get an object. You can do
that zero, one or more times and get an object every time. Each
one will have the same structure (instance members in it). They
are created according to the vision the blueprint is. 

Instance members should be accessed through the reference to the
instance that they belong to. 

public class One {
  public int x; // instance variable 
  public static int y;
  public int fun(int x, int y) { // instance method 
    int answer = x + y; 
    return answer; 
  }
  public static int nuf(int x, int y) {
    int answer;
    answer = x + y; 
    return answer;
  }
}

And this is an example on how I can work with it:

public class Two {
  public static void main(String[] args) {
    // at this point no x or fun is available 
    One a = new One(); 
    System.out.println(a.x); // prints 0 (zero)
    a.x = 3; 
    System.out.println(a.x); // prints 3
    System.out.println( a.fun(6, 1) ); // prints 7  
    One b = new One(); 
    System.out.println(b.x); // prints 0 (zero)
    b.x = -2;    
    System.out.println(b.x); // prints -2
    System.out.println(a.x); // still prints 3
    System.out.println( b.fun(2, 3) ); // prints 5          
  }
}

Now I am going to start modeling. 

http://www.cs.indiana.edu/classes/a202-dger/sum2010/zo.pdf

So I start modeling in the simplest way: 

class Student {
  
}

It looks empty, it is not. It has an empty blueprint. 

I instantiate it:

public class Two {
  public static void main(String[] args) {
    Student tori = new Student(), molly, ivy; 
    molly = new Student();
    ivy = new Student(); 
    System.out.println( tori ); 
    System.out.println( molly ); 
    System.out.println( ivy ); 
  }
}

It prints info showing the objects are unique: 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run Two
Student@2598af8d
Student@4c4ddcbb
Student@750d03ba


So I improve my modeling as follows: 

public class Two {
  public static void main(String[] args) {
    Student tori = new Student(), molly, ivy; 
    tori.name = "Tori"; 
    molly = new Student();
    molly.name = "Molly"; 
    ivy = new Student(); 
    ivy.name = "Ivy"; 
    System.out.println( tori.name ); 
    System.out.println( molly.name ); 
    System.out.println( ivy.name ); 
  }
}

This runs as follows:

Final stage in our efforts today:

public class Student {
  public String name; 
  public void talk() {
    System.out.println( "Hello, my name is " + name ); // what about our convention of accessing name through the reference to the object it belongs to?  
  }
}

public class Two {
  public static void main(String[] args) {
    Student tori = new Student(), molly, ivy; 
    tori.name = "Tori"; 
    molly = new Student();
    molly.name = "Molly"; 
    ivy = new Student(); 
    ivy.name = "Ivy"; 
    tori.talk() ; 
    molly.talk() ; 
    ivy.talk() ; 
  }
}

Look over this for next time 

http://www.cs.indiana.edu/classes/a202-dger/sum2010/zo.pdf

Also I will post some slides for Wednesday to use. 

--