Lecture 18, CS 302-6, October 14
i. By end of class today will have covered everything on exam
1. no 2d arrays on exam
i. Pair programming email me by EOD Saturday if you would like me to assign a partner for you to work with
i. And return values
i. Example - PassingAndReturning.java
ii. Call stack vs heap
1. Call stack where our methods go
2. Heap memory for storing arrays, etc
i. Example ArrayPassing.java
ii. The important concept here is the difference between data that is stored as a reference and data that is stored as a primitive. Integers, doubles, chars, etc are primitives you can think of the data is being stored in the variable. Arrays, on the other hand, are stored as references the variable itself only holds a pointer to the location in memory where the data is stored. That pointer is just a number referencing an address in memory.
i. (algebraic chess notation)
i. int[][] board=new int[8][8];
ii. Or, if you know the values you want to put in it:
1. int[][] board={{1,2,3},{4,5,6},{7,8,9}}
If we were to traverse and print this array, we might get something like:
1 2 3
4 5 6
7 8 9