CPSC 124, Winter 1998
Sample Answers to Lab 1

This page contains sample answers to some of the exercises from Lab #1 in CPSC 124: Introductory Programming, Winter 1998. See the information page for that course for more information.

Exercise 1: The first part of the exercise was to make some simple modifications to a program and to print it out. The second part was a short essay about variables:

A variable is used to hold information that is used in a program. The variable has a value that can be changed as the program is running. It has a name that can be used in the program to refer the current value of the variable. Since programs exist to process information, there must be some easy way for a programmer to work with data values. It is convenient to be able to refer to the values by name.

Exercise 2: A .java file contains a program written in the high-level language Java. This program must be compiled to produce an equivalent Java bytecode program. The bytecode program is stored in a .class file. In order to execute the program, a computer uses an interpreter that can execute Java bytecode. The interpreter needs only the .class file, not the original Java program.

An .html file is written in the HyperText Markup Language, and it contains the description of a Web page. The .html file tells a Web browser, such as Netscape, what to put on the page. One of the things that can be on a Web page is a Java applet. Netscape includes a Java bytecode interpreter that can be used to execute such applets. To display an applet on a page, Netscape needs the .class file, but not the .java file.

So, to publish an applet on a Web page, you need to publish an .html file to describe the page and a .class file that contains the program for the applet.

(Note: Most applet actually require several .class files. A complex applet might use several dozen or more. It is now possible to bundle several .class files into one "archive" file. The archive file names end in .zip or .jar. The advantage of this is that Netscape only has to download one file, instead of the many individual .class files. We will not use archive files in this course.)

Exercise 3: The exercise was to send me an email. Everyone who did this received a reply by email.

Exercise 4: The exercise was to publish a certain page on the Web and to tell me the URL of that page. A few people failed to include the URL. If you followed all the instructions in the lab worksheet, the Moiré applet that you published should have different colors from the ones on the original Web page. It should also have at least one other applet parameter changed.

Exercise 5: The exercise was to use Alta Vista's search facility to find a Web page related to some topic. A few people did not follow the instructions, and found the page in another way (such as by using Yahoo's topic listing).

David Eck, 15 January 1998