Concepts of Programming Languages

(Sean Pound) #1
inheritance of classes, although some of the benefits of multiple inheritance can
be gained by using its interface construct.
Among the C++ constructs that were not copied into Java are structs and
unions.
Java includes a relatively simple form of concurrency control through its
synchronized modifier, which can appear on methods and blocks. In either
case, it causes a lock to be attached. The lock ensures mutually exclusive access
or execution. In Java, it is relatively easy to create concurrent processes, which
in Java are called threads.
Java uses implicit storage deallocation for its objects, often called garbage
collection. This frees the programmer from needing to delete objects explicitly
when they are no longer needed. Programs written in languages that do not
have garbage collection often suffer from what is sometimes called memory
leakage, which means that storage is allocated but never deallocated. This can
obviously lead to eventual depletion of all available storage. Object deallocation
is discussed in detail in Chapter 6.
Unlike C and C++, Java includes assignment type coercions (implicit type
conversions) only if they are widening (from a “smaller” type to a “larger” type).
So int to float coercions are done across the assignment operator, but float
to int coercions are not.

2.17.3 Evaluation


The designers of Java did well at trimming the excess and/or unsafe features
of C++. For example, the elimination of half of the assignment coercions
that are done in C++ was clearly a step toward higher reliability. Index range
checking of array accesses also makes the language safer. The addition of
concurrency enhances the scope of applications that can be written in the
language, as do the class libraries for graphical user interfaces, database access,
and networking.
Java’s portability, at least in intermediate form, has often been attributed
to the design of the language, but it is not. Any language can be translated to
an intermediate form and “run” on any platform that has a virtual machine
for that intermediate form. The price of this kind of portability is the cost of
interpretation, which traditionally has been about an order of magnitude more
than execution of machine code. The initial version of the Java interpreter,
called the Java Virtual Machine ( JVM), indeed was at least 10 times slower
than equivalent compiled C programs. However, many Java programs are now
translated to machine code before being executed, using Just-in-Time ( JIT)
compilers. This makes the efficiency of Java programs competitive with that of
programs in conventionally compiled languages such as C++.
The use of Java increased faster than that of any other programming lan-
guage. Initially, this was due to its value in programming dynamic Web docu-
ments. Clearly, one of the reasons for Java’s rapid rise to prominence is simply
that programmers like its design. Some developers thought C++ was simply too

2.17 An Imperative-Based Object-Oriented Language: Java 93
Free download pdf