new2 new2
WWW http://www.math.utah.edu/~beebe

Java programming

Original version: Fri Apr 26 00:41:07 2002
Last updates: Wed May 01 01:19:45 2002    Fri Jun 07 10:06:28 2002    Fri Nov 12 15:57:19 2004    Thu Aug 4 17:16:39 2005    Thu Dec 15 09:14:55 2005

This Web site collects a few modest examples of Java code, sometimes with equivalents in other programming languages.


ELEFUNT in Java

The Code & Waite Elementary Function Test Package, ELEFUNT, has now been rewritten in Java. It is accompanied by a new class library that extends java.lang.Math, and new class libraries for numeric output formatting, an area where Java is seriously deficient.

For comments on the development of the Java version, see the README file.

The complete ELEFUNT distribution (Fortran, C/C++, Java) is available in these formats:


Fun with Fibonacci

The site at the above link treats the computation of the Fibonacci sequence in 49+ different programming languages. This proves an interesting exercise, and lets one compare languages for a relatively simple numeric programming problem that requires little beyond integer and floating-point arithmetic, a while loop, and a print statement.

These programs are only a couple of steps beyond the famous Kernighan and Ritchie Hello, world exercise from their million-selling books, The C Programming Language, Prentice-Hall (1978, 1988). Nevertheless, they serve to illustrate both strengths and weaknesses of more than two dozen languages.

[Note added 04 August 2005: There is a nice collection of "Hello, World" programs in nearly 60 programming languages at http://www.cuillin.demon.co.uk/nazz/trivia/hw/hello_world.html.]

As an aside, while preparing these programs, I had occasion to consult a score of books, plus online documentation (tutorials, language reference manuals, and library reference manuals) at Web sites, and in the GNU Emacs info tree, and for some languages, I looked at numerous files with sample code.

I was very surprised to find programming language books without the words `comment', `number', and `print' in their indexes! Long before one learns about the wonderful worlds of object orientation, templates, namespaces, exception handling, fancy output filters, and symbolic algebra, one needs basic information about any programming language:

It turned out, for some languages, to be quite difficult to find answers to these elementary questions. What should have been a few minutes work (after all, the Fibonacci programs are only a score or so lines of code) sometimes took hours of searching and experimentation.

Disclaimer and background: Some of these programs could be improved, but probably not by much: they are, after all, pretty simple. I consider myself competent to expert in at least awk, C, C++, Fortran, hoc, Java, Lisp, Pascal, PostScript, and TeX, and I have written a lot of code in dozens of other programming languages (several ill-suited to numeric computation, and so ignored here). I've also written a modest amount of Maple and Reduce code, but spread out over enough years that I need to refresh my memory when I start a new project in those languages. I've read a good deal of literature (sometimes several books each) on Ada, Axiom, Matlab, Mathematica, Metafont, S-PLUS, and Scheme. I also maintain comprehensive bibliographies about several of these languages, so I have a pretty good idea about what has been written about them. However, the bc, Maxima, python, and ruby samples were my first forays into those languages. I refuse to read or write perl, but I don't mind if a program (a2p) does so.

Certainly, an exercise like this gives one a feeling about whether it is worth learning more about particular languages!