knowledge-kitchen

Exam 3 Review - Intro to Computer Science

Intro to Computer Science

  1. Exam Structure
  2. Prior Knowledge
  3. Inheritance
  4. Polymorphism
  5. Interfaces
  6. Abstract Classes
  7. Exceptions and Errors
  8. Recursion
  9. Conclusions

Structure

Overview

The exam will take place during class time. It will be composed of two parts:

  1. Google Form Quiz (40%)
  2. GitHub Assignment (60%)

Accepting the Exam

Students must accept the exam by…

  1. Clicking the link provided by the instructor to the Google Form.
  2. Clicking the link provided by the instructor to the GitHub Assignment, and following the instructions therein to “accept” the assignment.

Submitting the Exam

Students must submit the exam by the end of the exam period.

  1. Click the Submit button on the Google Form.
  2. push the GitHub Assignment code to GitHub.

Verifying Your Submission

Students must verify on your own that you have actually submitted the exam.

  1. See the confirmation message on the Google Quiz after clicking submit.
  2. Click the link provided by the instructor to the GitHub Assignment, and verifying that your code has been pushed to the repository.

Prior Knowledge

Cumulative by nature

By nature of the material, the exam will include what was tested previously. So you would be wise to brush up:

Inheritance

Overview

We now know there are multiple types of inheritance in Java:

Polymorphism

Overview

The reference to an object is of a different type than the object’s declared type.

Mammal barstein = new Human("Foo", "Barstein");

Reference types

Polymorphic references can be of:

Polymorphic references can not be of:

In practice

In many cases, polymorophism is practically applied when it is convenient to do batch processes on a bunch of objects that share a common ancestor. In such situations, we place those various objects into some sort of collection (array, ArrayList, etc) that is typed as the ancestor class or interface that all the objects share in common.

//say you have a bunch of Mammals
Mammal[] mammals = {
    new Human("Foo", "Barstein"),
    new Dog("Fido"),
    new Mouse("Minnie")
};

//do some kind of batch process on all these Mammals
for (Mammal mammie : mammals) {
//do some things all Mammals can do, regardless of their declared type
mammie.tickle();

    //do some things only a particular declared sub-type of Mammal can do
    if (mammie instanceof Dog) {
        ((Dog) mammie).bark();
    }

}

Interfaces

Overview

Interfaces are a reference type that provide a form of inheritance, similar to classes, but with some key differences in purpose and implementation. Interfaces are often named with words ending in the [https://en.wiktionary.org/wiki/-able#Suffix suffix, “able”]].

Raison d’être

Interfaces are used to impose a contractual obligation on classes that they implement a particular set of methods with specific signatures. Why might this be useful?

Limitations

Interfaces can contain only:

All methods and properties in an interface are public.

In what case are default methods useful?

Abstract classes

Overview

Like interfaces, abstract classes can contain abstract methods and provide a form of inheritance. In what cases are abstract classes preferable to interfaces? To concrete classes?

Raison d’être

In what case are abstract classes preferable to interfaces?

Limitations

Unlike interfaces, abstract classes can contain any sorts of properties and methods. Thus, they are in many ways similar to concrete classes. However…

Unlike concrete classes, abstract classes…

Exceptions and Errors

Errors

Errors are irremediable failures that are usually due to external factors outside the scope of your code

Exceptions

Exceptions represent known problematic situations that can potentially be handled in code by one of two means:

Exceptions are represented in code as objects of various classes that extend Exception class.

Recursion

Overview

Methods that invoke themselves. A form of iteration, but different from loops.

Classic examples

The classic pattern: handle the base case, and then recurse on the remainder. Examples:

Termination

The recursion must terminate somehow in order not to trigger a stack overflow error. How does it stop recursing?

Conclusions

Thank you. Good luck!