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 wests in Mind. This Means That In Some Respects Scientists Must Exercise A bit of create and patience.
For the scientist thinking it
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 EfficIntly, and Scientific Programmers Have to Be Aable 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.
This also breaks the Golden Rule of Programming, that well-written programs should be easily understandable by people. As we'll discuss in Part 2, in a scientific program it's perfectly acceptable and even desirable to use variable names such as e, m, and c - because those are exactly how scientists write E = mc2 But by forcing such nice equations like c3 = c1 * c2to be written with notation like c3 = complexMultiply (c1, c2) means that they become harder to debug and more prone to! Errors.
Just for Fun, Here's A Snapshot of a Scientific Programmer's Nightmare (See the Sidebar "Scientific Program").
Scientific Programs Should be Understandable by Scientists Imagine a scientific program, which may have DOZENS of formulas that look similar to the example above In Fortran, the equation looks like this:. Vp = CSQRT ((1-v ** 2 / c ** 2) / (1-V / c)) But in Java, IT Might Look Like this: VP = ComplexSqrt (ComplexSubtract (1, ComplexDivide), ComplexPow (C, 2)))) , ComplexSubtract (1, Complex (V, V, C)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))); However, The Java Version Won't Give The Right Resuls A Scientific Program with dozens of these formulas? - KR
But not to worry: The language C also lacks an intrinsic complex data type, and this has not stopped scientists from writing programs in this language There are some standards for managing complex numbers, and there's even hope that the makers of Java will see! fit to include complex numbers as a future extension of the language. The Precision Problem The same Java program will give the same results on all systems. But ... will they be the right results? For business applications, Java's arithmetic and mathematics offer certainly enough accuracy. But for some applications, the IEEE 754 standard is actually a constraint. for example, if a hardware platform offers more than the required precision and Java insists that numbers be rounded, then not only may accuracy sacrificed but also execution speed. for Those Who Are Interested, Here Are Some Details of How Java Handles Numerics, More Details, And Even More Details! The Prospective Scientific Java Program Should Rest Easy on this i ssue: for the majority of the scientific community, IEEE 754 is enough and these "constraints" are likely to be unimportant The IDEs of March Wander the halls of any scientific research institution and you'll see the same problem played out in many offices. :. to write and run Fortran or C program, a scientist will TELNET to a remote workstation (! even a very slow machine) That's where command-line compilers and ASCII text-editors live, and those are the only programming tools a scientist may Know. The program output is life ftp '
d back to the PC, where it is plotted and analyzed - frequently not without trouble because of linefeed / carriage-return differences The whole procedure is then repeated until the scientist's fingers start to bleed It's a very sad loss of productivity since, say.. , the late 1980s, when a good scientific laboratory might have run a single VMS-based DEC system, loaded with all the tools a scientist needed. The problem, of course, is not that the productivity has dropped, merely the relative productivity. Many scientists trained before about 1990 have never taken the time to explore the new tools available to programmers. Today, new scientists grow up with PCs in the home and they learn about these new scientific programming tools in college. in fact, scientific courses at universities are CHANGING AS A Results Take Note: Modern Programs Are Written by Modern Program Using Modern Ides. An IDE (Integrated Development Environment) Is A User-Friendly Shell Which Wraps The Editor, Compiler, Debugger, And Output Window Into One User-Friendly Package [please See Debugging in Java: Techniques for bug eradication
]. "I do not have the time to learn a specific new gadget" is a common excuse among some scientists. But really, it's no excuse because IDEs are as universal as CD players. There's a box to put the source code, buttons to click on to compile, start and stop it, and a little output window that shows what's playing nevertheless, a scientist needs to exercise caution IDEs bring with them a new set of problems -.. compatibility problems - because they may combine highly-portable source code with nonportable library functions or files. For Java the sitution is not so bad. Because all aspects of the Java language are standardized, graphics included, very little effort is required to write IDE-independent source code. We'll discuss this in more detail in Part 2. The User-Interface Issue Be they theoretical results from a numerical simulation, images from a microscope, or else experimental data points with errorbars -. scientific data needs to be seen to be understood There are excellent For tran and C compilers for every type of machine, and these languages are almost completely portable -.. except for graphics Because graphics and GUIs are an intrinsic part of Java, they also enjoy "write-once, run-anywhere" status This includes basic tools for setting up GUIs with windows and boxes and buttons, as well as advanced tools for image processing (such as the Java advanced Imaging JAI classes). and because of Java's popularity, the scientist new to Java will find the Internet full of free tools And Source Code for Visualizing Data, Plotting Equation, Analyzing Images, etc.
The Hardware Problem in the Scientific Laboratory Scientists working at the European Synchtrotron Radiation Facility (ESRF) in Grenoble, France, know the problems that mixed-hardware environments create. The ESRF is one of over 30 multi-billion-dollar laboratories worldwide that provide scientists with access to an intense beam of x-rays. It's here where molecular biologists unravel the atomic structure of proteins, physicists explore the basic properties of matter, materials scientists synthesize new materials, and physicians design new methods to combat cancer. Scientists from around the world travel here to perform experiments at the ESRF, which exclusively uses Unix-based workstations and software to control the experiments and collect the data. But upon returning home to analyze their data, many of these scientists either prefer or else need to use tools only Available on PCS. There Are Some Solutions To Help Bridge The Hardware Gap, But UnTil Now Scientists Have Always Been Forc Ed To Chose One Platform for Writing New Software, Then "Damage-Control" The Consequences. - K.R.