Object-Oriented Programming

(A.k.a. CSCI-UA.0470-001)
Fall 2012
Class: Tuesday/Thursday 2:00 – 3:15, WWH 312.
Instructor: Robert Grimm
Office hours: by appointment


Object-oriented programming is a form of “computer programming that emphasizes the structure of data and their encapsulation with the procedures that operate upon it” (Britannica Concise Encyclopedia). Basically, “an object is a software bundle of related variables and methods. Software objects are often used to model real-world objects you find in everyday life” (Sun’s Java Tutorial). Object-oriented programming is attractive because it “promote[s] greater flexibility and maintainability in programming, and is widely popular in large-scale software engineering” (Wikipedia).


To learn how to build and evolve large-scale programs using object-oriented programming.


In exploring object-oriented programming, we investigate three questions:

How do we think about a program in terms of objects? To answer this question, we explore CRC cards, UML, and design patterns.
How do we express object orientation? To answer this question, we explore classes, interfaces, inheritance, method dispatch, generics, operator overloading, and reflection.
How do we realize object-oriented primitives? To answer this question, we explore virtual method dispatch and automatic memory management in detail.

Design and primitives matter because they represent the essence of object-oriented programming. Implementation matters because it enables us to debug object-oriented programs and tune their performance.


The focus of our exploration of object-oriented programming is a translator from Java to C++. You design, implement, and evaluate your own translator as a term-long project, working in teams of four to five students. In fact, you build two versions of your translator, taking half a term for each version and presenting your work in class on completion of each version. To make the project manageable, your translator only translates a restricted subset of Java into an even more restricted subset of C++; though the second version covers more functionality than the first version. I also provide you with “helper” code, notably for parsing and pretty printing program source files.

Each group elects a speaker, who coordinates with the members of the group and with me. A new speaker is elected at the middle of the term.

Your group’s midterm and final project presentations address three main issues:

You have a 15 minute slot for your presentation, which includes a demo of your translator and time to set up your laptop.

You build a large-scale program because that is the domain with the biggest promised impact of object-oriented programming. You build a translator from Java to C++ for two reasons. First, how to translate and transform programs is a real problem and a topic of active research, including my own and that of several other researchers. Second, the translator lets us explore both Java and C++, but without a big break at the middle of the term as we switch from one language to another. You build two versions of the translator so that you can explore object-oriented programming with a real program, learn what worked and what didn’t work, and then improve on your first experiences. I expect you to clearly improve the second version; though I also expect you to reuse code from the first version. Finally, you work in teams of students for two reasons. First, it provides you with an opportunity for close interaction with your peers in the face of a shared challenge. Second, team work is the favored approach for building large-scale programs both in academia and industry.


Class is organized as part lecture and part guided discussion. I provide a gentle introduction to individual topics and techniques, usually illustrating them with the Java-to-C++ translator. Together, we discuss alternatives and the reasoning behind the techniques. Class also provides a good forum for asking questions and starting the conversation of how to meet the challenges posed by your projects.


I provide the overall structure of the course, introducing topics and techniques, sharing my experiences, and facilitating our conversation. You actively participate in all aspects of the course, sharing your ideas, questions, and concerns as well as realizing a significant project. Together, we explore how to leverage object-oriented programming to build large-scale programs.


Group Meetings

Every project group meets with the instructor every other week for an informal discussion of issues currently facing the group. Group members will probably need additional meetings amongst themselves to better coordinate their work.

Class Notes

For each class, one student takes notes, which I will edit and post on this web page. Depending on class size, we will rotate through note takers a few times. Please use this HTML template for writing up your notes.


We rely on two textbooks:

Additionally, The C++ Programming Language, 3rd or special edition, by Bjarne Stroustrup is a useful reference.

Mailing List

Please subscribe to the class mailing list csci_ua_0470_001_fa12. Be sure to email your class-related questions to this list and not just the instructor (unless, of course, they concern private rather than technical or organizational issues). Note that messages sent to this list from email accounts that are not subscribed to it will be silently discarded.

Grading Policy

Approximately: 50% for projects; 25% for homework assignments and note taking; 25% for final exams.


This course relies on three different programming languages:

In more detail, the source language is Java without nested classes, anonymous classes, interfaces, enums, annotations, generics, the enhanced for loop, varargs, and automatic boxing and unboxing. Furthermore, the source language omits support for synchronization, i.e., synchronized methods and statements, and strict arithmetic operations, i.e. the strictfp modifier. It also omits support for transient and volatile fields as well as native methods. Finally, you may omit method overloading but not method overriding for the first version of the translator.

The target language is C++ without virtual methods, inheritance, and, in general, templates. It also omits features new to C++11, notably lambda functions and type inference, e.g., auto and decltype. It does, however, include gcc's statement expressions, i.e., ({ … }). When compared to C, the target language does include support for basic classes, exceptions, and name spaces. For the first version of the translator, you can ignore memory management and assume an infinite main memory. For the second version of the translator, you need to automatically reclaim unused memory through a so-called smart pointer. The smart pointer library, as well as any library support for implementing Java arrays, may use templates.

