Undergraduate Java Midterm
December 1, 1998
Choose 1 best answer (3 points each)
1. Which of the following is NOT a required method for an applet? a. init( )
b. start( )
c. destroy( )
d. add( )
2. Html is a language for describing
a. Java programs
b. top-down analysis c. hypermedia
d. list controls
3. A package may contain many
4. What comes after “new”?
a. a call of a constructor method b. a class name
c. a keyword
d. a URL
5. Each thread has its own
a. applet window
b. runtime stack
c. static variables
d. source code
6. An interface has only
b. menus and dialog boxes c. abstract classes
7. How do you add ten to Integer j in Java? a. j:=j+10;
b. Integer k = Integer(int(j)+10); c. j=j+10;
8. The “drawArc” method is contained in which package?
9. The “hashtable” class implements which abstract class?
a. may cause the runtime stack to be popped
b. are the same as subroutine calls
c. may be turned off
d. will cause the application to exit
Short answers (5 points each)
1. Write a Java for loop to print out two columns containing the integers 1 through 100 and their squares.
2. Write a constructor function Classname(int x) where you store the parameter x into a class attribute of the same name. How do you tell the compiler which x you are referring to?
3. How do you get the effect of a “scanf” function in Java? (Hint: scanf is C’s formatted read scanf(format, pointers to variables…)
4. URL(string) returns a URL. getImage(URL,filename) can create an image of the given name. Write statements to declare a variable “img” to be the image stored in the file “/home/user/dan/me.jpg”. Be sure to catch the exceptions if the file is not there or if the URL is malformed.
5. Write statements to create a button and add an actionlistener whose actionPerformed( ) callback method will write the word “hello” on System.out, using Java 1.1’s event-delegation model.
6. When is an applet’s “stop” method called?
Long Answers (20 points each)
1. Give an interface defining a course such as this programming language course,
including methods for setting and returning the name of the course, the registered
students, the total number of students, the instructor, and the course’s prerequisite
courses (i.e. courses to be taken before this course, such as C language and data
2. Describe Java’s reflective capabilities.
a. What does it mean for a language to be self-reflective?
b. How can you find out what methods a class has?
c. What are the steps in redefining a class as the program is running?