Advanced Programming Exit Exam

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Bahir Dar University

Bahir Dar Institute of Technology


Faculty of Computing
Advanced Programming Exam Bank
Multiple Choice
1. Which of the following statement is invalid?
A. JLabel prompt = new JLabel( );
B. JLabel prompt = new JLabel("Name");
C. JTextField input = new JTextField( 15 );
D. JTextField input = new JTextField( "Name", "John" );
2. Which one of the following components that enables the user to choose a single value or multiple
values at a time?
A. JTextField C. JList
B. JComboBox D. JLabel
3. Clicking a JComboBox object generates __________ event/s.
A. ActionEvent D. ContainerEvent
B. ItemEvent E. A and B
C. ComponentEvent
4. Which type of button is a toggle button that belongs to a group such that only one button in the
group may be selected at one time?
A. Radio button C. Menu item
B. Checkbox D. Panel
5. Which component cannot be added to a container?
A. JPanel C. JFrame
B. JButton D. JComponent
6. Clicking the closing button on the upper-right corner of a frame generates a(n) __________ event.
A. ItemEvent D. ComponentEvent
B. WindowEvent E. ContainerEvent
C. MouseMotionEvent
7. Which of these packages contains all the event handling interfaces?
A. java.lang C. java.awt.event
B. java.awt D. java.swing.event
8. Which of the following components generate action events?
A. Buttons C. Check boxes
B. Labels D. Windows
9. Which of these methods are used to register a mouse motion listener?
A. addMouse() C. addMouseMotionListner()
B. addMouseListener() D. eventMouseMotionListener()
10. To be a listener for ActionEvent, an object must be an instance of ____________.
A. ActionEvent D. WindowListener
B. ActionListener E. WindowEvent
C. EventObject

1
Bahir Dar University
Bahir Dar Institute of Technology
Faculty of Computing
Advanced Programming Exam Bank
11. To listen to mouse actions, the listener must implement the __________ interface.
A. MouseListener C. WindowListener
B. KeyListener D. ComponentListener
12. To listen to keyboard actions, the listener must implement the __________ interface or extend.
A. MouseListener C. WindowListener
B. KeyListener D. ComponentListener
13. Which of the following components is a helper class?
A. JFrame C. JPanel
B. Graphics D. JButton
14. Pressing a button generates a(n) __________ event.
A. ItemEvent D. ActionEvent
B. MouseEvent E. ContainerEvent
C. MouseMotionEvent
15. What is it called when a program is written to respond to the button clicks, menu selections, and
other actions of the user in whatever order the user does them?
A. Event-driven programming. C. User-driven programming.
B. Action-driven programming. D. Mouse-driven programming
16. Which of the following classes is a heavyweight component?
A. JButton C. JPanel
B. JTextField D. JFrame
17. Which one of the following is correct to create a JPanel with GridLayout?
A. JPanel p = new JPanel()
B. JPanel p = new JPanel(new GridLayout(GridLayout(3,2,5,5)));
C. JPanel p = new JPanel(new GirdLayout(3,2));
D. JPanel p = new JPanel().setLayout(new GridLayout(3,2));
18. Which event/s is/are generated when clicking a JList object?
A. ActionEvent and ItemEvent
B. ItemEvent and ItemListener
C. It generates only ActionEvent
D. It generates only ItemEvent
E. ActionEvent and ComponentEvent
19. Which of the following statements is for terminating the program when closing the frame?
A. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
B. frame.setDefaultCloseOperation(null)
C. frame.setDefaultCloseOperation(JFrame.STOP_ON_CLOSE)
D. frame.setDefaultCloseOperation(JFrame.TERMINATE_ON_CLOSE)
20. The method __________ gets the text (or caption) of the button jbt.
A. jbt.text() C. jbt.findText()
B. jbt.getText() D. jbt.retrieveText().

