0.1   Computing in a Web Page: Basics

If you're reading this text now, then you were able to follow a link with your web browser. You are off to a good start.

The main thing about these web pages which is different than most is that they are able to do computations. This is accomplished through what are called Java applets. They give you places to enter information, and buttons to click on to compute answers.

Our first example shows the basic form for many of our Java applets. It lets you input a positive integer n and computes the sum of the integers from 1 to n. When this page first loads, an initial value of n is chosen for you. Clicking on the button which says Compute! will perform the computation.

We are sorry, but your browser is currently not able to run Java applets. You will be able to read these web pages, but you will not be able to do any computations with them. In most cases, you would be able to upgrade to a more recent version of your browser for free, and recent versions of the popular web browsers can run Java.

You can click the mouse in an input field (where the number 5 is located) and edit its value. Change the 5 above to a 7 and recompute the answer.

In general, your web browser should show input areas with a white background and output areas with a grey background so that you can easily tell what values can be changed.

A second type of applet we will see is one where the ouput is more complicated than one or two numbers. In that case, the output is put in a scrolling output area. For example, the following applet takes two integers a and b and computes a+b, a*b, and ab.

You can click on the Compute! button, change the values of a and b, and click on it again. Try that a few times. You should notice that the output area can be scrolled up and down to see all of the output, even if it is more than can be seen at once. If you want to erase the contents of the output area, click on the Clear button.

The output may get very wide, so that you would want to scroll from side to side. To see that, try using a = 5 and b = 200.

In this last computation, we could see something else of interest: the Java applet does computations using arbitrary precision integers. This will be true of all of the Java applets.

Section 0.1 | Section 0.2 | Section 0.3 | Section 0.4 | Section 0.5

Chapter 0 | DNT Table of Contents

Copyright © 2001 by W. H. Freeman and Company