Document 6536979
Transcription
Document 6536979
1 of 9 http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k... Test 2010 Spring Final Exam Sample Instructions: Write your name on the examination. DO write on the examination, use it for scratch paper. You will get the examination back with your results. This is a closed book, notes, neighbor examination. Select the best answer. No, it is not a typo, all code appears as intended. Any text in this font is as intended. Do not ask the instructor about any "typos" that is in this font. All output is to be considered what appears in the console. When you have finished the examination, turn in both your answer sheet and the examination. 1. True or False? An Inner class can access methods and variables in their respective parent. A. True (Correct Answer) B. False 2. Which of the following will NOT produce an exception? A. ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("stuff.ser")); //stuff.ser does not exist (Correct Answer) B. os.writeObject(something); //something does not implement serializable C. ObjectInputStream is = new ObjectInputStream(new FileInputStream("stuff.ser")); //stuff.ser does not exist D. Foo something = is.readObject(); //the object being read is of type Foo E. None of the above 3. A Java Web Start application’s main method is specified in its JAR file. A. True B. False (Correct Answer) 4. Selecting a checkbox generates _________________ . A. An ActionEvent only B. An ItemEvent only C. Both an ActionEvent and an ItemEvent (Correct Answer) D. A CheckEvent 5. True or False? Runtime exceptions must be handled or declared. A. True B. False (Correct Answer) 6. Which three Throwable subclasses provide the "cause" argument in the constructor? A. Execute, Exception and Error. B. Error, Exception and Abort. C. Error, Exception and RuntimeException. (Correct Answer) D. Exception, Abort and Event. E. None of the above 7. If you want to disable a GUI component, what method do you use? A. Disabled B. Enabled C. SetDisabled D. setEnabled (Correct Answer) E. None of the above 8. What does this code do frame.getContentPane().add( );? A. Adds the number of total frames B. Make the current frame the top C. Add a component to the frame (Correct Answer) D. All of the above E. None of the above 9. Which of the following extend Collection? A. Set, List, and Map interfaces B. List and Map interfaces C. Set and Map interfaces D. Set and List interfaces (Correct Answer) E. None of the above 10. Package structures are meaningfully represented using hierarchies. 5/8/2010 7:33 PM 2 of 9 http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k... A. True (Correct Answer) B. False 11. For an anonymous inner class you can: A. extend a class and implement an interface. B. extend a class or implement an interface, not both. (Correct Answer) C. implement multiple interfaces. D. overload its instance initializer. E. None of the above 12. True or False? When a ServerSocket gets a request, it 'accepts' the request by making a Socket connection with the client. A. True (Correct Answer) B. False 13. Given the following code, which option if placed on the lines after the comment //here will result in compilation and output of run? public class SeSe implements Runnable { public static void main(String argv[]) { SeSe s = new SeSe(); s.go(); } public void go() { //here } public void run() { System.out.println("run"); } } A. Thread t = new Thread(this); t.start(); (Correct Answer) B. start(); C. Thread t = new Thread(this); this.start(); D. Thread t = new Thread(); this.start(t); 14. What will the code in a finally{} clause at the bottom of a try block do? A. It will execute right before an exception occurs. B. It will execute after an exception occurs. C. It will always execute (Correct Answer) D. It will execute if a exception occurs and is handled but if an unhandled exception occurs or an error occurs it won't execute. E. None of the above 15. True or False? If you define a try / catch block, a matching finally block is optional. A. True (Correct Answer) B. False 16. TreeMap class is used to implement which collection interface? A. Set B. SortedSet C. List D. Tree E. SortedMap (Correct Answer) 17. True or False? The static Thread.sleep() method forces a thread to leave the running state for at least the duration passed to the sleep method. Thread.sleep(200) puts a thread to sleep for 200 milliseconds. A. True (Correct Answer) B. False 18. True or False? If a superclass is not serializable then its subclasses can’t be serializable. A. True B. False (Correct Answer) 19. given the following compilable statement: Collections.sort(myArrayList); what method must the class of the objects stored in myArrayList implement? A. Comparator 5/8/2010 7:33 PM 3 of 9 http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k... B. C. D. E. Comparable compareTo() (Correct Answer) compare() None of the above 20. PrintWriter is a low level stream that writes bytes directly to the stream. A. True B. False (Correct Answer) 21. A JAR is a standard directory where your .class files should reside. A. True B. False (Correct Answer) 22. True or False? Object state can be saved only by using serialization. A. True B. False (Correct Answer) 23. Which of these is not a Layout Manager that comes with the Java Platform, Standard Edition? A. BoxLayout B. PaneLayout (Correct Answer) C. FlowLayout D. BorderLayout E. None of the above 24. The supporting file in a Java Archive declares which class has the main() method. A. True (Correct Answer) B. False 25. True or False? A finally block can exist without a try block. A. True B. False (Correct Answer) 26. Extracting a JAR with packages will create a file called MANIFEST.MF. A. True (Correct Answer) B. False 27. Reserved network ports for well-kown services are in the range ... A. from 0 to 1000. B. from 0 to 1023. (Correct Answer) 28. What will happen if you compile/run this code? 1: public class Q1 extends Thread 2: { 3: public void run() 4: { 5: System.out.println("Before start method"); 6: this.stop(); 7: System.out.println("After stop method"); 8: } 9: 10: public static void main(String[] args) 11: { 12: Q1 a = new Q1(); 13: a.start(); 14: } 15:} A. Compilation error at line 7. B. Runtime exception at line 7. C. Prints "Before start method" and "After stop method". D. Prints "Before start method" only. (Correct Answer) E. None of the above. 29. True or False? When we delete the first node in a list, we always set head to null. A. True B. False (Correct Answer) 30. For a BorderLayout, how many areas are provided? A. 4 B. 10 C. 7 5/8/2010 7:33 PM 4 of 9 http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k... D. 5 (Correct Answer) E. None of the above 31. True or False? A single try block can have many different catch blocks. A. True (Correct Answer) B. False 32. True or False? When creating a Java Archive you must create a file called jar,mf. A. True B. False (Correct Answer) 33. What package does the ActionListener interface belong to? A. javax.swing B. java.awt C. java.awt.event (Correct Answer) D. java.listener 34. Which is the class that allows reading of binary representations of Java primitives from an input byte stream? A. BufferedInputStream B. DataInputStream (Correct Answer) C. LineNumberInputStream D. PushbackInputStream E. None of the above. 35. What is a benefit of putting your classes in packages? A. It is required to make a java program. B. It makes the code compile faster. C. It makes the compiled program run faster. D. It helps prevent name conflics. (Correct Answer) E. None of the above 36. True or False? The transient modifier allows you to make instance variables serializable. A. True B. False (Correct Answer) 37. Selecting a radio button generates _________________ . A. An ActionEvent only B. An ItemEvent only C. Both an ActionEvent and an ItemEvent (Correct Answer) D. A RadioEvent 38. True or False? The main( ) method in your program must handle all unhandled exceptions thrown to it. A. True B. False (Correct Answer) 39. True or False? The repaint method automatically calls the paint method. A. True (Correct Answer) B. False 40. Given: class Outer { class Inner { void innerMethod() {} } } What's the correct way to create an instance of class Inner? A. Inner inner = new Outer.Inner(); B. Inner inner = new Inner(); C. Outer.Inner inner = new Inner(); D. Outer outer = new Outer(); Outer.Inner inner = outer.new Inner(); (Correct Answer) E. None of the above 41. True or False? A thread is said to be RUNNING when the JVM's thread scheduler has selected it to be the currentlyrunning thread. On a single-processor machine, there can only be one currently-running thread. A. True (Correct Answer) B. False 42. Different classes within a source file can belong to different packages. A. True 5/8/2010 7:33 PM 5 of 9 http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k... B. False (Correct Answer) 43. True or False? A try block must be followed by a catch and a finally block. A. True B. False (Correct Answer) 44. Which of the following orders components in a top to bottom order by default? A. BorderLayout B. BoxLayout (Correct Answer) C. FlowLayout 45. Which of the following is a property of a HashSet? A. fastest way to retrieve elements (Correct Answer) B. keeps the objects in ascending comparison order C. keeps the objects in the order in which they were added 46. True or False? To read text data from the server, create a BufferedReader, chained to an InputStreamReader, which is chained to the input stream from the Socket. A. True (Correct Answer) B. False 47. True or False? The String split() method includes separators as tokens in the result array. A. True B. False (Correct Answer) 48. True or False? Both file readers and file writers can optionally be buffered. A. True (Correct Answer) B. False 49. Which of these is true about threads? A. Threads run automatically. B. You can only have one thread at a time. C. A blocked thread can become runnable again. (Correct Answer) D. You can restart and re-use thread objects. E. None of the above 50. True or False? A try block can exist by itself, without a catch block or a finally block. A. True B. False (Correct Answer) 51. True or False? The Swing components are often referred to as lightweight components A. True (Correct Answer) B. False 52. What is a TCP port? A. The location of the server. B. A number that identifies a specific program on a server. (Correct Answer) C. Your computers address. D. A number that identifies a group of applications on a server. E. None of the above 53. True or False? At the command line, Java Archives are invoked using the -arch flag. A. True B. False (Correct Answer) 54. True or False? The order of catch blocks never matters. A. True B. False (Correct Answer) 55. True or False? If you define a try block, you can pair it with a matching catch or finally block, or both. A. True (Correct Answer) B. False 56. True or False? A JTextArea displays a single line field. A. True B. False (Correct Answer) 57. When compiling classes in a package, the -p flag is highly recommended. A. True 5/8/2010 7:33 PM 6 of 9 http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k... B. False (Correct Answer) 58. True or False? In a stack represented by a linked list, we delete, or pop, at the end of the list A. True B. False (Correct Answer) 59. Given that req is an HttpServletRequest, which returns the names of all the parameters in the request? A. Map names = req.getParameterNames(); B. String[] names = req.getParameters(); C. Enumeration names = req.getParameters(); D. String[] names = req.getParameterNames(); E. Enumeration names = req.getParameterNames(); (Correct Answer) 60. Which is NOT correct according to the Java API for Object? A. If objectA.equals(objectB) returns true, then objectA.hashCode() must equal objectB.hashCode() B. if objectA.hashCode() equals objectB.hashCode(), then objectA.equals(objectB) must return true (Correct Answer) C. objectA.equals(objectB) and objectB.equals(objectA) must either both return true or both return false D. if you override equals(...), you must override hashCode() E. None of the above 61. True or False? When we attempt to delete an item in a list, it is possible that we do not find that item in the list, in which case we cannot delete it. A. True (Correct Answer) B. False 62. True or False? To launch a new thread, you need a Runnable to pass to the Thread's constructor. A. True (Correct Answer) B. False 63. True or False? Chain streams can be used on their own or with connection streams. A. True B. False (Correct Answer) 64. True or False? A private inner class can directly access the fields of the public class that it is in. A. True (Correct Answer) B. False 65. True or False? A class is automatically serializable if one of its superclasses implements Serializable. A. True (Correct Answer) B. False 66. True or False? Judicious use of the -d flag can help to assure that there are no typos in your tree. A. True (Correct Answer) B. False 67. True or False? Both serialization and saving to a text file can throw exceptions. A. True (Correct Answer) B. False 68. Given the following URL: http://www.example.com/userConig/searchByName.do?first=Bruce& middle=W&last=Perry Which servlet code fragment from a service method, for example doGet(), will retrieve the value for the query string parameter "first"? A. String value = request.getParameter("Bruce"); B. String value = request.getParameter("first"); (Correct Answer) C. String value = getServletContext().getInitParameter("first"); D. String value = getServletConig().getInitParameter("first"); 69. True or False? Transient variables get serialized with the rest of the class. A. True B. False (Correct Answer) 70. Pressing the Enter key in a text field generates an _________________ . A. ActionEvent (Correct Answer) B. CommandEvent 5/8/2010 7:33 PM 7 of 9 http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k... C. EnterEvent 71. Given the following compilable statement: Collections.sort(myArrayList); what must the class of the objects stored in myArrayList implement? A. Comparator B. Comparable (Correct Answer) C. compareTo() D. compare() E. None of the above 72. True or False? Only 'compiler checked' exceptions can be caught. A. True B. False (Correct Answer) 73. When creating a GUI application class, which class do we typically extend? A. Window B. JFrame (Correct Answer) C. Component D. Container E. None of the above 74. What package does the ActionEvent class belong to? A. javax.swing B. java.awt C. java.awt.event (Correct Answer) D. java.event 75. True or False? When objects are deserialized they are read back in last-in, first out sequence. A. True B. False (Correct Answer) 76. True or False? In an empty list, head is null. A. True (Correct Answer) B. False 77. True or False? A finally block will run regardless of whether an exception is thrown. A. True (Correct Answer) B. False 78. What method is used to set the width and height of a window? A. setWindow B. setWidthHeight C. setHeightWidth D. setSize (Correct Answer) E. None of the above 79. True or False? You can have serious problems with threads if two or more threads have access to the same object on the heap. A. True (Correct Answer) B. False 80. What is the name of the collection interface used to maintain unique elements? A. List B. Map C. Queue D. Set (Correct Answer) E. SortedMap 81. Streams support what kind of data? A. simple bytes B. primitive data types C. objects D. All of the above (Correct Answer) E. None of the above 82. A BorderLayout divides a background into five regions. Which of the following does NOT belong. A. CENTER B. EAST 5/8/2010 7:33 PM 8 of 9 http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k... C. WEST D. TOP (Correct Answer) E. None of the above 83. True or False? Handling an exception is sometimes referred to as 'ducking'. A. True B. False (Correct Answer) 84. True or False? A method with a try/finally block, can optionally declare an exception that could be thrown in the try block. A. True B. False (Correct Answer) 85. True or False? Catch blocks can be polymorphic. A. True (Correct Answer) B. False 86. By default, applications run in a restricted environment, known as a ____________. A. junkyard B. vacancy C. jungle D. sandbox (Correct Answer) E. None of the above 87. Which interface do the methods mouseDragged and mouseMoved belong to? A. MouseListener B. MouseMotionListener (Correct Answer) C. Mouse D. MouseMotion 88. Some of the key points in preparing your code for deployment/distribution are listed below. Which does NOT belong? A. Organize your project so that your source code and class files are in the same directory. (Correct Answer) B. You can bundle your classes into JAR (Java ARchive) files. JAR is based on the pkzip format. C. The entire package directory structure must be immediately inside the JAR file. D. To make your compiled class land in the correct package directory structure under the classes directory, use the -d compiler flag. E. None of the above 89. Which abstract class is the super class of all classes used for reading bytes? A. Reader B. FileReader C. ByteReader D. InputStream (Correct Answer) E. FileInputStream 90. True or False? If a Java Web Start application is running in a secure sandbox, JAR files for the application can reside on different servers. A. True B. False (Correct Answer) 91. Clicking on a button generates an _________________ . A. ActionEvent (Correct Answer) B. CommandEvent C. EnterEvent 92. True or False? Extracting a JAR with packages will create a directory called META-INF. A. True (Correct Answer) B. False 93. True or False? To compile a servlet, you need the servlet packages which are in the servlets.jar file. The servlet classes are not part of the Java standard libraries, so you need to download the servlets.jar from java.sun.com or get them from a servlet-capable web server. A. True (Correct Answer) B. False 94. If you want to make a GUI component opaque or transparent, what method do you use? A. transparent B. opaque C. SetTransparent 5/8/2010 7:33 PM 9 of 9 http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k... D. setOpaque (Correct Answer) E. None of the above 95. Which of the following does NOT need to be done in order to perform event handling? A. implement an event listener interface B. register with the event source C. create the methods that the event source will call upon creation of the event D. instantiate an event object (Correct Answer) E. None of the above 96. What are the three standard streams? A. Standard Import, Standard Outport, Standard Erase B. Standard Input, Standard Output, Standard Error (Correct Answer) C. Standard Upload, Standard Download, Standard Clear D. Standard Install, Standard Uninstall, Standard Error E. None of the above 97. Which of the following about inner classes is false? A. An inner class can only be instantiated from within its outer class. (Correct Answer) B. An inner object can access private members of its outer object. C. An inner class is defined entirely inside its outer class. D. Java is one of very few languages that implement inner classes. E. None of the above 98. True or False? If you write a method that declares that it can throw a compiler-checked exception, you must also wrap the exception throwing code in a try / catch block. A. True B. False (Correct Answer) 99. True or False? The web server starts the servlet and calls the appropriate method (doGet(), etc.) based on the client's request. A. True (Correct Answer) B. False 5/8/2010 7:33 PM