- 作者:zhaozj
- 发表时间:2020-12-23 11:03
- 来源:未知
Java as a Scientific Programming Language (Part 1): More Issues for Scientific Programming in JavaBy Ken Ritley
Java was designed as a modern, object-oriented programming language. Its features such as platform-independence, ability to manage libraries, threads, etc. are important for modern scientific programs. These are good reasons for a scientist to choose Java.
But Java was developed without the specific needs of scientists in mind. This means that in some respects scientists must exercise a bit of creativity and patience.
For the scientist thinking about migrating to Java, there are many important issues to consider. What follows is a useful list of some of them.
Complex Numbers
Java, like C, does not support an intrinsic complex number type.
For those who may not know, a complex number (say, c) is simply an ordered pair of two numbers (say, a and b), which obeys some very simple rules of arithmetic.
The fundamental equations which describe almost everything in the universe — from weather systems to black holes to the way in which tiger populations depend on how many rabbits they eat — are based on complex numbers, not ordinary numbers. Scientific programs have to be able to handle complex numbers efficiently, and scientific programmers have to be able to code complex formulas easily.
It's actually straightforward to "patch" Java's lack of a complex number data type. One can use a class (let's call it Complex) with two member variables (say, realC and imagC), and separate public methods for all the needed arithmetic operations (addition, subtraction, etc.).
But there a few problems with this. One problem is such programs may be more inefficient, because the Java compiler will be forced to create a new object for each instance of a complex number. For loops with hundreds of thousands of iterations, use of an intrinsic complex data type is obviously much faster.
Further, instead of being able to code a simple complex number equation such as c3=c1*c2,Java forces the scientist to code it, for example, such as c3=complexMultiply(c1,c2). This means the complex number "patch" class must be distributed with each Java program, and depending on how these classes are implemented and defined, Java library subroutines may not easily integrate with one another.