Internet commentary

Kybernetes

ISSN: 0368-492X

Article publication date: 1 March 2002

62

Keywords

Citation

Andrew, A.M. (2002), "Internet commentary", Kybernetes, Vol. 31 No. 2. https://doi.org/10.1108/k.2002.06731bag.001

Publisher

:

Emerald Group Publishing Limited

Copyright © 2002, MCB UP Limited


Internet commentary

Keywords: Computer programming, Computer languages

Abstract: The programming languages Java and JavaScript are described. JavaScript allows the writing and running of programs on a modern PC using only standard software. Programs in Java can be run by any Java-enabled browser, but free software has to be downloaded to allow the origination of new programs. Java is an extremely powerful "state of the art" object-orientated language.

Java and JavaScript

A frequent complaint about modern home computers and the standard software that comes with them is that they do not allow computing as it used to be understood, with the user able to write and run his or her own programs in a language such as Basic or Fortran or Pascal. It is easy to feel there is a case for bringing out and dusting off an old Sinclair Spectrum which would use a television set as its display and would run programs in Basic.

In fact, though, the modern PC as usually supplied does provide the means of writing and running one's own programs, though the facility is certainly not stressed, and probably not even mentioned, in the literature that comes with the computer. JavaScript can be used without acquiring any further software whatsoever and it has the nice feature that programs can be sent to other people by e-mail or made available on a website.

JavaScript and Java are not the same, though they have features in common. Java is by far the more powerful of the two. In order to write programs in Java it is necessary to install extra software, but everything needed can be downloaded free of charge.

There are of course other ways of persuading a standard PC to provide a programming facility. Compilers for various languages can be purchased but are usually rather expensive, though one for the C language can be downloaded flee from: <http://www.cs.virginia.edu/~1cc-win32/>. Also, the Lotus SmartSuite package supplied with many home computers allows the use of LotusScript which is a comprehensive language geared to interacting with components of Lotus applications. There is however good reason to stick with Java and JavaScript which, besides being available free, are likely to remain popular for a long time to come. JavaScript is designed to be used in conjunction with HTML so is an integral pan of much web software, and Java has many important advantages and is widely seen as the "state of the art" in programming.

JavaScript

The JavaScript language is essentially Algol-type, although like Basic and Fortran it uses the plain equals sign for assignment. It then has to use a double equals for the Boolean test of equality, a convention that is difficult to keep in mind while typing. Strange program behaviour can result if a single equals is

inserted by mistake and the unintended assignment is made when the program runs. Details of the language can be found in an introductory text such as that of McBride (1997b).

Since it can only be run by a web browser, the program must be in an HTML document. Such a document can be created using FrontPage Express, and then the program can be inserted (with the deletion of some unnecessary text inserted by FrontPage Express) using a text editor such as WordPad. Then double-clicking on the icon of the document causes it to be opened by the browser and, if there are no errors, to run as a program.

To modify the program it is not necessary to shut down the browser and explicitly open the text editor. A right-click with the mouse somewhere in the display area produces a menu box in which one of the choices is: "View source", and this allows the HTML document to be viewed and edited using Notepad. Once the edited version has been saved, and Notepad closed, the program can be made to rerun by clicking the "Refresh" button of the browser.

It is usual, but not necessary, to put function declarations in the "head" part of the HTML document, where the main program is in the "body" part. Since many intriguing results are obtained by the use of recursion in functions, I tested JavaScript for this, and found it worked perfectly, and even allowed mutual recursion in which a function A is called within a function B, and B within A.

Interesting programs are shown by McBride (1997b) including one to play noughts-and-crosses and he also refers to a number of websites where further programs can be found, some of them maintained by enthusiasts for the language. An example of its use, which can illustrate the essentials of its application to numerical problems, and related to a paper submitted to Kybernetes, can be found at: <http://pages.britishlibrary.net/alexandrew/simpson.htm >.

Java

Unlike JavaScript, which is run interpretively, Java requires a compiler. This converts the program to run on a "Java virtual machine" that has been implemented on many different actual machines. The compiler, and an enormous amount of other software constituting "class libraries" is available from Sun Microsystems at: <http://www.javasoft.com/ >. With a standard modem it takes about two hours to download. The total contents, when downloaded and unzipped, constitute a "Java developer's kit", and they occupy a folder called jdkl. 1 for the version described by McBride, or with a higher version number for later downloads.