2
Bahir Dar University
Bahir Dar Institute of Technology
Faculty of Computing
Advanced Programming Exam Bank
21. Which of the following is true?
A. JButton inherits from javax.swing.AbstractButton.
B. You can create a JButton by specifying an icon and text.
C. You can create a JButton by specifying an icon.
D. You can create a JButton by a text.
E. You can create a JButton using its default constructor.
22. Which of the following statements are true?
A. All methods in FileInputStream/FileOutputStream are inherited from
InputStream/OutputStream.
B. You can create a FileInputStream/FileOutputStream from a File object
C. The return value -1 from the read() method signifies the end of file.
D. A FileNotFoundException would occur if you attempt to create a FileInputStream with a
nonexistent file.
E. All of the above
23. Which of the following statements is correct to create a DataOutputStream to write to a file named
out.dat?
A. DataOutputStream outfile = new DataOutputStream(new File("out.dat"));
B. DataOutputStream outfile = new DataOutputStream(newFileOutputStream("out.dat"));
C. DataOutputStream outfile = new DataOutputStream(FileOutputStream("out.dat"));
D. DataOutputStream outfile = new DataOutputStream("out.dat");
24. What does the following code do?
FileInputStream fis = new FileInputStream("test.dat");
A. It creates a new file named test.dat if it does not exist
B. It creates a new file named test.dat regardless of whether it exists or not
C. It creates a FileInputStream for test.dat if test.dat exists.
D. All
25. Which of the following statements are true?
A. You can use the PrintWriter class for reading text from a file.
B. You can use the Scanner class for writing text to a file.
C. A File object encapsulates the properties of a file or a path
D. The File class has different methods that can be used to manipulate the files.
E. All of the above
F. C and D
26. Which of the following statement is false?
A. Text I/O involves encoding and decoding.
B. Binary I/O does not require conversions.
C. Text I/O is more efficient than Binary I/O
D. Binary files are independent of the encoding scheme on the host machine and thus
are portable.

3
Bahir Dar University
Bahir Dar Institute of Technology
Faculty of Computing
Advanced Programming Exam Bank
27. What is the name of the abstract base class for streams dealing with general purpose (non-
character) input?
A. InputStream C. Reader
B. OutputStream D. Writer
28. What is buffering in java?
A. A section of memory used as staging area for input or output data
B. The cable that connects a data source to the bus
C. Any stream that deals with character IO
D. A file that contains binary file
29. Which of the following is used to read bytes from streams and converts them into appropriate
primitive type values or strings?
A. DataOutputStream C. FileInputStream
B. DataInputStream D. FileOutputStream
30. Which of the following is used to convert Java Objects into sequence of bytes?
A. DataOutputStream C. ObjectInputStream
B. DataInputStream D. ObjectOutputStream
31. Which of the following method is used to perform DDL statements in JDBC?
A. executeResult() C. executeUpdate()
B. executeQuery() D. execute()
32. Which of the following is used to call stored procedure?
A. Statement C. CallableStatment
B. PreparedStatement D. CalledStatement
33. Which of the following method/s is/are used for setting parameters in the object of
PreparedStatement Class?
A. getString() D. executeUpdate()
B. setString() E. B and C
C. setDouble() F. All
34. Which of the following statements loads the MYSQL JDBC driver?
A. Class.forName(com.mysql.jdbc.Driver);
B. Class.forName("com.mysql.jdbc.Driver");
C. Class.loadClass(com.mysql.jdbc.Driver);
D. Class.loadClass("com.mysql.jdbc.Driver");
35. To create a statement on a Connection object conn, use
A. Statement statement = conn.statement();
B. Statement statement = Connection.createStatement();
C. Statement statement = conn.createStatement();
D. Statement statement = connection.create();
36. Suppose a prepared statement is created as follows:
4
Bahir Dar University
Bahir Dar Institute of Technology
Faculty of Computing
Advanced Programming Exam Bank
Statement preparedStatement = connection.prepareStatement ("insert into Student (firstName, mi,
lastName) values (?, ?, ?)");
To set a value John to the first parameter, use
A. preparedStatement.setString(0, "John");
B. preparedStatement.setString(1, "John");
C. preparedStatement.setString(0, 'John');
D. preparedStatement.setString(1, 'John');
37. Database metadata are retrieved through ____________.
A. a Connection object C. a ResultSet Object
B. a Statement object D. a PreparedStatement object
38. What information may be obtained from a DatabaseMetaData object?
A. database URL and product name
B. JDBC driver name and version
C. maximum number of connections to the database
D. maximum table name length and maximum number of columns in a table
39. To execute a SELECT statement "select * from Address" on a Statement object stmt, use
A. stmt.execute("select * from Address");
B. stmt.executeQuery("select * from Address");
C. stmt.executeUpdate("select * from Address");
D. stmt.query("select * from Address");
40. What information may be obtained from a ResultSetMetaData object?
A. database URL and product name
B. JDBC driver name and version
C. number of columns in the result set
D. number of rows in the result set
E. All of the above
41. If a prepared statement object preStatement is a SQL SELECT statement, you execute the
statement using _________.
A. preStatement.execute(); C. preStatement.executeQuery();
B. preStatement.executeUpdate(); D. preStatement.query();
42. Which of the following expressions must be true if you create a thread using Thread = new
Thread(object)?
A. object instanceof Thread C. object instanceof Applet
B. object instanceof Frame D. object instanceof Runnable
43. You can use the _________ method to temporarily release time for other threads.
A. sleep(long milliseconds) C. stop()
B. yield() D. suspend()
44. You can use the ________ method to force one thread to wait for another thread to finish.
5
Bahir Dar University
Bahir Dar Institute of Technology
Faculty of Computing
Advanced Programming Exam Bank
A. sleep(long milliseconds) D. suspend()
B. yield() E. join()
C. stop()
45. Which of the following statements are true about Semaphores?
A. Semaphores can be used to restrict the number of threads that access a shared resource.
B. Before accessing the resource, a thread must acquire a permit from the semaphore.
C. After finishing with the resource, the thread must return the permit back to the semaphore.
D. You can create a Semaphore with a specified number of permits.
E. All of the above
46. What will be the state of a thread when isLive() method returns true?
A. The thread has not yet started. C. The thread is at New state
B. The thread is finished D. The thread is at Running state
47. Which one of the following is the advantage of Multithreading?
A. You can perform multiple operations together at a time
B. Threads are dependent on other threads
C. A thread can execute concurrently with other threads within a single process.
D. It is used to perform tasks in parallel processing

