Here we list some of the shortcomings that Java has
with regard to science and engineering applications:
- Performance Limitations
Several features
of Java that make it a powerful and useful language, can also
slow it down unfortunately, especially for mathematical calculations.
The interpretation of bytecode,
which makes Java programs so easily portable, causes a hit on
performance as compared to running a program compiled directly
to local machine code.
Other features, such as no direct access to pointers and
array limit checking, make the code safer but can also
lower performance.
The more advanced VM's, like those with Just-in-Time (JIT)
compilers that convert bytecodes to local code, can greatly ameliorate
these problems.
For intensive mathematical processing, however, it will be difficult
to achieve performance levels of C or Fortran. In such cases,
it may be advantagous to use Java for the graphical user interface
and for its other capabilities like networking, but
interface to the C/Fortran program such that it becomes
the calculation engine inside the Java body.
- No Rectangular
Arrays
Java 2-D arrays are actually arrays of 1-D arrays:
Java:
A[0]
==> A[0][0] A[0][1] A[0][2] A[0][3]
A[1] ==> A[1][0] A[1][1]
A[2] ==> A[2][0]
A[2][1] A[2][2] A[2][3] A[2][4]
A[3] ==> A[3][0] A[3][1] A[3][2]
Fortran or C:
A(0,0)
A(0,1) A(0,2) A(0,3) A(0,4)
A(1,0) A(1,1) A(1,2) A(1,3) A(1,4)
A(2,0) A(2,1) A(2,2) A(2,3) A(2,4)
A(3,0) A(3,1) A(3,2) A(3,3) A(3,4)
For the Java arrays, moving from one element to the next requires
extra memory operations as compared to simply incrementing a pointer
as in C/C++. This slows the processing if the calculations require
mulitiple operations on large arrays.
- No Complex Primitive
Type
Many numerical & scientific calculations required imaginary
number processing but Java does not include a complex primitive
(i.e. built into the core language) type.
You can easily create acomplex class but the processing is slower
than if a primitive type were available.
- No Operator Overloading
In C++ operators such as "+"
and "-"
can be redefined so that when they operate on objects of particular
classes they perform user defined operations. For mathematical
formulas this is very helpful. Unfortunately, operator overloading
is not available in Java yet.
- Inline code &
Dynamic Binding
Optimization of C/C++ for high performance numerical processing
often involves replacing a call to a function with the code itself,
especially for short functions. This inlining saves the time of
jumping to the function location.
Java normally loads classes as they are needed. This dynamic binding
normally means that the latest compiled bytecode is always employed.
Java optimization can do inlining but, in this case, if the function
is in another file and the function is altered, the inlined code
will not be changed unless the code is recompiled.
- Floating Point
Variations
The early versions of Java provided only 32 or 64 bit FP
regardless of whether the host machine provided for greater precision.
This was so that the JVM gave exactly same result on all machines.
However, as of Java 1.2, implementations can use wider exponent
representations if allowed on the platofrm. The keyword modifier
strictfp
forces the FP calculations to follow the standard precision
operations. See Chapter
2: Tech: More about Floating Point for lots of details about
FP in Java.
Latest update: Dec.10.2003
|