PrefaceWhat is Java? Why use Java? Why Buy this Book? Acknowledgements
What is Java?
Java is an important new programming language, designed by a team at Sun Microsystems. Many of you will have heard of it in the context of the Internet, which is where it made its initial impact. Sun started developing Oak, the forerunner of Java, in 1990. Java was released in 1993 and has grown from nothing to become widely accepted as one of the world's most important programming languages. All major web browsers now support Java and companies such as Microsoft and Apple are already building support into their operating systems. Many of the new Network Computers will run little other than Java programs.
At present, Java is usually thought of as a means of embedding fancy graphics or interaction into web pages. However, it is capable of much more than this. In fact, it is a language comparable to any other: Fortran, C, C++, Pascal or Modula-3. It provides all of the standard language constructs that you would expect and a standard library which goes beyond what any of these provides. It is available on most systems: Windows, Macintosh, Solaris, Linux and many others, including almost all varieties of UNIX.
As you will see later in this book, Java is capable of matrix manipulation, RSA encryption, computing pi and all of the other types of computation that a scientific programmer might want to perform.
Why use Java?
If you already know another language or are trying to decide which to learn then you are probably thinking something like `OK, so Java can do everything that more traditional languages do, but why should I choose it in particular?'
From the point of view of the scientific programmer, Java has several advantages:
In addition, if you are involved in any kind of teaching then Java provides two further benefits.
Why Buy this Book?
Java has made such an impact on the programming community that bookshops are currently flooded with books on the subject. The vast majority of these cover exactly the same ground. They are designed for corporate programmers: people who intend to write flashy graphical additions for web pages, standard business applications or networking software. As such, these books discuss the entire standard library, concentrating on issues such as graphics, user interface design and networking. In addition, these books tend to assume quite a high level of expertise and most of the popular titles, such as Java in a Nutshell (Flanagan, 1997), assume knowledge of C/C++ and familiarity with object orientation.
This book is different. It is aimed at the scientific programmer and at the increasing number of science students who are being taught Java as their first language. As such, the focus is different and discussion of issues such as user interface components is almost entirely omitted. Indeed, this book makes no attempt to cover the entire standard library. Instead we concentrate on those parts which will be of use to you. For example, the library supports arbitrary precision arithmetic. Most other books would relegate this to an aside. Here, however, this is the second part of the standard library that we discuss (following on from the standard mathematical functions), and we follow our discussion by implementing RSA (large prime number) encryption.
In addition, unlike other Java books, our examples perform the kind of computations that a scientific programmer will be interested in. This book is not intended as a systematic source of good numerical algorithms - the programs are intended to illustrate language features. However, all of the examples perform a scientific computation of some sort and there are brief introductions to more serious numerical algorithms, software engineering and physical modelling in the second part of the book. These introductions are directed towards students who have not encountered these subjects before. We also include a description of Visual Numerics' `JNL, a Numerical Library for Java' and a simple library of our own, `JSGL, a Scientific Graphics Library for Java', to handle graphical output for you so that you do not need to learn the full structure of Java graphics. Both of these libraries are intended for professional numerical work. The JSGL will run on all platforms that support Java, in contrast to most other graphical systems and languages in which you must rewrite your code to switch platforms.
This book has a fast track for those who already know C/C++, which are superficially similar, and also a more elementary introduction for students who have done no previous computing. Whichever category you are in, I have tried to provide an easier introduction to the subject than many other books on Java. No knowledge of any particular programming language is assumed, nor is any familiarity with object orientation.
I should like to thank Professor Brian Davies, who acted as my scientific advisor, ensuring that the style did not get too technical and suggesting some of the examples. I should also like to thank Daniel Andor, Alan Bain, Tobias Berger, Sarah Clelland, Andrew Kanaber, Tom Oinn, Andrew Serjantov and Chris Webb, students at Cambridge University who acted as my proof-readers and Drs Tim Cutts, Andrew Gee and Robert Hunt, members of staff with whom I had useful conversations. I must stress, however, that it is of course the author alone who is responsible for any errors in the final draft.
Richard J. Davies