CS 477 Lecture Notes

Week Thirteen, Thursday: Early Project Demonstrations

Homework Assignment

Worth 10 points, due Thursday, week 14, 1999, in class:

Write a one-page (exactly) essay on your term project team experience. What was good about it? What was bad about it? What could be done next year to improve things to make the experience more relevant and valuable? Use this format: 12 point times font, one-and-a-half spaced lines. Use one half line above and below justified non-indented paragraphs (block style). One inch (+/- 1/8 inch) margins all around. One point off for each error in formatting. This will be the last homework assignment for the semester.

Demonstration Agenda

This time is available for any team that wants to get its demonstration out of the way a week early.

Java: A Case Study in Software Engineering

This lecture is based on the Epilogue (p. 483) in Software Engineering with Java.

Java was created by James Gosling to overcome the reliability and security shortcomings of C++. The portability, security, and robustness of Java make it a case study in software engineering.

Java and Modularity

Java is a pure object-oriented language (does not support functions or procedures) so its modularity is in the form of classes. Java allows classes to be grouped into packages:


A Java product can be divided into packages
assigned to individual programmers.

Java packages provide another layer of abstraction with its own level of visibility (scope).

Multiple Inheritance
Multiple inheritance is occasionally necessary, but it can make software extremely complicated and difficult to understand. Java does not support multiple inheritance, but its "interfaces" provide the major benefit of multiple inheritance without the drawbacks.

Java and Structured Programming

Java does not suport goto, but this issue is a bit of a red herring. I have never seen goto used in any C or C++ program in practice. It's a bit like saying that a dog is superior to a human being because a dog is incapable of being disloyal.

Java and Portability

Portability is an important issue. C and C++ code is just as portable (theoretically) as Java code because all you have to do is port a compiler to the new machine. In practice however, porting is not so easy. X-Window programs for example, are hard to port to Wintel because of the vast differences in the Windows API and X-server.

Java programs have finally fulfilled the promise of portability which can be demonstrated easily by running this applet in Wintel and Macintosh simultaneously.

The performance of Java programs is usually worse by a constant factor (5 to 10) than a comparable program written in C or C++. However, if performance were the most important criterion, we would all be coding in assembly language. For those applications where performance is critical, Java code can be translated to C code with the java2c program and compiled natively with an optimizing C compiler. A properly designed optimizing compiler will unroll loops move functions inline without the programmer having to worry about it.

Java does not support memory leaks like C and C++ do. The Microsoft Foundation Classes (MFC) still have memory leaks five years after they were first reported.

Java and Security

Viruses (and other malevolent code) frequently use pointers to access restricted address space. This is not possible in Java. As the world grows more connected, computer security will also grow in importance. Applets implement additional safeguards for security.

Java and Reliability

Java is a strongly typed language. C++ supports strong typing, but because it is compatible with C, it does not enforce it. One of the most weakly typed languages is Visual Basic, which can lead to some extremely sloppy coding habits.

Java has array bounds checking. A common source of bugs in C and C++ code is referencing memory beyond the end of an array.

Java's absence of memory leaks also enhances its reliability.

Java and Object Orientation

As mentioned above, Java is a pure object oriented language. However, that doesn't mean it can't be used in a structured paradigm way. Object oriented design requires knowledge and discipline to achieve the advantages of the object oriented paradigm.

Java and Reusability

Java does not support templates. However, interfaces, and the ability to pass the top Java class, Object, and cast it to the desired type, effectively implements the template capability. Java.util.Vector is an example.

Java and Visibility

The access specifiers of Java are a little more convoluted than those of C++, but C++ has the "friend" specifier that can make code more confusing. The scope (visibility) levels of Java are summarized in the table below:

Visibility Level Description Key Word
Public Access from anywhere in the product. public
Protected Package visibility (see below) plus: a subclass in a different package can inherit attributes inherited from its superclass (but cannot access attritutes of instances of the superclass). protected
Package Access from anywhere in the package in which it is defined. <null>
Private Protected Access from within an instance of the class in which it is defined plus: access from within instances of subclasses. private protected
Private Access from within an instance of the class in which it is defined. private

Note that package level visibility is the default if no attribute specifier is used. These rules apply to both attributes and methods.

Java: Language of the Web

The various communications protocols (TCP/IP, HTTP, sockets, UDP, etc.) can be used in many languages. The Berkeley Socket library, for example, is written in C. The Java.net package provides convenient access to many Internet and Web protocols.

Java is enhanced as the "language of the Web" by its features such as reliability, security, and portability. However, "Java is the language of the Internet because it was well designed from the start, not because it was specifically designed for Internet use. In other words, Java is indeed a case study in software engineering."


This page established April 8, 1998; last updated January 18, 2000.