Pitfalls to Avoid: Here are things to do and concepts to keep clear + read and follow *all* instructions *and* comments! + assignment is "destination = result", *not* "result = destination" + $==$ versus $=$ + $return$ versus $print$ + *declaration* versus *assignment* versus *instantiation*: $int x;$ versus $x = y;$ $Person p;$ versus $p = q;$ versus $new Person(...)$. $int[] a;$ versus $a = b;$ versus $new int[] { 2, 3, 4 }$. + values versus non-values: + methods can return only values + variables can contain only values + objects are not values + references to objects are values + variables are not values + there are never references to variables + (re)initialize variables in an inner loop: incorrect: // try to print sum of each row: // i = next row to process, j = next column to process in row i --> sum = 0; for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) sum += a[i][j]; System.out.println(sum); } correct: // try to print sum of each row: // i = next row to process // j = next column to process in row i // sum = sum so far of row i = sum of a[i][..j-1] for (int i = 0; i < a.length; i++) { --> sum = 0; for (int j = 0; j < a[i].length; j++) sum += a[i][j]; System.out.println(sum); } + write a specification-comment for each method, briefly explaining *what* the method does in terms of all its parameters, but usually not explaining *how* the method does it. + write a loop "invariant" or "storyline" for loops, briefly explaining what the loop does in terms of its variables (see example above). often a clear picture is a good idea. this is to help both you and us understand the code. + inheritance: when choosing which implementation of a method to run, *always* start searching from the specific class of the *object*, *not* from the declared class of the reference. + visibility with inheritance: what is visible to a method depends on its *implementation-specific* class, *not* the specific class of the object. + instance versus static methods, e.g. method $overlap$ on Prelim 3. + Matlab indices start from 1, Java indices start from 0