Although a great many books deal with the Java language, most are rather vague about the practical details of getting started. The clearest explanation I have found is in McBride (1997a) but even there some details are glossed over. The trouble is that the Java compiler runs in the unfamiliar DOS environment, not in Windows. It is first necessary to create a short DOS batch file called gojava.bat, and this can be created within Windows, using either Notepad or WordPad, and the suffix ".bat" ensures that the file is of the required type. When called within DOS this allows the Java system to find the compiler and class libraries in the jdk folder. The user's source programs should also be placed in this folder, preferably in a subfolder within it..

A confusing point, not made entirely clear even by McBride, is that although the DOS batch file can be created using Notepad or WordPad, it is not possible to create the files to hold source programs in the same way. These files have the suffix ".java", which is recognised only by the Edit facility within DOS. Once the files have been created, however, their contents can be edited using Notepad or WordPad, which are much more convenient than the DOS editor for the insertion of long programs. Wright (2000) seems to assume that it would all be done using the DOS editor exclusively, which is feasible but tedious. (The necessary frequent switches between Windows and DOS do not entail restarting the computer. Among the entries in the Windows "Program" menu there is an MS-DOS Prompt that allows quick entry to DOS.)

Java programs are termed "classes" and if there are no errors the compiler produces a file with the same name as the original "java" file but with the subscript "class", and this can run under DOS. However, if the program defines an "applet" this can be activated from a suitable entry in an HTML document. This means that the Java applet can be run by a Java-enabled browser, and therefore within Windows. This is one of the most exciting uses of Java, especially since it produces programs that can run on a remote computer. To run under a web browser it is only necessary that the "class" ffle defining the applet be in the same folder as the HTML document activating it.

A very impressive set of interactive applets is available at the website: <http://www.math.berkeley.edu/~sethian/ >, illustrating points from the book by Sethian (1999). It is not necessary to understand everything in the book to be impressed by the possibilities of this means of demonstrating computational methods.

Object orientation

Apart from its advantage of portability, Java has in very strong measure the great advantage of object-orientated languages, namely that of allowing reuse of existing programs, with modifications to suit new requirements. Skilful exploitation of this is claimed to allow the development of complex programs quickly and reliably, without spending time "reinventing the wheel". This obviously depends on acquaintance with the enormous class libraries and with the principles of inheritance that underlie object orientated programming. As Wright (2000) puts it: "Java is not a difficult language to learn; it is a difficult language to master".

The JIKES compiler

Wright suggests the use of a programmer's text editor called TextPad, available from: <http://www.textpad.com >. This can be downloaded and used without charge for a limited period, after which continued use requires a payment. An alternative text editor, specifically prepared for use with Java, can be downloaded free from: <http://www.execpc.com/~dgregoir >. It is termed dg_coder, devised by David R. Gregoire. (So much is available free on the Internet that it is natural to become miserly!)

An interesting feature of dg_coder is that it can utilise an alternative compiler instead of the standard one supplied by Sun Microsystems. It is termed the JIKES compiler, written and maintained by an IBM group. It can be downloaded free from: <http://www 10.software.ibm.com/developerworks/opensource/jikes/project/stable/ >, and needs only a few minutes to download (since it is a compiler only, and not a complete system with class libraries). It is claimed to have the advantage over the standard compiler of much faster operation.

When dealing with the "toy" programs that are used in the early stages of learning a language, compiler speed is not important since compilation is virtually instantaneous in any case. It is hoped that observations on more advanced use of Java and experience with these facilities will appear in a future Commentary.

Alex M. Andrew

References

McBride, Peter (1997a), Java Made Simple, Made Simple Books (imprint of Butterworth- Heinemann), Oxford.

McBride, Peter (1997b), JavaScript Made Simple, Made Simple Books, Oxford.

Serbian, J.A. (1999), Level Set Methods and Fast Marching Methods, Cambridge (reviewed in Kybernetes 29, no. 2, pp. 242-4).

Wright, Chris (2000), Teach Yourself Java, Hodder & Stoughton, London University Press.

Related articles