48. Which one of the following methods are invoked while threads can communicate with other thread
A. wait() C. notifyAll()
B. notify() D. All
49. Which of the following methods invokes the run() method in a thread?
A. join() D. yield()
B. wait() E. A and D
C. start()
50. Which of the following is correct?
A. public class Test implements Thread{}
B. class Test implements Runnable{}
C. public class Test extends Runnable{}
D. public Test class extends Thread{}
51. Which of the following method is used to find out the state of a thread?
A. isInterrupted() C. start()
B. isAlive() D. notify()
52. Which of the following methods cause to interrupt a thread for the specified amount of time?
A. sleep(long milliseconds) C. stop()
B. yield() D. suspend()
53. When creating a server on a port that is already in use, what will happen?
A. java.net.BindException occurs.
B. The server is created with no problems.
C. The server is blocked until the port is available.
6
Bahir Dar University
Bahir Dar Institute of Technology
Faculty of Computing
Advanced Programming Exam Bank
D. The server encounters a fatal error and must be terminated.
54. The server listens for a connection request from a client using the following statement:
A. Socket s = new Socket(ServerName, port);
B. Socket s = serverSocket.accept()
C. Socket s = serverSocket.getSocket()
D. Socket s = new Socket(ServerName);
55. To create an InputStream on a socket s, you use __________.
A. InputStream in = new InputStream(s);
B. InputStream in = s.getInputStream();
C. InputStream in = s.obtainInputStream();
D. InputStream in = s.getStream();
56. ______________ models an IP address, which can be used to find the host name and IP address
of the client.
A. The ServerSocket class C. The InetAddress class
B. The Socket class D. The Connection interface
57. You can invoke ______________ on a Socket object, say socket, to obtain an InetAddress object.
A. socket.InetAddress(); C. socket.obtainInetAddress();
B. socket.getInetAddress(); D. socket.retrieveInetAddress();
58. The ____________ method in the InetAddress class returns the IP address.
A. getIP() C. getHostAddress()
B. getIPAddress() D. getAddress()

