Algorithms and OOD (CSC 207 2013F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [IRC] [Teaching & Learning]
Current: [Assignment] [EBoard] [Lab] [Outline] [Partners] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Overview
What simple tests?
{ }
{ "sam":"rebelsky" }
{ "samr" : { "fname":"Sam", "lname":"Rebelsky", "ryphot":0 } }
What do we return?
Mostly dictionary-like thingys
Also arrays of those
You might create MyJSONObject and MyJSONArray
Memory associated with your program has three parts
Sample code!
public class Counter {
static int operations = 0;
int counter;
void increment() {
++Counter.operations;
++this.counter;
} // increment()
void decrement() {
++Counter.operations;
--this.counter;
} // decrement()
int get() {
++Counter.operations;
return this.counter;
} // get()
} // class Counter
public class CounterExpt {
public static void main(String[] args) {
Counter c1 = new Counter();
Counter c2 = new Counter();
Counter c3 = c1;
c1.increment();
c2.decrement();
c3.increment();
System.out.println("ops: " + Counter.operations);
System.out.println("c1: " + c1.get());
System.out.println("c2: " + c2.get());
System.out.println("c3: " + c3.get());
System.out.println("ops: " + Counter.operations);
} // main
} // class CounterExpt
Why doesn't this code do what we expect?
// Replace a tree by its right subtree
tree = tree.larger;
It doesn't work because it's pointer assignment (see whiteboard)
Is there a *tree = *tree.larger in Java? NO
We also can't explicitly get the address of something.
Why do we not allow such assignments?
*left = *right, right have more fields than left.Code
class Foo {
int x;
}
class Bar extends Foo {
int y;
}
Foo foo = new Foo();
Foo bar = new Bar();
*foo = *bar; // What does this really mean?
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [IRC] [Teaching & Learning]
Current: [Assignment] [EBoard] [Lab] [Outline] [Partners] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Copyright (c) 2013 Samuel A. Rebelsky.

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.