1 of 7

CS/COE 0401

Midterm Review & Lab 6

Wednesday 11:00 AM Session (10827)

1

CS/COE 0401 Intermediate Programming in Java

CS/COE 0401 Intermediate Programming in Java

2 of 7

Midterm Review

  • Types
    • int: 0, 1, 2, -1, 2, ...
    • boolean: true/false
    • double/float: 0.12, 2.0, Math.PI
    • char 'a', '1', ' '
    • String "abc", "123", "" (empty string)
    • Arrays (T[]) [1, 2], [1.12, 2.0], []
  • Compare & Contrast
    • Compiler v.s. Interpreter
    • Interpreted v.s. Compiled Language

2

CS/COE 0401 Intermediate Programming in Java

3 of 7

Midterm Review

  • Compare & Contrast
    • Literals v.s. Variables
    • Case-Sensitive v.s. Non-Case-Sensitive
    • if, if ... else, switch ... case (break!)
    • for, for-each, while, do-while
    • = v.s. == v.s. equals()
    • Class v.s. Instance v.s. Object
    • Property v.s. Method
    • Public v.s. Private
    • Static v.s. Regular

3

CS/COE 0401 Intermediate Programming in Java

4 of 7

Array

  • Declare an array of type T: T[] arrOfT;
    • Examples:
      • array of integer (int) - numbers:
        1. int[] numbers;
      • array of string (String) - lines:
        • String[] lines;
  • Initialize an array of type T with size N: new T[N];
    • Examples:
      • initialize numbers as an array of 5 integers (int):
        • numbers = new int[5];

4

CS/COE 0401 Intermediate Programming in Java

5 of 7

Array (continues)

  • Consider integer array
    • numbers = new int[5] {3, 1, 4, 15, 9};
  • Indexes (or if you prefer, indices)

  • To access elements in the array, we use their indexes.
    • To get the 2nd element (4), we use: numbers[2]
    • Note: we count from 0 to N-1. The Nth element doesn’t exist.
  • To get the size of an array, we use its property length.
    • int sizeOfNumbers = numbers.length;

5

0 1 2 3 4

CS/COE 0401 Intermediate Programming in Java

6 of 7

DEMO

6

CS/COE 0401 Intermediate Programming in Java

7 of 7

Time to try

  • Write your Lab 6 program (follow instructions on course website).
  • Slides can be found at zacyu.com.
  • Your will until the beginning of the next lab to demonstrate your Lab 6 program to me to receive full credit.

7

  • Good luck on your midterms :)

CS/COE 0401 Intermediate Programming in Java