59. Which one of the following class is used for UDP connection?
A. ServerSocket C. DatagramSocket
B. Socket D. InputStream
60. The GET and POST methods are specified in _________.
A. a CGI program C. an HTML form
B. a Java program D. a URL string
61. The _______ method ensures that a new Web page is generated.
A. GET C. DELETE
B. POST D. UPDATE
62. If your request is not time-sensitive, such as finding the address of a student in the database, use the
__________ method to speed up the performance.
A. GET C. DELETE
B. POST D. UPDATE
63. Apache Tomcat is a ________.
A. Servlet
B. Java program

7
Bahir Dar University
Bahir Dar Institute of Technology
Faculty of Computing
Advanced Programming Exam Bank
C. Web server
D. Web server that is capable of running Java programs.
64. A servlet is an instance of __________.
A. the Object class C. the HttpServlet class
B. the Applet class D. the HTTPServlet class
65. To start the Tomcat servlet engine, use the command __________ from the TomcatRootDir\bin
directory.
A. java TomcatServlet C. start
B. start Tomcat D. startup
66. By default, Tomcat runs on port ___________.
A. 8080 C. 1080
B. 80 D. 8888
67. The _________ interface defines the methods that all servlets must implement.
A. javax.servlet.Servlet C. ServletRequest
B. HttpServlet D. ServletResponse
68. The _______ method is called when the servlet is first created, and is not called again as long as the
servlet is not destroyed.
A. init C. destroy
B. service D. getServletInfo
69. The _________ class defines a servlet for the HTTP protocol.
A. javax.servlet.http.HttpServlet C. HttpServletRequest
B. Servlet D. HttpServletResponse
70. _________ is a subinterface of ServletRequest.
A. HttpServletRequest C. HttpServlet
B. HttpServletResponse D. Servlet
71. Every doXxx method in the HttpServlet class has a parameter of the __________ type, which is an
object that contains HTTP request information, including parameter name and values, attributes, and
an input stream.
A. HttpServletRequest C. HttpSession
B. HttpServletResponse D. Cookie
72. Every doXxx method in the HttpServlet class has a parameter of the HttpServletResponse type,
which is an object that assists a servlet in sending a response to the client.
A. HttpServletRequest C. HttpSession
B. HttpServletResponse D. Cookie
73. Suppose the two parameters in the doGet or doPost method are request and response. To specify
HTML content type sent to the client, invoke ___________.
A. response.setContentType("text/html")
B. request.setContentType("text/html")
C. response.setContentType("html")

8
Bahir Dar University
Bahir Dar Institute of Technology
Faculty of Computing
Advanced Programming Exam Bank
D. request.setContentType("html")
74. Suppose the two parameters in the doGet or doPost method are request and response. To send output
to a client, create a PrintWriter using _____________.
A. response.getWriter() C. response.writer()
B. response.getPrintWriter() D. response.getWrite()
75. The code for loading a JDBC driver and connecting to a database should be invoked from _____ in a
servlet.
A. the init method C. the doPut method
B. the doGet method D. the destroy method
76. To store a hidden value for lastName as Smith in an HTML form, use __________.
A. <input type=?text? name=?lastName? value=?Smith?>
B. <input type=?text area? name=?lastName? value=?Smith?>
C. <input type=?radio? name=?lastName? value=?Smith?>
D. <input type=?checkbox? name=?lastName? value=?Smith?>
E. <input type=?hidden? name=?lastName? value=?Smith?>
77. To create a cookie for lastName with value Smith, use ____________.
A. new Cookie("Smith", "lastName");
B. new Cookie(Smith, lastName);
C. new Cookie("lastName", "Smith");
D. new Cookie(lastName, \Smith);
78. Suppose the two parameters in the doGet or doPost method are request and response. To send a
cookie to a client, use ____________.
A. response.addCookie(cookie) C. request.addCookie(cookie)
B. response.sendCookie(cookie) D. request.sendCookie(cookie)
79. Suppose the two parameters in the doGet or doPost method are request and response. To retrieve a
cookie from a client, use ____________.
A. response.retrieveCookie()
B. response.getCookie()
C. You have to use request.getCookies() to obtain all cookies in an array
D. You have to use request.getCookie() to obtain a cookie
80. For an instance of Cookie, say cookie, to retrieve the name of the cookie, use ____________.
A. cookie.getValue()
B. cookie.getName()
C. You have to use cookie.getNames() to obtain all values in an array.
D. You have to use cookie.getValues() to obtain all values in an array.
81. Suppose the two parameters in the doGet or doPost method are request and response. To create an
HTTP session, use ____________.
A. request.createSession() C. response.createSession()
B. request.getSession() D. response.getSession()

