Why Use Java?
These sections list some of the main reasons why Java is a much better implementation
language for your applications compared to C++. The C++ language, while being the
overwhelming language over the last decade, has a number of very serious design
flaws which make debugging and maintaining large scale systems written in C++ very difficult.
In short, the language was overhyped and most people adopted it for no better reason than
that was what everyone else was using.
The fact is that today C++ is becoming an out-dated language, and the alternatives of
some of the more modern languages provide programmers with a great deal more support
to improve productivity and reliability.
Here we list some of the advantages that the new Java programming environment has over
C and C++ ones. (The list is not exhaustive, and other critiques of C++ exist on the net).
The list is given in what Lingasoft consider to be the most important to least important
advantages (though it of course depends on a customers situation).
- Reliability
Probably the single biggest flaw in C/C++ is the ease at which memory can be corrupted,
often by obscure and difficult to find bugs. Extensive use of pointers and arrays mean
that is very easy for the stack or HEAP storage to become overwritten. But the worst
problem with this kind of bug is that the program may not crash until sometime later,
usually in perfect parts of the code that crash simply because their part of HEAP memory
has become corrupted by an earlier problem. In these cases the programmers have no idea
where the problem occurred, and (especially if it happens in released production software),
there is a tendancy to shrug the shoulders and say "lets wait to see if it happens again,
shall we".
In Java this kind of overwriting of memory cannot occur, the language and its
environment simply do not allow for it. Address of operators have been removed from the language,
so a program can not simply write to any memory address it wishes to, and all writes
to arrays are run-time checked, with a run-time exception thrown should an illegal array
index be used. Casting is type safe and run-time checked too, another big problem area in C++.
What all this adds up to is a massive improvement in program reliability. Our experience in
implementing applications in Java is that they simply never crash, and if an error does
occur (such as accessing an illegal memory address) an exception is thrown and reported.
This means that the error is reported exactly where the problem in the program is, rather
than crashing in a much later, working part of code. This reduces the time required to spot
and fix the bug by a huge margin, and even errors that come from production environments are
meaningful and can be found.
- Productivity
Java programs can do the same as C++ programs in fewer lines of code. One of the biggest
reasons why this is the case is that Java provides automatic garbage collection. Our experience
with C++ programming has shown considerations of why and how to free up unneeded objects can
add considerably to the amount of code required, and can often be the cause for bugs. This is
especially true for multi-threaded programming, where one must be sure no other thread will
try to access some object after it is freed in another thread. Java programmers do
not worry about these issues, saving many lines of code and debugging time.
Java does not require the use of seperate header files like C++, which reduces duplication
of effort (i.e. having to repeat function prototypes in the header and module) and removes
the potential for error. This lack of need for headers further decreases the amount of code
a Java programmer needs to write. The javadoc tool (see section on documentation below) means
that a programmer can easily view an objects interface without having to look at its
implementation.
- Portability
Many people think the only real advantage Java has over C++ is that it runs on any platform
with a JVM (Java virtual machine). Not surprisingly, this is the advantage Sun Microsystems
tend to concentrate on. We think it is important, but we place it below other advantages
(see above) for most customers, many of whom have other reasons for sticking with just one
platform (ease of administration, or third party software availability). However if developing
software to run on several platforms (such as a software vendor), the portability is a huge
benefit, massively reducing the time and maintenance effort of providing programs (especially
graphical ones) on all platforms they sell to. As the Linux operating system continues to
rise in popularity, this portability advantage is likely to become even more important.
- Maintenance
For all the reasons mentioned above, and in the simplicity advantage discussed below, systems
written in Java are much more maintainable, which reduces your costs as your systems mature
and need enhancing. As programmers come and go, ease of maintenance is a big issue. Often new
bugs are introduced as the requirements or loads of an existing system are changed (the classic
case is when a statically allocated array which used to be just the right size later becomes
too small as another part of the system changes). Because of Java's robustness, these problems
are spotted much earlier and in the correct place in the code.
- Available Libraries in the Standard Enviroment
By JDK 1.2 the available classes the programmer has available for his or her use in the standard
delivered environment is very large. There are not only classes for graphical operations,
but there are also ones for networking and dealing with collections, plus many others. The
set of graphical components are now much richer than those provided by OSF/Motif
(e.g. Table and Tree widgets), and also somewhat cleaner and better designed than those provided
by the MFC (Microsoft Foundation Classes), such as support for the Model View Controller design
concept.
Contrast this library by the one provided by the Standard C++ library. This has classes for
Strings, I/O and collections, but precious little else. Other classes can be obtained from
third parties, but it is surprising how many people do not bother to obtain these.
In short the Java programmer has much more functionality available to him or her. This
reduces the amount of code they need to write. C++ programmers tend to have to continually
reinvent the wheel in so many areas where useful utility libraries could have been provided.
- Simplicity
Although Java was designed after the C++ language, it actually is much simpler. Many of the
redundant or poor features from C++ were not incorporated into the Java language, such
as automatic implicit type conversion, overloaded operators and templates.
C++ has been developed over many years and has become an extremely complex language,
especially during the time it was becoming a standard. Quite honestly, it has become a very
bloated programming lanuage that takes a thick book to describe completely. It is filled
with several ways
of doing the same thing, often as a result of maintaining compatibility with the C language.
Features such as namespaces were added later, but look and operate like an afterthought
bolt on, and are nowhere near as simple and easy as the Java package concept.
Java's simplicity makes its programs more readable and easy to understand. All the bad and/or
redundant features have been removed, while making it possible to do all the same things as
C++ in an equal amount or less code.
- Self Documentation which remains up-to-date
In Java, useful documentation on the code and its interfaces can be easily produced using a
tool known as javadoc. Here special comments are added in the source code itself, and then
the tool produces HTML documents for each class, describing the provided public functions of
the class, and inserting the special comments into the code. This provides an easy way of
producing quality code maintenance documentation, an area of documentation normally lacking in
large C++ systems (programmers nearly always hate writing documentation). Because the
documentation is generated from the source code, it is always up-to-date. We have often
had experience with Word documents written about program interfaces in C++, usually before
or just after a class is implemented. These documents however quickly become out of date
when the class is further developed, and very rarely do people go back to update the Word
document to reflect these changes.
This list includes just some of the advantages Java has over C++. There are others.
Quite simply the C++ language now represents yesterdays technology for yesterdays development
environments. The availability of much stronger alternatives such as Java means that
there are now very compelling reasons not to choose C++ when starting new developments. In
addition, especially since Java syntax is largely based on that of C++, there is a huge
temptation to convert at least some existing C++ legacy applications to the Java language,
especially for systems which will need considerable changes in the future and where reliability
and maintenance are very important factors.