You are on page 1of 31

PRJ311

Study online at quizlet.com/_3iz1hw

1. A How do you change the current layout manager for a container?


a) Use the setLayout method
b) Once created you cannot change the current layout manager of a component
c) Use the setLayoutManager method
d) Use the updateLayout method
2. A The client can connect to the server regardless of whether the port is in use or not.
A. true
B. false
3. A Given the following code, which set of code can be used to replace the comment so that the program displays time to the
console every second?

import java.applet.*;
import java.util.*;

public class Test extends Applet implements Runnable {


public void init() {
Thread t = new Thread(this);
t.start();
}

public void run() {


for(; ;) {
//display time every second
System.out.println(new Date().toString());
}
}
}
A. try { Thread.sleep(1000); } catch(InterruptedException e) { }
B. try { sleep(1000); } catch(InterruptedException e) { }
C. try { Thread.sleep(1000); } catch(RuntimeException e) { }
D. try { t.sleep(1000); } catch(InterruptedException e) { }
4. A Which of the following statements loads the JDBC-ODBC driver?
A. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
B. Class.forName(sun.jdbc.odbc.JdbcOdbcDriver)
C. Class.loadClass("sun.jdbc.odbc.JdbcOdbcDriver")
D. Class.loadClass(sun.jdbc.odbc.JdbcOdbcDriver)
5. A To run an object on a separate thread, the object must be a subclass of Thread.
A. true
B. false
6. A The Runnable interface is more general than the Thread class. You can convert any class that extends Thread to a class that
implements Runnable.
A. true
B. false
7. A 8 An exception occurs if the resume() method is invoked by a finished thread object.
A. true
B. false
8. A You can set a priority for an object of ThreadGroup using the setPrority() method.
A. false
B. true
9. A You should not directly invoke the run() method of a thread object.
A. true
B. false
10. A What is the default layouts for a applet, a frame and a panel?
Ans : For an applet and a panel, Flow layout is the default layout, whereas Border layout is default layout for a frame.
If a frame uses a Grid layout manager and does not contain any panels, then all the components within the frame are the same
width and height.
a) True
b) False.
11. A Which method returns the preferred size of a component?
a) getPreferredSize( )
b) getPreferred( )
c) getRequiredSize( )
d) getLayout( )
12. A Which of these interface is implemented by Thread class?
a) Runnable
b) Connections
c) Set
d) MapConnections
13. A The server listens for a connection request from a client using the following statement:
A. Socket s = serverSocket.accept()
B. Socket s = new Socket(ServerName);
C. Socket s = serverSocket.getSocket()
D. Socket s = new Socket(ServerName, port);
14. A A Frame's background color is set to Color. Yellow, and a Button's background color is to Color.Blue. Suppose the Button is
added to a Panel, which is added to the Frame. What background color will be used with the Panel?
a) Colr.Yellow
b) Color.Blue
c) Color.Green
d) Color.White
15. A Which of the following creates a List with 5 visible items and multiple selection enabled?
a) new List(5, true)
b) new List(true, 5)
c) new List(5, false)
d) new List(false,5)
16. A What method sets the size of the displayed JFrame?
A. setSize( int width, int height)
B. setSize( int height, int width)
C. setVisible( int width, int height)
D. setVisible( int height, int width)
17. A Which constructor creates a TextArea with 10 rows and 20 columns?
a) new TextArea(10, 20)
b) new TextArea(20, 10)
c) new TextArea(new Rows(10), new columns(20))
d) new TextArea(200)
18. A Which method is used to set the text of a Label object?
a) setText( )
b) setLabel( )
c) setTextLabel( )
d) setLabelText( )
19. A What are the immediate super classes of the following classes?
a) Container class
b) MenuComponent class
c) Dialog class
d) Applet class
e) Menu class
20. A A resource bundle is ___________
A. a Java class file or a text file that provides locale-specific information.
B. a Java source code the contains image, audio, and text files.
C. an audio file.
D. an image file.
21. A To display number in desired format, you have to use the NumberFormat class or its subclasses.
A. true
B. false
22. A The locale property is in the Component class, thus, every Java Swing component has the locale property.
A. true
B. false
23. A You can get year, month, day, hour, minute, and second from an instance of GregorianCalendar.
A. true
B. false
24. A You can get hour, minute and second from the Date class.
A. false
B. true
25. A 29 _________ specify the permissible values for an attribute.
A. Domain constraints
B. intra-relational constraints
C. Primary key constraints
D. inter-relational constraints
E. Foreign key constraints
26. A What is the return value from
stmt.executeUpdate("insert into T values (100, 'Smith')")
A. an int value indicating how many rows are effected from the invocation
B. void
C. a value indicating whether the SQL statement has been executed successfully
D. an object that contains the status of the execution
27. A Database meta data are retrieved through ____________.
A. a Connection object
B. a PreparedStatement object
C. a Statement object
D. a ResultSet Object
28. A Invoking Class.forName method may throw ___________.
A. ClassNotFoundException
B. RuntimeException
C. IOException
D. SQLException
29. A You should always invoke the unlock method in the finally clause.
A. true
B. false
30. A To create a statement on a Connection object conn, use
A. Statement statement = conn.createStatement();
B. Statement statement = conn.statement();
C. Statement statement = Connection.createStatement();
D. Statement statement = connection.create();
31. A What is synchronization in reference to a thread?
• A. It's a process of handling situations when two or more threads need access to a shared resource.
• B. Its a process by which many thread are able to access same shared resource simultaneously.
• C. Its a process by which a method is able to access many different threads simultaneously.
• D. Its a method that allow to many threads to access any information require.
32. A Which of the following sets the frame to 300 pixels wide by 200 high?