9
Bahir Dar University
Bahir Dar Institute of Technology
Faculty of Computing
Advanced Programming Exam Bank
82. For an HttpSession, say session, how do you set an attribute pair with name lastName and value
Smith?
A. session.setValue("lastName", "Smith")
B. session.setAttribute("lastName", "Smith")
C. session.value("lastName", "Smith")
D. session.attribute("lastName", "Smith")
83. For a HttpSession, say session, how do you get its attribute?
A. session.getValue("lastName") C. session.value("lastName")
B. session.getAttribute("lastName") D. session.attribute("lastName")
84. A JSP file ends with __________.
A. .java extension C. .shtml extension
B. .html extension D. .jsp extension
85. You can run JSP from _____________.
A. any Web server.
B. any JVM.
C. any Web server that supports Java servlet and JSP.
D. any Web browser
86. _______________ is a JSP scriptlet.
A. <%= i %>
B. <%= Math.pow(2, 3) %>
C. <%! private long computeFactorial(int n) { if (n == 0)return 1;else return n *
computeFactorial(n - 1); } %>
D. <% for (int i = 0; i <= 10; i++) { %>
E. <!-- HTML Comment --%>
87. _______________ is a JSP declaration.
A. <%= i %>
B. <%= Math.pow(2, 3) %>
C. <%! private long computeFactorial(int n) { if (n == 0) return 1; else return n *
computeFactorial(n - 1); } %>
D. <% for (int i = 0; i <= 10; i++) { %>
E. <!-- HTML Comment -->
88. _______________ is a JSP comment.
A. <%= i %>
B. <%-- i --%>
C. <%! private long computeFactorial(int n) { if (n == 0) return 1; else return n *
computeFactorial(n - 1); } %>
D. <% for (int i = 0; i <= 10; i++) { %>
E. <!-- HTML Comment -->
89. The JSP explicit object out is actually _________.
A. response.getOutputStream() D. request.getWriter()
B. response.getWriter() E. application
C. request.getOutputStream()

10
Bahir Dar University
Bahir Dar Institute of Technology
Faculty of Computing
Advanced Programming Exam Bank
90. ________ is a statement that gives the JSP engine information about the JSP page.
A. A JSP implicit object C. A JSP expression
B. A JSP scriptlet D. A JSP directive
91. The ________ directive lets you provide information for the page, such as importing classes and
setting up content type. The page directive can appear anywhere in the JSP file.
A. page C. tablib
B. include D. import
92. A class is a JavaBeans component if ____________________.
A. it is a public class
B. it has a public constructor with no arguments
C. it is serializable.
D. All
93. ____ completely separates Web UI from Java code so the application developed using JSF is easy to
debug and maintain.
A. Java servlet D. PHP
B. JSP E. JavaScript
C. JSF
94. What is the Default Templating System for JSF?
A. Facelets C. Spring
B. ReXSL D. XUL
95. What is full form of JSF?
A. JavaScript Framework C. JavaServer Facility
B. JavaServer Faces D. None of the above
96. What are the different types of JSF events?
A. Pre Destroy Application Event C. PreRender View Event
B. Post Construct Application Event D. All of the above
97. What is the file extension of JSF?
A. .jsf C. .jvm
B. .js D. None of the above
98. A JSF application typically follows ________ in its life.
A. five steps C. four steps
B. six steps D. three steps
99. _______ is Often Used with JSF.
A. JCL C. Cobit
B. Ajax D. JCL
100. _________ Creates a Radio Button.
A. H:selectOneRadio C. H:selectOneMenu
B. H:outputLink D. None of the above

11

You might also like