Java, C++, and Scientific Computing

December, 1996

Advantages of Java:

Platform independence. Very important! If science is a universal language like we all say it is, why shouldn't our programs be be platform-neutral. I see no point in learning to program a GUI (Graphic User Interface) unless it is platform-independent and standard-based.

Cleaner than C++ in certain aspects. For example, I like the concept of interface. Keywords such as extends and implements make the program more readable. Automatic garbage-collection is nice too.

Competition is making Java compilers virtually free, at least if you are not interested in fancy IDE (Integrated Development Environment) or RAD (Rapid Application Development). The fact that one can get a compiler basically free is a big attraction for us poor physicists.

Java is making Microsoft sweat, which is good for the computer industry. Monopoly kills innovation. There is no question about it. Microsoft is being challenged because Java, a cross-platform computer language, has encapsulated many traditional operating system features such as GUI, networking, and thread control. Such characteristics of Java make the underlying operating system much less relevant.

The dreadful speed of Java Applets does not concern me. It is only a short-term phenomenon.

Disadvantages of Java:

Complex number is not a primitive data type. This is a big problem because

Java does not support operator overloading. The combination of these two means to add two complex numbers x and y, you need to do something like

z = Complex.add( x, y );

The expression 2*a+b*c would be something like

z = Complex.add( Complex.multiply( 2, a ), Complex.multiply( b, c ) );


z = a;
z += Complex.multiphy(b, c);

It gets worse for more complicated expressions. Obviously, people who design compilers do not seem to think that complex numbers exist or they think they are not important. C does not support complex numbers. C++ did not support it either but at least it was not as serious a problem because of operator overloading. Compare this ignorance of complex numbers with what they think about strings: In Java, operators such "+" are defined only for primitive value-types such are double. In general, an expression such as


would fail if R is of a reference type, unless it is a string of course! They have overloaded the "+" operator to infer string concatenation. In this case, 2.0 is promoted (through the toString method in class Double) to a string and concatenated with string R. Such a design may be convenient but is not very consistent.

In my opinion, it would have been nice if all the math operations including both arithmetic operators and mathematical functions were implemented as interfaces so that one could do things such as

class Complex implements ArithmeticOperations, BasicMathFunctions


class Matrix implements ArithmeticOperations, BasicMathFunctions

We can take care of the implementation ourselves or through a third-party library.


There are many things I like about Java. I just wish it was a little more science-friendly. Scientists use complex numbers and we use matrices. Give me Java + Complex + Matrices and I will make the switch overnight. The numerical extensions being proposed by Visual Numerics should help if implemented.

The big thing next century will not be so much in computer technology, it will be in using computers to solve real-world scientific problems. On this simple premise, I expect the next major computer language to be one that a scientist can enjoy. C++, with its Standard Library, is my current favorite. Java can take the lead with proper extensions.

Java Resources:

Back to Bo Gao's Home Page