A. frm.setSize( 300, 200 );


B. frm.setSize( 200, 300 );
C. frm.paint( 300, 200 );
D. frm.setVisible( 300, 200 );
33. A 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.
b. Action-driven programming.
c. User-driven programming.
d. Mouse-driven programming
34. A 1. class newthread implements Runnable {
2. Thread t;
3. newthread() {
4. t = new Thread(this,"My Thread");
5. t.start();
6. }
7. public void run() {
8. System.out.println(t.getName());
9. }
10. }
11. class multithreaded_programing {
12. public static void main(String args[]) {
13. new newthread();
14. }
15. }
advertisements
a) My Thread
b) Thread[My Thread,5,main]
c) Compilation Error
d) Runtime Error
35. A . Which function of pre defined class Thread is used to check weather current thread being checked is still running?
• A. isAlive()
• B. Join()
• C. isRunning()
• D. Alive()
36. A . Which of these method of Thread class is used to Suspend a thread for a period of time?
• A. sleep()
• B. terminate()
• C. suspend()
• D. stop()
37. A What is the one component that nearly all GUI programs will have?
a. Frame
b. Mouse
c. Monitor
d. Button
38. A What is synchronization in reference to a thread?
a) It's a process of handling situations when two or more threads need access to a shared resource.
b) Its a process by which many thread are able to access same shared resource simultaneously.
c) Its a process by which a method is able to access many different threads simultaneously.
d) Its a method that allow to many threads to access any information require.
39. A import java.io.*;
class streams {
public static void main(String[] args) {
try {
FileOutputStream fos = new FileOutputStream("serial");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeInt(5);
oos.flush();
oos.close();
}
catch(Exception e) {
System.out.println("Serialization" + e);
System.exit(0);
}
try {
int z;
FileInputStream fis = new FileInputStream("serial");
ObjectInputStream ois = new ObjectInputStream(fis);
z = ois.readInt();
ois.close();
System.out.println(x);
}
catch (Exception e) {
System.out.print("deserialization");
System.exit(0);
}
}
}
a) 5
b) void
c) serialization
d) deserialization
40. a Pressing the Enter key on a JTextField generates _____________ events.

A. ActionEvent
B. ItemEvent
C. ComponentEvent
D. ContainerEvent
41. a Clicking a JList object generates __________ events.

A. ActionEvent and ItemEvent


B. ItemEvent and ComponentEvent
C. ComponentEvent and ContainerEvent
D. ActionEvent and ContainerEvent
42. a The coordinate of the upper-left corner of a frame is __________.

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.*;

