CP2003 - Tutorial 7 and 8

Java and Javascript

For the Java programming questions, you should log onto the machine. You would typically have three items open: (i) netscape communicator pointing to http://www.cs.jcu.edu.au/jcuonly/javadocs1.2.2/docs/api/index.html , (ii) a DOS-prompt on drive H: where you compile and run your own Java programs, (iii) an editor where you edit the source files of your programs.


1. Give three reasons for the popularity of the programming language Java.

2. A fictitious company SuperCompTM has developped a new computer platform. Enterprise XYZ wants to buy such a platform and migrate its 1000 Java applications from its existing platform to the SuperCompTM platform.

Explain:

3.a. Write, compile and run the HelloWorld2.java program from the lecture notes.

b. Write a program HelloWorld3.java that is able to process any number of arguments from the command-line.

As an example

java HelloWorld3

should produce

Hello World

and

java HelloWorld3 John Mary Apollo ET

should produce

Hello John, Mary, Apollo, ET

4. Write two small Java applications that both process a number of positive integers entered by the keyboard (and terminated with a zero or negative integer). The program should then calculate and output a float which is the average of the integers entered.

a. Version 1. Reads the integers into an (Java) int array. The array has fixed size 10.

b. Version 2. Reads the integers as Integer objects into a Vector .

Try to fool Version 1 by feeding it with more than 10 integers.

5. HTML and Javascript!

a. Visit http://www.pageresource.com/jscript/index.html . Read the tutorial "Learn the JavaScript Basics".

b. Briefly describe what Javascript is.

c. Write your own small webpage in HTML and Javascript which displays some simple text and a button named "Change Color". The button changes the background color of the webpage in the following order: white, yellow, red and then back to white, ... starting with white as the initial color.

Procedure:


Marc Gysin, September 1999