Java compared to C++ (1996)

C++ is a programming-language developed at AT&T Bell Laboratories in the early 1980s by Bjarne Stroustrup. It is an evolution of the C programming language. Two major advantages of C were its simplicity of expression and speed of execution, nowadays most of the programming languages have these two. C++ also has these two and extends C in three important ways:

  1. It provides support for creating and using data abstractions
  2. It provides support for object-oriented design and programming
  3. It provides various nice improvements over existing C constructs

C++ is widely available and is in wide use for real application and system development. Within six months of its intitial release from AT&T in late 1985, there were commercial ports of C++ available on over 24 systems, ranging from PCs to large mainframes. Since then, more ports have been made, and C++ is now available directly from many computer vendors. In 1988 the first native compilers were produced for the PC and workstation markets. Additionally, large-scale libraries and program support environments have begun to appear.

The future of C++

The language is still undergoing some changes. But changes mean most of the times more additions to the language, which have made the language so disorderly in the past years. In C++ one can program in a neatly object-oriented style, but mind the bold word "can" !!! Now that Java has been released and many C++ programmers discover the similarity in programming-style while offering great robustness, I think C++ might become the biggest victim of the growing popularity of Java.

But in computerland nothing can be predicted: so let's just wait and see if C++ will survive.

Characteristics compared

In the following table, some important characteristics of C++ and Java are mentioned. In that way C++ and Java can be compared more easily. Here they are:

JAVA properties C++ properties
Java does not contain a template class facility. That means that an object cannot store data of an arbitrary other data-type. C++ supports the use of template classes. Although compiling them does take some work sometimes (for example with the gnu-compiler), it works good and offers more flexibility.
A program written in Java can run - after compilation - on multiple platforms and operating systems without any changes. The Java interpreter takes care of machine dependent properties. A program written in C++ has to be compiled for the platform and operating system it has to run on. Sometimes even the source-code has to be altered because of machine dependent properties.
Java supports multi-threading: tasks can run simultaneously. Critical data is protected (no need for semaphores, a way of manually protecting critical data for processes) and nothing tricky about it: it is a standard feature of Java. C++ does not support something like multi-threading. Of course, something comparable can be accomplished using extra libraries or really low-level programming (not every programmer will agree at this point, but I think it is at a lower level than it should be ... like in Java) but protection of critical data must be done manually, which is a lot more work, as the entire programming-process is in C++ (compared to Java of course).
Java was designed to be Object Oriented from the bottom-up. This means that there exists only one kind of pointer-references to objects, that the way of programming is much more consistent and that the OO-way of programming is not artificial, as is the case with C++. C++ is an evolution of the classical programming language C. C was a great programming language for its time, but nowadays it is hopelessly old-fashioned. C++ has all the features of C with the necessary additions to offer the possibility of object-oriented programming: this means that the OO-way of programming is accomplished in an artificial way (for example: C++ classes are translated internally to the C struct-type). Another result of all this is that in C++ programming can be done in different ways, which is certainly not consistent. Last but not least: objects can be referenced to with pointers, references or as local which makes it all very confusing.
Java programs can be run using the Java interpreter. Although this causes Java programs to be runnable on multiple platforms and operating systems, it also makes them generally slower during execution. C++ programs must be compiled for the system they are going to run on. This means that a compiled program can run only on a system compatible with the system for which the program was compiled. But it also means that a C++ program runs faster during execution, because compilers for specific systems have special optimization steps which makes the programs faster.
Inheritance is one of the most crucial concepts in object-oriented programming. It means that only differences from some other class have to be specified for a new class. Java supports single inheritance: each class can have only one superclass (although any given superclass can have multiple subclasses). The designers of Java made the choice to let Java only be singly inherited to make inheritance simpler. C++ supports multiple inheritance: classes can have more than one superclass, and they inherit combined variables and methods from all those classes. Multiple inheritance can provide enormous power in terms of being able to create classes that factor just about all imaginable behavior, but it can also significantly complicate class definitions and the code to produce them.
Java applications fall into two main groups: applets and applications. Applets are Java programs that can be integrated in HTML WWW-pages: they are downloaded over the World Wide Web and executed by a Web browser on the reader's machine. C++ programs actually cannot be compared to Java programs when we're dealing with this subject: C++ never was designed for something like the World Wide Web! When you want to add more to a WWW-page, C++ can be used for minor calculations but certainly not for the things Java can do.

Wow! That was quite a list about Java and C++! I hope you have a little impression of the properties of Java and C++ and the differences between them now.

How do you feel now?

I hope you that you are not as bored now as I was when I read this page for the first time after I had made it. But I don't know how to make it more entertaining: perhaps programming is only meant for boring nerds (not personally if you enjoyed reading this...).