public class Test {


public static void main(String[] args) {
JFrame f1 = new JFrame("My Frame");
JFrame f2 = f1;
JFrame f3 = f2;
f1.setVisible(true);
f2.setVisible(true);
f3.setVisible(true);
}
}

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. Socket s = new Socket(ServerName, port);


B. Socket s = serverSocket.accept();
C. Socket s = serverSocket.getSocket();
D. Socket s = new Socket(ServerName);
53. a When creating a client on a server port that is already in use, __________.

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.*;

class helloFrame ___________ Frame


{
public void ___________( Graphics g )
{
g.___________("Hello", 10, 50 );
}
}

public class Tester


{
public static void main ( String[] args )
{
helloFrame frm = new helloFrame();
frm.setSize( 150, 100 );
frm.setVisible( true );
}
}
a. import, drawString, paint
b. extends, paint, drawString
c. extends, draw, paint
d. include, drawString, paint
61. B If a frame uses its default layout manager and does not contain any panels, then all the components within the frame are the same
width and height.
a) True
b) False.
62. B With a Border layout manager, the component at Center gets all the space that is left over, after the components at North and
South have been considered.
a) True
b) False
63. B Which of these is an interface for control over serialization and deserialization?
a) Serializable
b) Externalization
c) FileFilter
d) ObjectInput
64. B Which of these class extend InputStream class?
a) ObjectStream
b) ObjectInputStream
c) ObjectOutput
d) ObjectInput
65. B To connect to a local MySQL database named test, use
A. Connection connection = DriverManager.getConnection(jdbc:mysql://localhost/test);
B. Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test");
C. Connection connection = DriverManager.connect("jdbc:mysql://localhost/test");
D. Connection connection = DriverManager.getConnection("mysql:jdbc://localhost/test");
66. B You want to construct a text area that is 80 character-widths wide and 10 character-heights tall. What code do you use?
a) new TextArea(80, 10)
b) new TextArea(10, 80)
67. B The CheckboxGroup class is a subclass of the Component class.
a) True
b) False
68. B Fill in the blanks so that this program displays a JFrame:>

import java.awt.*;
import javax.swint.*;

public class microGUI


{
public static void main ( String[] args )
{
JFrame frm = new ___________();
frm.___________( 150, 100 );
frm.___________( true );
}
}
A. Form, setVisible, setOn
B. JFrame, setSize, setVisible
C. Frame, setVisible, setSize
D. Window, setSize, paint
69. B 1. Which of these method is used to implement Runnable interface?
a) stop()
b) run()
c) runThread()
d) stopThread()
70. B In a relational data model, _________ defines the representation of the data.
A. SQL
B. Structure
C. Language
D. Integrity
71. B getInputStream() and getOutputStream() are used to produce InputStream and OutputStream on the socket.
A. false
B. true
72. B Which of these method can be used to make the main thread to be executed last among all the threads?
a) stop()
b) sleep()
c) join()
d) call()
73. B You must specify a name for the thread group that you will create.
A. false
B. true
74. B Which of these method can be used to make the main thread to be executed last among all the threads?
• A. stop()
• B. sleep()
• C. join()
75. B class newthread implements Runnable {
2. Thread t;
3. newthread() {
4. t = new Thread(this,"My Thread");
5. t.start();
6. }
7. public void run() {
8. System.out.println(t);
9. }
10. }
11. class multithreaded_programing {
12. public static void main(String args[]) {
13. new newthread();
14. }
15. }
a) My Thread
b) Thread[My Thread,5,main]
c) Compilation Error
d) Runtime Error
76. B The server can create a server socket regardless of whether the port is in use or not.
A. true
B. false
77. B 17. What is multithreaded programming?
• A. It's a process in which two different processes run simultaneously.
• B. It's a process in which two or more parts of same process run simultaneously.
• C. Its a process in which many different process are able to access same information.
• D. Its a process in which a single process can access information from many sources.
78. B An applet cannot connect to a server program on a Web server where the applet was loaded.
A. false
B. true
79. B You can transmit objects over the socket.
A. false
B. true
80. B The URL constructor throws MalformedURLException if the URL is syntactically incorrect.
A. true
B. false
81. B You cannot get instances of InputStream or OutputStream because InputStream and OutputStream are abstract classes.
A. true
B. false
82. B You can find all the available locales from a Swing object.
A. true
B. false
83. B The TimeZone class has a static method for obtaining all the available time zone IDs.
A. false
B. true
84. B You can get all the available locales from an instance of Calendar, Collator, DateFormat, or NumberFormat.
A. false
B. true
85. B class newthread extends Thread {
2. newthread() {
3. super("My Thread");
4. start();
5. }
6. public void run() {
7. System.out.println(this);
8. }
9. }
10. class multithreaded_programing {
11. public static void main(String args[]) {
12. new newthread();
13. }
14. }
a) My Thread
b) Thread[My Thread,5,main]
c) Compilation Error
d) Runtime Error
86. b o 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();
87. b When a client requests connection to a server that has not yet started, __________.

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. g.drawLine(0, 0, 100, 100)


