Instructors' Guide


Introduction Terminology Expressions Control Objects Inheritance Technology Summary

Terminology

In comparison with C++, Java is almost as rich in keywords. Notably lacking, however, is the keyword virtual. This is not needed, since in Java every method is by definition subject to dynamic dispatching. Also, since Java doesn't allow multiple inheritance, there is no need to use it for avoiding multiple copies of inherited base classes.

Keywords:

Java overview


Language features:


slide: Java -- terminology (1)

New is the keyword interface in Java. Defining an interface is equivalent to defining an abstract class in C++. One merely lists the methods provided by the (abstract) claas, without providing an implementation. A concrete class may then indicate that it implements the interface. In this way multiple (interface) inheritance is supported in a nice and clean way.

Also new is the keyword synchronized, reflecting the built-in support for concurrency in Java. A synchronized method excludes multiple invocations of that method, which might otherwise occur in a multi-threaded program.

The keyword final may be used to indicate that a particular value may not be changed. In this sense it is similar to the C++ keyword const. It must be noted that Java is even more elaborate in the use of the keywords private, protected and public than C++. They are used to indicate access restrictions for the methods of an object for objects inside and outside the package in which the objects' class is defined. The language features offered by Java resemble those of C++. However, in many respects Java is much simpler than C++. Most notably, the absence of pointers, a sure source of errors, makes programmers' lives easier. In particular since Java offers automatic garbage collection, programmers need not to worry about disposing objects created dynamically. Resource management, however, may be done by defining a method finalize. The counterpart, however, of that is that all objects in Java come into existence by explicit dynamic creation.

The availability of interfaces compensates for the restriction to single inheritance, which must be indicated by the keyword extends instead of the colon. It has often been argued that multiple inheritance is not really necessary. This holds true, however, only for implementation inheritance. Multiple (interface) inheritance is a powerful feature that has interesting applications once one has discovered how to use it.