Cs2 Midterm Review

UML Shapes Assignment

  • Due Friday of this week
  • Think about how things were structured in MineSweeper
  • yay

Project Euler Examples / Notes

Problem 3

  • We start with a number too big to fit in an int, use a long instead.

Problem 10

  • just use the Sieve, and use longs because ints are too small.

Problem 12

  • need a routine that will give you for any number its factors.
  • probably within the long range.
  • remember that it's asking for 501 divisors.

Problem 13

  • Use Big Integers
  • since they're too big to fit in longs, you may have to write your own addition routine to add ascii.
  • You might be able to just use doubles, and hope that the high-order digits fit within the range of doubles.

Problem 26

  • probably should skip this one.
  • write your own division routine to draw out the numbers, and then look back after a while to find any repition.

Exam Characteristics

  • Closed-computer
  • Closed-book
  • As many handwritten notes that you want
    • must have been written by yourself

Things to know for Midterm

  • Primitive Object Types
  • Classes and Objects
    • Difference b/t class and object

String, StringBuffer

  • String vs. StringBuffer
    • Mutability: Strings are immutable; once they are created, they can't be changed. Similar to Arrays. Has profound consequences on speed. StringBuffer (StringBuilder) is a mutable Object type; you can add on to it.

Streams

  • Concept of streams
  • difference b/t print, println, printf

Interfaces

  • Command line applications
    • "main" method and its arguments
  • keyboard input via Scanner
  • Applets vs. Gui applications

Path and Classpath

  • Path: a set of directories used by the OS to find executable files.
  • Classpath: A set of directories used by the Java VM to find classes.
  • Classpath and package declaration

Constructors

  • Constructors
    • Constructor overloading
    • Default constructors
    • Default actions for uninitialized variables
    • Calling constructors from constructors (using this)

Getters, Setters

  • Getters
    • functions to get properties of an object
  • Setters
    • Functions to set properties of an object

Overloading

  • Method signature

    • Name, type & number of params
    • NOT return type
  • Automatic type conversion in overloading

Arrays

  • Stored together in memory
  • Array syntax:
double[] temperature = new double[7];
  • resizing an array (NOT allowed)
  • Array length: A.length
  • Array range: 0 to A.length-1
  • Default values for array variables

Array Loop Types

  • be sure to know both normal for loops, and the "enhanced" for loops.

Big O notation

  • What does O(n) mean?

  • What does O(n2) mean?

Multidimensional Arrays

  • Arrays of Arrays
  • Row-major order, by convention
  • Nested loops to process arrays
  • Finding neighboors of an array element
  • Higher-dimensional arrays
int[][][] threeDimensions = new int[4][4][4];
  • ragged arrays

Inheritance

  • extends keyword
  • super keyword
  • What happens to public, private, protected methods and variables?
  • Terminology
    • Superclass -> sublcass
    • Parent class -> child class
    • Base class -> derived class
    • Class hierarchy
    • Is-a vs. Has-a relationships

Overriding

  • Overriding vs. Overloading
    • Overriding comes from superclass
    • Overloading uses same name but different signature.
  • calling "super" in a constructor:

Casting

  • Fine:
Undergraduate U = new Undergraduate();
Student S = U;
  • Error:
Student S = new Undergraduate(); // fine
Undergraduate U = new Student(); // ERROR

Abstract Classes, Interfaces

  • Abstract Classes
    • Allows creation of base class that does not implement any functionality.
    • Serves as placeholder
    • make it simple to derive classes
    • Assures compatible functionality to use in Polymorphism.

Polymorphism

Graphical User Interfaces

  • JFrame and Japplet
  • JOptionPane
  • Components
    • Jlabel
    • Jbutton

Events and Listeners

  • Event - listener model
  • Registering as an event listener
    • ActionListener

Exceptions

  • Throwing exceptions
  • Catching exceptions
    • exception handler
  • Try block

  • checked exceptions vs. unchecked

    • checked require a try-catch block
    • unchecked do not, examples: ArrayIndexOutOfBoundsException, ArithmeticException, NullPointerException