COP-3338, Programming III Lectures
- Aug 29: Opening remarks and Java basics
- Remarks PDF slides
- Basics PDF slides
- Examples of C++ nonsense that can never happen in Java
(writeup by Cay Horstmann)
- In Java, if you step outside of the bounds of an array, the
VM will signal a problem. In C++, you might run for a while without a problem.
- In Java, the garbage collector will never reclaim an object while it is still usable. In C++,
you clean up yourself, and you can delete an object
while it is still usable, resulting in unpredictable behavior.
- In Java, objects are never created on the stack, so pointers
cannot go stale. Not so in C++.
- In Java, the compiler is required to perform a conservative flow analysis
to make sure that local variables are definitely assigned prior to use of their
values.
Not so in C++,
which can get you into oodles of trouble, especially when pointers
are uninitialized.
- Java is very type safe. C++ is not.
- A host of C++ pitfalls
just do not happen in Java (one does have a corresponding Java pitfall though).
- Aug 31: Classes
- Sep 5 and 7: Inheritance, Exceptions, and Interfaces
- Sep 12 and 14: The Object class, Reflection, and the Proxy Pattern
- Object class PDF slides
- Reflection PDF slides
- Examples
- Illustration of the correct way to override
equals, hashcode, toString,
and clone
ObjectDemo.java
- Illustration of using reflection to invoke main
InvokeMain.java
- Using accessible fields to get private data
Spy.java
- Illustration of the proxy pattern.
Shows generation by hand, generation by using Java 1.3 dynamic proxies,
and an approximation of what
the dynamic proxy is actually producing for you behind the scenes
TestProxy.java
- Sep 19: I/O and the Decorator Pattern
- PDF slides
- Examples
- Program to copy from one file to another, with line numbering
NumberLines.java
- Program that uses StringTokenizer to parse a line of input into two ints
MaxTest.java
- Program that uses File class to get information about a directory and its contents
FileSystem.java
- Sep 21: The Collections API and the Iterator Pattern
- Sep 26 and 28: Inner Classes
- PDF slides (revised 9/26/00 9PM)
- Examples
- SortedArrayList class illustrates the use of
instance inner classes for iterators
and nested classes too
SortedArrayList.java
- A nonsense demo that illustrates how to construct
inner objects from outside the outer class,
name clashes with locals, inners, and outers, and also
shows how the compiler generates wrappers to access private
outer class members.
- Series of programs that show the moving of a function
object closer and closer to its use.
Program uses
Rectangle.java
and
Comparator.java
from interfaces lecture.
- Oct 3 or 10, 12 and 17: Threads and Synchronization
- Because of the weather, part I is Oct 3 3:30PM OR Oct 10 5:00PM.
- PDF slides
- Examples:
- Illustrates basics of getting threads to run:
ThreadDemo.java
- Illustrates threads corrupting data:
NoSync.java
- Series of examples using an Account.
Some threads do deposits, some do withdraws on shared account.
- Two examples with multiple monitors
- Static methods have different monitors than instance methods:
StaticsAndThreads.java
- Oct 19: Networking
- Oct 24 and Oct 26: Server-side Programming
- Oct 31 and November 2: Swing and Applets
- Nov 7 and (a little of) 9: Serialization
- Nov 14, and 16: Programming in C
- Nov 21: Native Methods in C and C++
- PDF slides
- Examples
- Hello World:
HelloNative.java,
HelloNative.h, and
HelloNative.cpp.
- Visual C++ setup
-
To compile:
cl -GX /GR -IC:\jdk1.3\include -IC:\jdk1.3\include\win32 HelloNative.cpp -LD -FeHelloNative.dll
- Accessing fields of Date class:
Date.java,
TestDate.java,
Date.h, and
Date.cpp.
- Accessing methods of Date class:
Date.java,
TestDate.java,
Date.h, and
Date.cpp.
- Accessing strings in Date class:
Date.java,
TestDate.java,
Date.h, and
Date.cpp.
- Using arrays:
NativeSumDemo.java,
NativeSumDemo.h, and
NativeSumDemo.cpp.
- Using exceptions:
NativeSumDemo.java,
NativeSumDemo.h, and
NativeSumDemo.cpp.
- Creating a Java VM from C++:
ReadMe.txt,
InvokeHello.cpp, and
Hello.java.
- Nov 28: JDBC
- PDF slides
- This class will be held on the same day as evals, since there is not much material
- Examples
- Nov 30: Java 1.2 Security Basics: Permissions and Policy Files, Code Signing
- Another whiteboard lecture, with a few examples.
- Dec 5: Introduction to RMI
- Dec 7: Class will not be held