B. g.drawLine(0, 0, getWidth(), getHeight())
C. g.drawLine(0, 0, getHeight(), getHeight())
D. g.drawLine(0, 0, getWidth(), getWidth())
91. b To wrap a line in a text area jta on words, invoke ____________.

A. jta.setWrapStyleWord(false)
B. jta.setWrapStyleWord(true)
C. jta.wrapStyleWord()
D. jta.wrapWord()
92. b The header for the paintComponent method is ________________.

A. private void paintComponent(Graphics g)


B. protected void paintComponent(Graphics g)
C. public void paintComponent(Graphics g)
D. protected void paintComponent()
93. b What is best to describe the relationship between a container and a layout manager?

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.*;

public class Test {


public static void main(String[] args) {
JFrame frame = new JFrame("My Frame");
frame.add(new JButton("OK"));
frame.add(new JButton("Cancel"));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setVisible(true);
}
}

A. Only button OK is displayed.


B. Only button Cancel is displayed.
C. Both button OK and button Cancel are displayed and button OK is displayed on the left side of button OK.
D. Both button OK and button Cancel are displayed and button OK is displayed on the right side of button OK.
97. b _______________ returns the selected item on a JComboBox jcbo.

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.*;

public class Test {


public static void main(String[] args) {
Component c = new JButton("OK");
JFrame frame = new JFrame("My Frame");
frame.add(c);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

A. You cannot assign a JButton to a variable of java.awt.Component.


B. You can only add c to a container because c's type is Component.
C. You cannot add a Swing component directly to a JFrame using add(c) prior to JDK 1.4, but it is OK in JDK 1.5.
D. You cannot create a JFrame using new JFrame("My Frame").
126. c The correct order of the following three statements is ___________.

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. g.drawRect(20, 50, 20, 20)


B. g.drawRectFill(20, 20, 20, 50)
C. g.drawRect(20, 20, 20, 50)
D. g.drawRectFill(20, 50, 20, 20)
128. c The method __________ appends a string s into the text area jta.

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.*;

public class Test extends JFrame {


public Test() {
add(new MyDrawing("Welcome to Java!"));
}

public static void main(String[] args) {


JFrame frame = new JFrame();
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

class MyDrawing extends JPanel {


String message;

public MyDrawing(String message) {


this.message = message;
}

public void paintComponent(Graphics g) {


super.paintComponent(g);

g.drawString(message, 20 ,20);
}
}

A. The program runs fine and displays Welcome to Java!


B. The program would display Welcome to Java! if new JFrame() is replaced by Test().
C. The program would display Welcome to Java! if new JFrame() is replaced by new Test().
D. The program would display Welcome to Java! if new JFrame() is replaced by new Test("My Frame").
132. c The ____________ method in the InetAddress class returns the IP address.

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. The ServerSocket class


B. The Socket class
C. The InetAddress class
D. The Connection interface
134. c To draw graphics, it is better to define a class that extends ________ and override the paintComponent method.

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.*;

public class Test extends JFrame {


public static void main(String[] args) {
JFrame f1 = new Test();
JFrame f2 = new Test();
JFrame f3 = new Test();
f1.setVisible(true);
f2.setVisible(true);
f3.setVisible(true);
}
}

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?

A. A container is another name for an array or vector.


B. A container is any class that is made up of other classes.
C. A container is a primitive variable that contains the actual data.
D. A container is an object like a frame that has other GUI components placed inside of it.
156. D class newthread extends Thread {
2. Thread t;
3. newthread() {
4. t = new Thread(this,"My Thread");
5. t.start();
6. }
7. public void run() {
8. try {
9. t.join()
10. System.out.println(t.getName());
11. }
12. catch(Exception e) {
13. System.out.print("Exception");
14. }
15. }
16. }
17. class multithreaded_programing {
18. public static void main(String args[]) {
19. new newthread();
20. }
21. }
a) My Thread
b) Thread[My Thread,5,main]
c) Exception
d) Runtime Error
157. D Which layout should you use to organize the components of a container in a
tabular form?
a) CardLayout
b) BorederLayout
c) FlowLayout
d) GridLayout
158. D What will happen if two thread of same priority are called to be processed simultaneously?
• A. Any one will be executed first lexographically
• B. Both of them will be executed simultaneously
• C. None of them will be executed
• D. It is dependent on the operating system.
159. D What is a container object in GUI programming?
a. A container is another name for an array or vector.
b. A container is any class that is made up of other classes.
c. A container is a primitive variable that contains the actual data.
d. A container is an object like a Frame that has other GUI components placed inside of it.
160. D . Which of these class is used to make a thread?
• A. String
• B. System
• C. Thread
• D. Runnable
161. D When creating a server on a port that is already in use, __________.
A. the server encounters a fatal error and must be terminated.
B. the server is blocked until the port is available.
C. the server is created with no problems.
D. java.net.BindException occurs.
162. D To connect to a server running on the same machine with the client, which of the following can be used for the hostname?
A. InetAddress.getLocalHost(),
B. "127.0.0.1"
C. "localhost"
D. All of the above.
163. D What is a Graphics object?
a. The Graphics object represents the part of the Frame that you can draw on.
b. The Graphics object represents the whole Frame.
c. The Graphics object represents the entire monitor.
d. The Graphics object represents the graphics board.
164. D Which of these is a process of extracting/removing the state of an object from a stream?
a) Serialization
b) Externalization
c) File Filtering
d) Deserialization
165. D Which of these process occur automatically by java run time system?
a) Serialization
b) Memory allocation
c) Deserialization
d) All of the mentioned
166. 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 cases.
167. D Which of these interface extends DataInput interface?
a) Serializable
b) Externalization
c) ObjectOutput
d) ObjectInput
168. D What is the output of this program?

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 __________.

