Chapter 2 Progress Checks


1. Identify all errors in the following program:

/* Program Exercise

A program with many errors.

//

importjavabook.mainwindow;


class Exercise

{

public void Main()

{

MainWindow mainWindow;

mainWindow.show();

}

}


2. Identify all errors in the following program:

// Program Exercise

A program with many errors

//


import JavaBook.*;


class Exercise {

public static void main method() {

mainWindow mainWindow;

MessageBoxmybox1, mybox2;


MainWindow = new MainWindow();

messageBox.show();

mybox2 = new MessageBox();

}

}


3. Identify all of the errors in the following program:

/* Program Exercise

A program with many errors.

//

import java.applet;


class Exercise extends applet {

static public void paint() {

graphic.drawString("Internet is fun and useful"));

}

}

4. Describe the purpose of comments.


5. Name the types of comments available.


6. Can you include comment markers inside a comment?


7. Does a Java program always have to include an import statement?


8. What is the purpose of the import statement?


9. Show the syntax for importing one class and all classes in a package.


10. What is a reserved word?


11. List all the Java reserved words mentioned in this chapter.


12. Which of the following are invalid identifiers and why?

One

my Window

1234

acct122

hello

JAVA

hello,there

DecafeLattePlease


13. Which of the following are invalid identifiers and why?

R2D2

whatchamacallit

Java

GoodName

CPO

ThisIsReallyOkay

java

aPPlet


14. Describe the steps you take to run a Java application and the tools you use in each step.


15. What different types of errors are detected at each step?


16. What are source files and bytecode files?


17. What's wrong with the following code?

MainWindow mainWindow();

mainWindow.show();


18. Which of the following statements is valid?

MainWindow.setVisible("true");

mainWindow.setVisible(true);


19. Describe the difference between object declaration and object creation. Use a state-of-memory diagram to illustrate the difference.


20. Show a state-of-memory diagram after each of the following statements is executed:

MainWindow window1;

MessageBox mbox1,mbox2;


window1 = new MainWindow();

mbox1 = new MessageBox(window1);

mbox2 = new MessageBox(window1);


21. Show a state-of-memory diagram after each of the following statements is executed:

Person person1, person2;

person1 = new Person();

person2 = new Person();

person2 = new Person();


22. Which of the following identifiers violate the naming convention for class names?

R2D2

whatchamacallit

Java

GoodName

CPO

ThisIsReallyOkay

java

aPPlet


23. Which of the following identifiers violate the naming convention for object names?

R2D2

whatchamacallit

Java

GoodName

CPO

ThisIsReallyOkay

java

aPPlet


24. How are Java applets different from Java applications?


25. What is a web page?


26. What tag is required to run an applet in a web browser?


27. How are an applet viewer and a web browser different?


28. Which method of the Graphics class do you use to draw a rectangle?