Object Oriented Programming in Java

Module [M09] - Generics

With this module, we go back to fundamental OOP tools offered by the Java language. This time, we will explore more advanced OOP concepts than in the first part of the course.

  • Textbook Reading Assignments
  • The following sections of the textbook are assigned for this module.
    • Chapter #19 – Generics

Module Learning Outcomes

In this module, you will develop further your programming skills as follows;

Tracing
Ability to read and trace Java programs leveraging Generics.
Implementing
Ability to write Java programs leveraging Generics.
Testing
Ability to develop tests for Java programs leveraging Generics.
Debugging
Ability to troubleshoot Java programs leveraging Generics.
Designing
Ability to design Java programs leveraging Generics.

These lecture recordings should go a bit more in-depth than the reading assignments. Use them to supplement the readings and go back to them after watching the videos. You should have a few questions to post on the forums :)

  • Lecture - Intro to Generics
  • Video Link: YouTube Slides: PDF
  • We start with an overview of the motivation behind generics. As is usual for longer videos, here are links to the main parts;
    • [00:17] Module Overview
    • [04:12] Suggested Readings - Please note two things;
      • Even though the slide says "mandatory" readings, these are entirely optional in this course
      • We are using a different textbook this semester
    • [07:41] What are Generics?
    • [22:30] What are Generic Types?
    • [49:24] Raw Data Types
  • Lecture - Generic Types with Multiple Type Parameters
  • Video Link: YouTube Slides: PDF
  • Nothing very difficult here, we are just showing how the concept of generic type generalizes.
  • Lecture - Generic Methods
  • Video Link: YouTube Slides: PDF
  • In addition to Generic Types, Generic Methods are the second Java construct in which we are able to inject Type Parameters.
  • Lecture - Generics & Inheritance
  • Video Link: YouTube Slides: PDF
  • Generics hold some surprises for us when we try to combine them with inheritance and polymorphism.
  • Lecture - Bounded Type Parameters
  • Video Link: YouTube Slides: PDF
  • We introduce a way to restrict the kind of Type Arguments that may be passed as Type Parameters to a Generic Type or Generic Method.
  • Lecture - Bounded Type Parameters vs. Polymorphism
  • Video Link: YouTube Slides: PDF
  • Sanity checks are always a good thing. No need for an inception-style spinner though here. We are just going to ask ourselves whether this new technique we just learned about is something that we could have done without all along.
  • Lecture - Type Inference
  • Video Link: YouTube Slides: PDF
  • Lecture - Type Erasure
  • Video Link: YouTube Slides: PDF
  • As is usual for longer videos, here are links to the main parts;
  • B01 - Re-implementing GenericStack
  • This exercise is #19.1 in the 10th edition of our text.
  • B02 - Generic Maximum-Finding in 1D Arrays
  • This exercise is #19.5 in the 10th edition of our text.
  • B03 - Generic Maximum-Finding in 2D Arrays
  • This exercise is #19.6 in the 10th edition of our text.
  • B04 - Every day I am shuffle-in
  • This exercise is #19.8 in the 10th edition of our text.
  • B05 - ArrayList Sorter Method
  • This exercise is #19.9 in the 10th edition of our text.