Professional Documents
Culture Documents
import java.applet.*;
import java.util.*;
A. ActionEvent
B. ItemEvent
C. ComponentEvent
D. ContainerEvent
41. a Clicking a JList object generates __________ events.
A. (0, 0)
B. (25, 25)
C. (100, 100)
D. (10, 10)
43. a Suppose a button jbt is placed in a frame, the coordinate of the button within the content pane of the frame is _______.
A. (jbt.getX(), jbt.getY())
B. (jbt.x, jbt.y)
C. cannot be obtained
D. (0, 0)
44. a __________ are referred to as heavyweight components.
A. AWT components
B. Swing components
C. GUI components
D. Non-GUI components
45. a You can draw graphics on any GUI components.
A. true
B. false
46. a To repaint graphics, invoke __________ on a Swing component.
A. repaint()
B. update()
C. paintComponent()
D. init()
47. a Swing components that don't rely on native GUI are referred to as ___________.
A. lightweight components
B. heavyweight components
C. GUI components
D. non-GUI components
48. a How many frames are displayed?
import javax.swing.*;
A. 1.
B. 2.
C. 3.
49. a 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)
50. a The method __________ adds a text area jta to a scrollpane jScrollPane.
A. jScrollPane.add(jta)
B. jScrollPane.insert(jta)
C. jScrollPane.addItem(jta)
D. None of the above.
51. a What should you use to position a Button within an application Frame so that the size of the Button is NOT affected by the Frame
size?
A. a FlowLayout
B. a GridLayout
C. the center area of a BorderLayout
D. the East or West area of a BorderLayout
E. the North or South area of a BorderLayout
52. a The client requests a connection to a server using the following statement:
A. the client can connect to the server regardless of whether the port is in use.
B. java.net.BindException occurs.
C. the client is blocked until the port is available.
D. the client encounters a fatal error and must be terminated.
54. a Clicking a JButton object generates __________ events.
A. ActionEvent
B. ItemEvent
C. ComponentEvent
D. ContainerEvent
55. B When using the GridBagLayout manager, each new component requires a new instance of the GridBagConstraints class. Is this
statement true or false?
a) true
b) false
56. B To execute a SELECT statement "select * from Address" on a Statement object stmt, use
A. stmt.executeUpdate("select * from Address");
B. stmt.executeQuery("select * from Address");
C. stmt.query("select * from Address");
D. stmt.execute("select * from Address");
57. B Usually GUI programs are written by using existing software components provided in a toolkit. The Java toolkit used in this chapter
is the:
a. GUI toolkit
b. Abstract Windowing Toolkit
c. Graphics Event Toolkit
d. Java Enhancement Toolkit
58. B 22 A database URL for an access database source test is ________.
A. jdbcodbc:test
B. jdbc:odbc:test
C. test
D. sun.jdbc:odbc:test
59. B An Applet has its Layout Manager set to the default of FlowLayout. What code would be the correct to change to another Layout
Manager?
a) setLayoutManager(new GridLayout());
b) setLayout(new GridLayout(2,2));
c) setGridLayout(2,2,))
d setBorderLayout();
60. B Fill in the blanks so that the following draws a Frame containing "Hello".
import java.awt.*;
import java.awt.*;
import javax.swint.*;
A. java.net.BindException occurs.
B. java.net.ConnectionException occurs.
C. the client is blocked until the server is started.
D. the client encounters a fatal error and must be terminated.
88. b How many items can be selected from a JComboBox object at a time?
A. 0
B. 1
C. 2
D. Unlimited
89. b To create an Image object from an ImageIcon object imageIcon, use the __________ method.
A. imageIcon.image()
B. imageIcon.getImage()
C. imageIcon.setImage()
D. imageIcon.returnImage()
90. b Given a Graphics object g, to draw a line from the upper left corner to the bottom right corner, you use __________.
A. jta.setWrapStyleWord(false)
B. jta.setWrapStyleWord(true)
C. jta.wrapStyleWord()
D. jta.wrapWord()
92. b The header for the paintComponent method is ________________.
A. Association
B. Aggregation
C. Composition
D. Inheritance
94. b What layout manager should you use so that every component occupies the same size in the container?
A. a FlowLayout
B. a GridLayout
C. a BorderLayout
D. any layout
95. b To wrap a line in a text area jta, invoke ____________.
A. jta.setLineWrap(false)
B. jta.setLineWrap(true)
C. jta.WrapLine()
D. jta.wrapText()
96. b Analyze the following code.
import java.awt.*;
import javax.swing.*;
A. jcbo.getSelectedIndex()
B. jcbo.getSelectedItem()
C. jcbo.getSelectedIndices()
D. jcbo.getSelectedItems()
98. b You can obtain the server's hostname by invoking _________ on an applet.
A. getCodeBase().host()
B. getCodeBase().getHost()
C. getCodeBase().hostName()
D. getCodeBase().getHostName()
99. b Clicking a JComboBox object generates an ItemEvent event,
A. if an item is selected.
B. if a new item is selected.
100. C . Which of these method waits for the thread to treminate?
• A. sleep()
• B. isAlive()
• C. join()
• D. stop()
101. C Which of these is a method of ObjectInput interface used to deserialize an object from a stream?
a) int read()
b) void close()
c) Object readObject()
d) Object WriteObject()
102. C What is the default value of priority variable MIN_PRIORITY AND MAX_PRIORITY?
a) 0 & 256
b) 0 & 1
c) 1 & 10
d) 1 & 256
103. C The data in DefaultTableModel are stored in ___________.
A. an ArrayList
B. an array
C. a Vector
D. a LinkedList
104. C Which of these method is used to find out that a thread is still running or not?
a) run()
b) Alive()
c) isAlive()
d) checkRun()
105. C When is the paint() method of a frame object called?
a. The user calls it to display the frame.
b. The main() method calls it once when the program starts.
c. The Java system calls it every time it decides to display the frame.
d. The Java system calls it once when the program starts.
106. C Which of these method waits for the thread to treminate?
a) sleep()
b) isAlive()
c) join()
d) stop()
107. C class newthread extends Thread {
2. Thread t;
3. newthread() {
4. t = new Thread(this,"New Thread");
5. t.start();
6. }
7. public void run() {
8. System.out.println(t.isAlive());
9. }
10. }
11. class multithreaded_programing {
12. public static void main(String args[]) {
13. new newthread();
14. }
15. }
a) 0
b) 1
c) true
d) false
108. C Which of these method of Thread class is used to find out the priority given to a thread?
• A. get()
• B. ThreadPriority()
• C. getPriority()
• D. getThreadPriority()
109. C The three software parts of a GUI program are:
a. Windows, Buttons, Mice
b. GUI Components, Graphics, Code
c. GUI Components, Event Listeners, Application Code
d. Frames, Code, Events
110. C Which of these method is used to explicitly set the priority of a thread?
a) set()
b) make()
c) setPriority()
d) makePriority()
111. C . Which of these are types of multitasking?
• A. Process based
• B. Thread based
• C. Process and Thread based
• D. None of the mentioned
112. C An application has a frame that uses a Border layout manager. Why is it probably not a good idea to put a vertical scroll bar at
North in the frame?
a) The scroll bar's height would be its preferred height, which is not likely to be enough.
b) The scroll bar's width would be the entire width of the frame, which would be much wider than necessary.
c) Both a and b.
d) Neither a nor b. There is no problem with the layout as described.
113. C The data in DefaultTableModel are stored in ___________.
A. an array
B. a LinkedList
C. a Vector
D. an ArrayList
114. C A database URL for a MySQL database named test on host panda.armstrong.edu is ________.
A. jdbc:mysql:/panda.armstrong.edu/test
B. jdbc.mysql://panda.armstrong.edu/test
C. jdbc:mysql://panda.armstrong.edu/test
D. jdbc.mysql.//panda.armstrong.edu/test
115. C 31 What information may be obtained from a ResultSetMetaData object?
A. number of rows in the result set
B. JDBC driver name and version
C. number of columns in the result set
D. database URL and product name
116. C 32 ________ is an attribute or a set of attributes that uniquely identifies the relation.
A. A primary key
B. A key
C. A superkey
D. A candidate key
117. C 34 Where is com.mysql.jdbc.Driver located?
A. in the standard Java library bundled with JDK
B. in a JAR file classes12.jar
C. in a JAR file mysqljdbc.jar
118. C Which of the following code is correct to obtain hour from a Calendar object cal?
A. cal.getHour();
B. cal.get(Hour);
C. cal.get(Calendar.HOUR);
D. cal.hour();
119. C A text field has a variable-width font. It is constructed by calling new TextField("iiiii"). What happens if you change the contents of
the text field to "wwwww"? (Bear in mind that i is one of the narrowest characters, and w is one of the widest.)
a) The text field becomes wider.
b) The text field becomes narrower.
c) The text field stays the same width; to see the entire contents you will have to scroll by using the ß and à keys.
d) The text field stays the same width; to see the entire contents you will have to scroll by using the text field's horizontal scroll
bar.
120. C . Which of these packages contain all the Java's built in exceptions?
• A. java.io
• B. java.util
• C. java.lang
• D. java.net
121. C Suppose a Panel is added to a Frame and a Button is added to the Panel. If the Frame's font is set to 12-point TimesRoman, the
Panel's font is set to 10-point TimesRoman, and the Button's font is not set, what font will be used to display the Button's label?
a) 12-point TimesRoman
b) 11-point TimesRoman
c) 10-point TimesRoman
d) 9-point TimesRoman
122. C Which Component method is used to access a component's immediate Container?
a) getVisible()
b) getImmediate
c) getParent()
d) getContainer
123. C What is the name of the Swing class that is used for frames?
A. Window
B. Frame
C. JFrame
D. SwingFrame
124. C class newthread implements Runnable {
2. Thread t;
3. newthread() {
4. t = new Thread(this,"My Thread");
5. t.start();
6. }
7. }
8. class multithreaded_programing {
9. public static void main(String args[]) {
10. new newthread();
11. }
12. }
a) My Thread
b) Thread[My Thread,5,main]
c) Compilation Error
d) Runtime Error
125. c Analyze the following code.
import java.awt.*;
import javax.swing.*;
1. frame.setLocationRelativeTo(null);
2. frame.setSize(100, 200);
3. frame.setVisible(true);
A. 1 2 3
B. 1 3 2
C. 2 1 3
D. 3 2 1
127. c Given a Graphics object g, to draw an outline of a rectangle of width 20 and height 50 with the upper-left corner at (20, 20), you
use __________.
A. jta.setText(s)
B. jta.appendText(s)
C. jta.append(s)
D. jta.insertText(s)
129. c Which of the following statements is for placing the frame's upper left corner to (200, 100)?
A. frame.setLocation(100, 100)
B. frame.setLocation(100, 200)
C. frame.setLocation(200, 100)
D. frame.setLocation(200, 200)
130. c The method __________ adds an item s into a JComboBox jcbo.
A. jcbo.add(s)
B. jcbo.addChoice(s)
C. jcbo.addItem(s)
D. jcbo.addObject(s).
131. c import java.awt.*;
import javax.swing.*;
g.drawString(message, 20 ,20);
}
}
A. getIP()
B. getIPAddress()
C. getHostAddress()
D. getAddress()
133. c ______________ models an IP address, which can be used to find the host name and IP address of the client.
A. JLabel
B. JButton
C. JPanel
D. JComponent
135. c ____________ is a component that enables the user to choose a single value or multiple values.
A. A text field
B. A combo box
C. A list
D. A label
136. c ______________ sets the background of the selected item in list jlst to yellow.
A. jlst.setBackground(Color.YELLOW)
B. jlst.setSelectedBackground(Color.YELLOW)
C. jlst.setSelectionBackground(Color.YELLOW)
D. jlst.setSelectionbackground(Color.YELLOW)
137. c You should override the __________ method to draw things on a Swing component.
A. repaint()
B. update()
C. paintComponent()
D. init()
138. c Which component cannot be added to a container?
A. JPanel
B. JButton
C. JFrame
D. JComponent
139. c How many frames are displayed?
import javax.swing.*;
A. 1.
B. 2.
C. 3.
D. 0.
140. c What is best to describe the relationship between a container and a SWing GUI object in the container?
A. Association
B. Aggregation
C. Composition
D. Inheritance
141. c Invoking __________ returns the width of the string in a FontMetrics object fm.
A. getLength(s)
B. fm.getHeight(s)
C. fm.stringWidth(s)
D. fm.getWidth(s)
142. D Which of these statement is incorrect?
a) A thread can be formed by implementing Runnable interface only.
b) A thread can be formed by a class that extends Thread class.
c) start() method is used to begin execution of the thread.
d) run() method is used to begin execution of a thread before start() method in special
143. D class newthread implements Runnable {
2. Thread t;
3. newthread() {
4. t = new Thread(this,"New Thread");
5. t.start();
6. }
7. public void run() {
8. t.setPriority(Thread.MAX_PRIORITY);
9. System.out.println(t);
10. }
11. }
12. class multithreaded_programing {
13. public static void main(String args[]) {
14. new newthread();
15. }
16. }
a) Thread[New Thread,0,main]
b) Thread[New Thread,1,main]
c) Thread[New Thread,5,main]
d) Thread[New Thread,10,main]
144. D 1. class newthread implements Runnable {
2. Thread t;
3. newthread() {
4. t1 = new Thread(this,"Thread_1");
5. t2 = new Thread(this,"Thread_2");
6. t1.start();
7. t2.start();
8. }
9. public void run() {
10. t2.setPriority(Thread.MAX_PRIORITY);
11. System.out.print(t1.equals(t2));
12. }
13. }
14. class multithreaded_programing {
15. public static void main(String args[]) {
16. new newthread();
17. }
18. }
a) true
b) false
c) truetrue
d) falsefalse
145. D import java.io.*;
class serialization {
public static void main(String[] args) {
try {
Myclass object1 = new Myclass("Hello", -7, 2.1e10);
FileOutputStream fos = new FileOutputStream("serial");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(object1);
oos.flush();
oos.close();
}
catch(Exception e) {
System.out.println("Serialization" + e);
System.exit(0);
}
try {
int x;
FileInputStream fis = new FileInputStream("serial");
ObjectInputStream ois = new ObjectInputStream(fis);
x = ois.readInt();
ois.close();
System.out.println(x);
}
catch (Exception e) {
System.out.print("deserialization");
System.exit(0);
}
}
}
class Myclass implements Serializable {
String s;
int i;
double d;
Myclass(String s, int i, double d){
this.d = d;
this.i = i;
this.s = s;
}
}
a) -7
b) Hello
c) 2.1E10
d) deserialization
146. D Which method is method to set the layout of a container?
a) startLayout( )
b) initLayout( )
c) layoutContainer( )
d) setLayout( )
147. D You can invoke ______________ on a Socket object, say socket, to obtain an InetAddress object.
A. socket.obtainInetAddress();
B. socket.InetAddress();
C. socket.retrieveInetAddress();
D. socket.getInetAddress();
148. D How do you indicate where a component will be positioned using Flowlayout?
a) North, South,East,West
b) Assign a row/column grid reference
c) Pass a X/Y percentage parameter to the add method
d) Do nothing, the FlowLayout will position the component
149. D 3 Which of the following expressions must be true if you create a thread using Thread = new Thread(object)?
A. object instanceof Applet
B. object instanceof Thread
C. object instanceof Frame
D. object instanceof Runnable
150. D To obtain an ObjectInputStream from a socket, use ________.
A. socket.objectInputStream()
B. socket.getInputStream()
C. socket.getObjectInputStream()
D. socket.getObjectStream()
151. D Which of the following layout managers honours the preferred size of a component:
A) CardLayout
B) FlowLayout
C) BorderLayout
D) GridLayout
152. D In Java, what do you call an area on the screen that has nice borders and various buttons along the top border?
A. A window.
B. A screen.
C. A box.
D. A frame.
153. D Which of these statements is incorrect?
• A. By multithreading CPU's idle time is minimized, and we can take maximum use of it.
• B. By multitasking CPU's idle time is minimized, and we can take maximum use of it.
• C. Two thread in Java can have same priority
• D. A thread can exist only in two states, running and blocked.
154. D The size of a frame on the screen is measured in:
A. inches
B. nits
C. dots
D. pixels
155. D What is a container object in GUI programming?
import java.io.*;
class serialization {
public static void main(String[] args) {
try {
Myclass object1 = new Myclass("Hello", -7, 2.1e10);
FileOutputStream fos = new FileOutputStream("serial");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(object1);
oos.flush();
oos.close();
}
catch(Exception e) {
System.out.println("Serialization" + e);
System.exit(0);
}
try {
int x;
FileInputStream fis = new FileInputStream("serial");
ObjectInputStream ois = new ObjectInputStream(fis);
x = ois.readInt();
ois.close();
System.out.println(x);
}
catch (Exception e) {
System.out.print("deserialization");
System.exit(0);
}
}
}
class Myclass implements Serializable {
String s;
int i;
double d;
Myclass(String s, int i, double d){
this.d = d;
this.i = i;
this.s = s;
}
}
a) -7
b) Hello
c) 2.1E10
d) deserialization
169. D What is the output of this program?
import java.io.*;
class streams {
public static void main(String[] args) {
try {
FileOutputStream fos = new FileOutputStream("serial");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeFloat(3.5);
oos.flush();
oos.close();
}
catch(Exception e) {
System.out.println("Serialization" + e);
System.exit(0);
}
try {
FileInputStream fis = new FileInputStream("serial");
ObjectInputStream ois = new ObjectInputStream(fis);
ois.close();
System.out.println(ois.available());
}
catch (Exception e) {
System.out.print("deserialization");
System.exit(0);
}
}
}
a) 1
b) 2
c) 3
d) 4
170. D import java.io.*;
class streams {
public static void main(String[] args) {
try {
FileOutputStream fos = new FileOutputStream("serial");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeFloat(3.5);
oos.flush();
oos.close();
}
catch(Exception e) {
System.out.println("Serialization" + e);
System.exit(0);
}
try {
FileInputStream fis = new FileInputStream("serial");
ObjectInputStream ois = new ObjectInputStream(fis);
System.out.println(ois.available());
}
catch (Exception e) {
System.out.print("deserialization");
System.exit(0);
}
}
}
a) 1
b) 2
c) 3
d) 4
171. D 1. class newthread extends Thread {
2. Thread t1,t2;
3. newthread() {
4. t1 = new Thread(this,"Thread_1");
5. t2 = new Thread(this,"Thread_2");
6. t1.start();
7. t2.start();
8. }
9. public void run() {
10. t2.setPriority(Thread.MAX_PRIORITY);
11. System.out.print(t1.equals(t2));
12. }
13. }
14. class multithreaded_programing {
15. public static void main(String args[]) {
16. new newthread();
17. }
18. }
a) true
b) false
c) truetrue
d) falsefalse
172. D Result set meta data are retrieved through ____________.
A. a Connection object
B. a PreparedStatement object
C. a Statement object
D. a ResultSet Object
173. D 27 In a relational data model, _________ imposes constraints on the data.
A. Language
B. Structure
C. SQL
D. Integrity
174. D How do you create a condition on a lock?
A. Condition condition = Lock.getCondition();
B. Condition condition = Lock.newCondition();
C. Condition condition = lock.getCondition();
D. Condition condition = lock.newCondition();
175. d How many items can be added into a JComboBox object?
A. 0
B. 1
C. 2
D. Unlimited
176. d What is best to describe the relationship between JComponent and JButton?
A. Association
B. Aggregation
C. Composition
D. Inheritance
177. d Which of the following classes is a heavyweight component?
A. JButton
B. JTextField
C. JPanel
D. JFrame
178. d Given a Graphics object g, to draw an circle with radius 20 centered at (50, 50), you use __________.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
A. The program runs fine and displays nothing since you have not set a string value.
B. The program would display Welcome to Java! if you replace new MyCanvas() by new MyCanvas("Welcome to Java!").
C. The program has a compile error because new Test1() is assigned to frame.
D. The program has a NullPointerException since message is null when g.drawString(message, 20, 20) is executed.
180. d import java.awt.*;
import javax.swing.*;
g.drawString(message, 20 ,20);
}
}
A. one
B. two
C. ten
D. an unlimited number of
182. e To obtain an ObjectOutputStream from a socket, use ________.
A. socket.getOutputStream()
B. socket.getObjectStream()
C. socket.getObjectOutputStream()
D. socket.objectOutputStream()
E. new ObjectOutputStream(socket.getOutputStream())
183. e You can create a JTree using __________.
A. new JTree()
B. new JTree(new DefaultTreeModel())
C. new JTree(new Object[]{"red", "green", "blue"})
D. new JTree(new Vector())
E. All
184. e Given a Graphics object g, to draw a filled oval with width 20 and height 30 centered at (50, 50), you use __________.