Java Test #2
March 30, 1998
I have not violated the Honor Code in completing this test.
Signed: ___________________________________________
READ THESE NOTES
Sign the pledge and initial each sheet. SHOW ALL YOUR WORK Do as many questions as you are able.
DO NOT spend an excessive amount of time on any one question since all questions count the same.
You may OMIT any ONE question. You MUST indicate which question is to be omitted by circling its number and writing the word OMIT next to it.
1. Errors, such as "division by zero" or "attempt to open a nonexistent file" in java are referred to as __________________
2. Java applications are executed by the java interpreter which defines the
A) java API
B) java virtual machine
C) java profiler
D) java system interface
E) java web connector
3. Write a Java for loop to compute the sum of the first 100 positive integers.
4. Write a Java while loop to compute the sum of the first 100 positive integers.
5. Match the following:
| A) Abstraction | ______ Bringing together methods and fields (properties) to create a class.
|
| B) Encapsulation | ______ Different methods may have the same name.
|
| C) Inheritance | ______ Extracting the essential characteristics of a concept.
|
| D) Polymorphism | ______ A subclass possesses the fields and methods of its superclass.
|
6. Describe the most important difference between a java application and a java applet.
7. A special method that is automatically executed when an object is created is called a _______________
8. Give an example of
A.) A single line Java comment
B.) A multiline Java comment
9. Fill in the blanks with the correct answers.
The attributes of an object are called ___________________
Functions/procedures that an object may perform on itself are called ___________________
Actions which may happen to an object are called _________________
10. Name three primitive Java datatypes.
11. A) What is the purpose of casting?
B) Give a java statement that illustrates the use of casting
12. A static field is directly associated with ____
A) a class
B) an instance of a class
C) an object
D) a method
E) a package
13. A) What is the purpose of static fields in a class?
B) Give java declarations that illustrates the use of a static field.
14.
A) Exceptions which occur inside a ________ block may trigger exception handling routines.
B) A ________ clause defines a block of code used to process exceptions
15. Give the output from the following block of java code.
String myline = "this is a test"; //create and initialize a string
StringTokenizer st = new StringTokenizer(myline);
while(st.hasMoreTokens()) {
s = st.nextToken();
System.out.print(s); System.out.print('*');
}
16. Give the output from the following block of java code.
int A[] = {1, 2, 3}; //create and initialize three arrays
int B[] = {4, 5, 6};
int C[] = {7, 8, 9};
B = A;
//copy array A to array C beginning at element 0
System.arraycopy(A, 0, C, 0, A.length);
A[0] = 11; A[1] = 22; A[2] = 33; // change the content of array A
for (int i = 0; i <=2; i++) {
//display the contents of all three arrays
System.out.println("For arrays A, B and C");
System.out.println("element " + i + "=" + A[i] + " " + B[i] + " "+ C[i]);
} // end for
17. An interface is _____
- a method executed when an object is created.
- a special field located in the superclass of a class.
- a class used as a template to define other classes.
- a library of classes.
- a connection to a web browser.
18. What is a java stream?
19. What is the purpose of the bufferred reader class in java?
20. What is the purpose of the import directive in java?