Java Reference
In-Depth Information
program in local machine code. This was a particular problem in the early days
of Java, and its slow performance led many who experimented with Java to
drop it.
Fortunately, more sophisticated JVMs have greatly improved Java perfor-
mance. So called Just-in-Time compilers, for example, convert bytecode to local
machine code on the fly. This is especially effective for repetitive sections of
code. During the first pass through a loop the code is interpreted and con-
verted to native code so that in subsequent passes the code will run at full native
speeds.
Another approach involves adaptive interpretation, such as in Sun's Hotspot,
in which the JVM dynamically determines where performance in a program is
slow and then optimizes that section in local machine code. Such an approach
can actually lead to faster performance than C/C
programs in some cases.
Here are some other problems in applying Java to technical programming:
++
No rectangular arrays -Java2Darrays are actually 1D arrays of references to other
1D arrays. For example, a 4 × 4 sized 2D array in Java behaves internally like a single
1D array whose elements point to four other 1D arrays:
A[0] ==> B[0] B[1] B[2] B[3] B[4]
A[1] ==> C[0] C[1] C[2] C[3] C[4]
A[2] ==> D[0] D[1] D[2] D[3] D[4]
A[3] ==> E[0] E[1] E[2] E[3] E[4]
The B, C, D, and E arrays could be in widely separated locations in memory. This differs
from Fortran or C in which 2D array elements are contiguous in memory as in this
4
×
4array:
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)
Therefore, with 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 when the calculations require multiple operations on large arrays.
No complex primitive type - Numerical and scientific calculations often require imag-
inary numbers but Java does not include a complex primitive data type (we discuss the
primitive data types in Chapter 2). You can easily create a complex number class, but
the processing is slower than if a primitive type had been available.
No operator overloading -For coding of mathematical equations and algorithms it
would be very convenient to have the option of redefining (or “overloading”) the defini-
tion of operators such as “ + ” and “ - ”. In C ++ , for example, the addition of two complex
number objects could use c1+c2 ,where you define the + operator to properly add
such objects. In Java, you must use method invocations instead. This lengthens the code
Search WWH ::




Custom Search