18-02: Java Arrays

  1. Having multiple aliases to updatable locations with different types is unsound!
    • Disallow subtyping through arrays: B[] < A[] if B = A
    • Java fixes the problem by checking each array assignment at runtime for type correctness.

18-03: Java Exceptions

  1. When we encounter a try:
    • Mark current location in the stack.
  2. When we throw an exception:
    • Unwind the stack to the first try;
    • Execute corresponding catch.

18-04: Java Interfaces

  1. Methods in classes implementing interfaces need not be at fixed offsets;
  2. Dispatches e.f(…) where e has an interface type are more complex than usual:
    • Because methods don’t live at fixed offsets.
  3. One approach:
    • Each class implementing an interface has a lookup table method names -> methods;
    • Hash method names for faster lookup:
    1. hashes computed at compile time.

18-05: Java Coercions

  1. Java distinguishes two kinds of coercions & casts:
    • Widening always succeed (int -> float);
    • Narrowing may fail if data can’t be converted to desired type (float -> int, downcast).
  2. Narrowing casts must be explicit;
  3. Widening casts/coercions can be implicit.

18-06: Java Threads

  1. In synchronized methods, this is locked;
  2. Writes of values are atomic, except doubles (not volatile).