You are on page 1of 4

AMA Computer College

Dagupan Campus Mayombo District, Dagupan City Pangasinan

Final Examination in COMPR2 (CSDP 2)


Computer Programming 2 (Java) Generic Instruction: ERASURES AND ALTERATIONS shall be considered WRONG from Part I to Part III. However, erasures and alterations on the last part shall be considered. I. Multiple Choice (20 Points). Choose the letter of the correct answer 1. It is the process of inserting an item at the top of the stack. a. push b. enqueue a. Last In, Last Out b. First In, Last Out c. dequeue d. pop c. First In, First Out d. Last In, First Out

2. Stack follows the principle of __________.

3. It is a concept of object oriented programming which follows the principle of inheriting traits from the grandparent through the direct parent of a child. a. Inheritance b. Multiple Inheritance in your program. a. BufferedReader b. InputStreamReader a. Merge Sort b. Bubble Sort c. Scanner d. FileInputStream c. Heap Sort d. Insertion Sort c. Simple Inheritance d. Level Inheritance

4. An input stream mechanism class which can be used when the java.util package was imported

5. A sorting algorithm which actually sort a given set of element in a heap.

6. Which of these is not a convention for naming variables in Java? a. After the first word in the variable name, each successive word begins with a capital letter. b. The first letter of the variable name is lowercase. c. All letters are capitalized. d. You should not use any reserved words when declaring a variable. 7. Java programming follows which execution process? a. Read Write Compile Execute b. Write Compile Read Execute c. Write Read Compile Execute d. None of the above

25 Copies

mjfsc

8. If you have a program with objects named obj1 and obj2, what happens when you use the statement obj2 = obj1? a. The instance variables in obj2 are given the same values as obj1. b. obj2 and obj1 are considered to be the same object. c. Neither a nor b. d. Both a or b will do. 9. Which loop is used to execute the statements in the loop at least once before the conditional expression is evaluated? a. do-while b. while a. / c. for d. either a, b or c will do c. % d. ? : c. length d. either a or c will do

10. Which operator returns the remainder of a division operation? b. ? a. size b. MAX_VALUE a. None b. The classes stored in the folders of your CLASSPATH c. The classes in the java.lang package d. The java.io package 13. What keyword is used to jump out of a try block and into a finally block? a. catch b. throw c. return d. throws

11. Which instance variable of an array is used to find out how big it is?

12. What packages are automatically imported into your Java classes?

14. What happens when you create a FileOutputStream using a reference to an existing file? a. An exception is thrown. b. The data you write to the stream is appended to the existing file. c. The existing file is replaced with the data you write to the stream. d. Both b and c will happen 15. A copy of any template created in your java program is called _______ a. Class b. Instance c. object d. neither a, b nor c 16. Multiple inheritance is not applicable in JAVA because _________. a. Your java program is entirely a class b. It is not possible to inherit traits from two different parents simultaneously. c. The only applicable inheritance in java only includes simple and level inheritance. d. All of the above. 17. Any statement which is automatically executed when an error occurred is_________. a. catch b. assertion c. finally d. none of the choices

25 Copies

mjfsc

18. Removing item at the end of an array falls under __________. a. Pop include __________. a. Accessing element in an empty array. b. Accessing an element which is not included in the array element. c. Accessing elements in the middle of the array elements. d. None of the above. 20. The process in merge sorting which involves the sorting each elements separately. a. Merging II. b. divide and conquer c. sorting d. a, b and c b. enqueue c. dequeue d. push 19. When an ArrayIndexOutOfBoundsException was thrown, the possible error which occurs might

Identification (20 POINTS). Identify what is being asked. 1. Usually the errors that occur during program execution that affects the normal flow of the program. 2. A class associated with InputStreamReader when reading data entered using keyboard. 3. This process involves calling the method itself repetitively in solving a particular problem. 4. An exception handler which is associated with the errors involving improper user input using a keyboard. 5. A process by which you continuously loop through blocks of code. 6. When the specified text file does not exist, the _____________ will be called automatically. 7. The process of inserting an item at the top of your stack is called. 8. An input mechanism class which treats all inputs as string. 9. A file created after you compile your java program is called _____. 10. A mechanism which allows data to flow from your program to an external text file. 11. Any function which does not need to be defined by the programmer is called __________. 12. An output stream class which creates an empty text file and allow data to flow from your program to that text file. 13. Returns the string wherein all occurrences of the oldChar in this string is replaced with newChar. 14. An output mechanism function which does not automatically attach new line character into the string. 15. Formula in determining the size of the second array in a merge sort algorithm. 16. An input mechanism under the java.lang package which is use to accept user input on the console. 17. Returns the smaller value between two double values. 18. The process of concatenating entered data into the current data available in the text file. 19. A class which is needed to access the function nextInt() or nextDouble(). 20. A type of network connection wherein all resources in a network are controlled through a server.

25 Copies

mjfsc

III.

Enumeration (20 POINTS). Enumerate the following A. 7 OSI Layers (in order) B. 3 Mechanism in handling exceptions C. 5 Functions under the String class D. 3 OOP Concepts E. 2 Operations involved in Merge Sort

IV.

Sorting Algorithm (20 Points). Show in diagram how are you going to sort the following array elements using heap sort. Address Values 0 -75 1 -10 2 -25 3 0 4 1

V.

Stack (10 Points). Show the appearance of the following expression when you perform stack (show using a diagram). Value to be stored in Stack: Java Programming STACK:

VI.

Output Tracing (10 Points). Trace the output of the following pseudocode. int n, m; for (n = 1; n <= 10; n++){ for (m = 10; m >= 1; m){ System.out.println(n + " times " + m + " = " + n*m); } } --Each individual has their own problem. These problems may be similar with one another. However, we have our own UNIQUE way on perceiving and solving these problems. God Bless in solving your problem

Prepared by: Matthew John F. Sino Cruz Instructor

Checked by: And Julie D. Rosal College Dean

25 Copies

mjfsc

You might also like