Most Java statements and expressions translate directly into the corresponding C++ statements and expressions (modulo minor language differences). As a result, the main challenges for the course project are figuring out (1) how to translate Java class hierarchies into C++ without inheritance and (2) how to implement Java’s virtual method dispatch in C++ without virtual method dispatch, (3) how to select the right overloaded method, and (4) how to automatically manage memory without an existing garbage collector. Note that we will explore how to approach each challenge in class; we will also leave the latter two challenges for the second version of the translator.

Besides the programming language itself, any version of Java includes a rather extensive set of platform libraries, with the facilities in the java.lang package being tightly integrated with Java’s execution model. For our translator, we only support the hashCode(), equals(), and toString() methods in java.lang.Object and the printing of numbers and strings through out.print() and out.println() in java.lang.System. Furthermore, we do not support the dynamic loading of Java classes, but rather translate all Java classes of the source program into one C++ program.

Please note that the translator need not perform any correctness checks on source programs; in other words, you can assume that source programs are free of compile-time errors. At the same time, when writing your own Java test programs, it seems prudent to test them with a regular Java compiler.


Please be sure to regularly check this page for updates.

Sep 4
Introductions — to the course and to each other. Slides.
Sep 6
Our first Java class: a four-dimensional point.
Sep 11
Our first C++ class: a four-dimensional point.
Sep 13
Designing our translator: CRC cards and UML at work.
  • Read OODP chapters 2 and 3 before class.
  • Notes.
Sep 18
Tools of our trade: make, version control, and xtc.
Sep 20
Q & A on design and tools.
Sep 25
Inheritance, method overriding, and virtual method dispatch.
Sep 27
Implementing inheritance and virtual method dispatch by hand.
Oct 2
Q & A on inheritance and virtual method dispatch. Notes.
Oct 4
Object-oriented design revisited. Notes.
Oct 9
All about arrays, incl. how to translate Java arrays into C++. Notes.
Oct 11
Generics: a better translation of Java arrays into C++. Notes.
Oct 16
Fall recess. No class.
Oct 18
Traversing graphs: the visitor design pattern. Calculator.java. Notes.
  • Read OODP chapters 5 and 10 before class.
Oct 23
Q & A on generics and the visitor design pattern. Notes.
Oct 25
In-class midterm project presentations.
Oct 30
Frankenstorm. No class.
Nov 1
Frankenblackout. No class. — You may want to read OODP chapter 7 anyway and explore xtc.tree.Visitor with last year's notes as a guide. You are not responsible for this material on the final exam.
Nov 6
Will the real method please stand up? Method overloading in Java. Notes.
Nov 8
Operators are methods: operator overloading in C++. Notes.
Nov 13
Q & A on method and operator overloading. Notes.
Nov 15
Explicit memory management in C++: the Law of the Big Three. Notes.
Nov 20
Smart pointers in C++: a reference-counting garbage collector in (little more than) one screen of code.
Nov 22
Thanksgiving. No class.
Nov 27
The casts of C++: hurling our smart pointer from type to type.
Nov 29
Q & A on explicit memory management and casts. Notes.
Dec 4
Traits and iterators in C++.
Dec 6
Performance considerations: getting it done versus getting it done quickly. Notes.
Dec 11
Q & A — the object-oriented programming potpurri.
Dec 13
In-class final exams. Study guide.
Dec 18
2:00 – 3:50, WWH 312. Final project presentations.

Tools and Resources

For Java, we use the Java 2 Platform Standard Edition 5.0, née JDK 1.5, or later. Oracle provides an implementation for Linux. Apple provides an implementation with Mac OS X, no installation required. In either case, you need to separately install Java’s API documentation. In the case of Mac OS, the documentation is included with Xcode, Apple’s IDE.

For C++, we use gcc, the GNU Compiler Collection, as our compiler. It is the default compiler for Linux and included with Apple’s Xcode for Mac OS X.

If you are running Windows, please dual-boot into Linux or use a virtual machine monitor such as as VirtualBox for running Linux. Trying to make gcc and make work on Windows (i.e., through a Unix emulation layer such as Cygwin) is an exercise in pointless pain and suffering.

Like many large-scale software projects, we rely on a version control system such as git to manage program sources and on make to automate the build management. If you are using github or a similar service, please make sure that your repository is not publicly visible.

To simplify the task of reading source files in one language, translating them into another language, and then printing source files for that language, we use the xtc toolkit for source-to-source translators. xtc includes a parser for Java source files, which converts the external, textual representation into an internal tree representation. It also includes support for traversing, modifying, and pretty-printing such trees.

You may also find the following resources useful: