Make your own free website on Tripod.com

Java Programming
Test 1
Create a Word document to answer these questions. You may need additional software and Internet assistance to answer some questions, but the grade will depend on what's in the document. Save the document as Java Test 1.doc in your folder on the server.

 

1. What are the differences between a Java application and a Java applet?

2. What is a Java 'class'?

public class Demo {
	public static void main(String[] args) {
		int sum = 0;
		for (int current = 1; current <= 5; current++) {
			sum += current;
		}
		System.out.println("Sum = " + sum);
	} //  3a. What is this curly brace for?
}         //  3b. What is this curly brace for?

4. Is the above code an application or an applet? How do you know?

5. What is the filename for the above code?

6. What is the output of the above code?

7. The Java programming alnguage has two types of variables: primitive and reference. What are the primitive data types?

8. A variable name cannot be a Java keyword. How many Java keywords are there?

// some stuff here
{
	int i = 17;
	// more stuff in here
}

System.out.println("The value of i = " + i);

9. What error is demonstrated in the code above?

10. Which of the following are valid variable names (indicate by writing ‘valid’ next to the valid ones only)?

	int
	anInt
	i
	i1
	1
	thing1
	1thing
	ONE-HUNDRED
	ONE_HUNDRED
	something2do

11. See Questions and Exercises: Object-Oriented Concepts on the Sun tutorial. Modify the ClickMe applet so that the background is blue and the spots are drawn in random colors. Use "x=Math.random();" to get a random double from 0 to 1. You'll have to convert this number to an int from 0 to 255!

Example (click on the blue area below):

Your browser does not support Java applets!

BONUS! What I really wanted was to have the applet NOT erase prior spots when you click, so that you can draw a bunch of spots! Can you do it?