Suppose you have a set of two-letter words and their definitions. You want to be able to look up the definition of any word, very quickly. The two-letter word is the key that addresses the definition.
- May 9, 2018...more
Encapsulation
May 9, 2018...moreA module is a set of methods that work together as a whole to perform some task or set of related tasks. A module is encapsulated if its implementation is completely hidden, and it can be accessed only through a documented interface.
Exceptions
May 8, 2018...moreEXCEPTIONS
When a run-time error occurs in Java, the JVM
throws an exception,
prints an error message, and quits. Oddly, an exception is a Java object (namedException
), and you can prevent the error message from printing and the program from terminating bycatching
theException
that Java threw.Programming Efficiently
May 7, 2018...moreGenerics, Conversion, Promotion
May 7, 2018...moreComing up Next: The Syntax Lectures
In the next three lectures, we’ll build an
Array
based implementation of aMap
, and along the way, learn some new syntax.- Autoboxing, promotion, immutability, generics
- Exceptions, Iterables/Iterators
- Access control, equals, other loose ends
- Wildcards, type upper bounds, covariance (not in the scope of the class).
Java Packages
May 6, 2018...moreJAVA PACKAGES
In Java, a package is a collection of classes and Java interfaces, and possibly subpackages, that trust each other. Packages have three benefits.
Java Libraries & Abstract Classes
May 5, 2018...moreSubtype Polymorphism vs. HoFs
May 4, 2018...moreSubtype Polymorphism
The biggest idea of the last couple of lectures: Subtype Polymorphism
- Polymorphism: “providing a single interface to entities of different types”
Extends, Casting, Higher Order Functions
May 3, 2018...moreComplexity: The Enemy
When building large programs, our enemy is complexity.
Some tools for managing complexity:
- Hierarchical abstraction.
- Create layers of abstraction, with clear abstraction barriers!
- “Design for change” (D. Parnas)
- Organize program around objects.
- Let objects decide how things are done.
- Hide information others don’t need.
- Hierarchical abstraction.
Equals() & Testing
Apr 29, 2018...moreequals()
Every class has an
equals()
method. If you don’t define one explictly, you inheritObject.equals()
, for whichr1.equals(r2)
returns the same boolean value as "r1 == r2", where r1 and r2 are references. However, many classes override equals() to compare the content of two objects.