else's data. Java placed necessary constraints around pointer use for sig-
nificant gains in security and stability.
Poor memory management in C ++ . Java is a “garbage-collected” lan-
guage, which means that the memory management is much more auto-
matic. Where each object in C++ must be explicitly allocated and freed,
Java objects can be automatically removed from memory when the last
reference to them is removed. Chapter 6 will show us that we still have
to pay cursory attention to Java memory management, but the issues
are much less complex and absorb much less time.
Problematic multiple inheritance. C++ programmers had a difficult time
with multiple inheritance , or inheritance from more than one parent.
For example, a person could be a customer and also a father. When
frameworks got complicated, programmers had a difficult time deter-
mining which methods were inherited from which parent. Many a mas-
ters thesis was written on the C ++ diamond inheritance problem, an
artifact of C++ multiple inheritance. Java addresses this problem by
allowing only single inheritance. Interfaces can still be used to imple-
ment classes with more than one characteristic.
Runtime type errors in Smalltalk. Java is strongly typed, so programs
have fewer instances of runtime type errors. The compiler can catch
many instances of type collisions.
Frustration with the proliferation of compiler directives. Includes, defines,
and typedefs were convenient at times but difficult to manage. In C ++ ,
cascading include files were very difficult to maintain, understand, and
debug. Java forbids include files, and it does not have compiler directives.
Though Java has its own set of problems, it did address some significant com-
plaints of C++ and Smalltalk programmers. It is a fine example of the industry
looking at the antipatterns of a technology and then solving them with an
improved technology. Languages and standards layers can play a role in anti-
pattern development. Frequently, the development process will play a larger
role in the antipattern life cycle.
Java allows us to take significant steps forward from its predecessors. The
capabilities of the language and libraries are improving rapidly. But a language
in itself is only a tool. It cannot protect us from major antipatterns. The meth-
odologies and procedures that we define to employ the tool have a much
larger bearing on success or failure.