A. g.drawOval(50, 50, 20, 20)


B. g.drawOval(50, 50, 40, 40)
C. g.drawOval(30, 30, 20, 20)
D. g.drawOval(30, 30, 40, 40)
179. d Analyze the following code.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Test1 extends JFrame {


public Test1() {
add(new MyCanvas());
}

public static void main(String[] args) {


JFrame frame = new Test1();
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

class MyCanvas extends JPanel {


private String message;

public void setMessage(String message) {


this.message = message;
}

public void paintComponent(Graphics g) {


super.paintComponent(g);

g.drawString(message, 20, 20);


}
}

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.*;

public class Test {


public static void main(String[] args) {
JFrame frame = new JFrame("My Frame");
frame.add(new MyDrawing("Welcome to Java!"));
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setVisible(true);
}
}

class MyDrawing extends JPanel {


String message;

public MyDrawing(String message) {


this.message = message;
}

public void paintcomponent(Graphics g) {


super.paintComponent(g);

g.drawString(message, 20 ,20);
}
}

A. The program runs fine and displays Welcome to Java!


B. The program has a compile error because the paintcomponent should be spelled as paintComponent.
C. The program has a runtime error because the paintcomponent should be spelled as paintComponent.
D. The program runs, but it does not display the message.
E. It is a runtime error to invoke the setVisible(true) twice.
181. d A ServerSocket can connect to ________ clients.

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 __________.

A. g.fillOval(50, 50, 20, 30)


B. g.fillOval(50, 50, 40, 30)
C. g.fillOval(30, 30, 20, 30)
D. g.fillOval(30, 30, 40, 30)
E. g.fillOval(40, 35, 20, 30)

You might also like