Java Prsolutions
Java Prsolutions
com
a. The program has a compilation error because it is defined in both the main() method and the
constructor Test().
b. The program compiles fine, but it does not run because you cannot use the keyword this in
the constructor.
c. The program compiles and runs and displays nothing.
d. The program compiles and runs and displays test.
3. Analyze the following code:
public class Test implements Runnable {
T he l k e d i ma g e c a n o t b e
d i s ai ny e d . T he f i l ma y h a v eb e n
pl e
mo v e d , r e n a me d , o r d e l e d . V e ri f
t th e l i n o i n t s t o t h e ct e o re c t y
h at k p
f a nd l t i on .
i o ca
le
a. The program does not compile because this cannot be referenced in a static
method.
b. The program compiles fine, but it does not print anything because t does not invoke the
run() method.
c. The program compiles and runs fine and displays test on the console.
d. Runtime Error
http://www.prsolutions08.blogspot.com
a. The program does not compile because the start() method is not defined in the Test
class.
b. The program compiles, but it does not run because the start() method is not defined.
c. The program compiles, but it does not run because the run() method is not implemented.
d. The program compiles and runs fine.
5. You can use the _ _ _ _ _ _ _ _ method to force one thread to wait for another thread to
finish.
a. sleep(long milliseconds)
b. yield()
c. stop()
d. join()
6. Analyze the following code:
public abstract class Test implements Runnable {
public void do Something() {
};
}
a. The program will not compile because it does not implement the run() method.
b. The program will not compile because it does not contain abstract methods.
c. The program compiles fine.
d. Runtime Error.
7. Which of the following expressions must be true if you create a thread using Thread =
new Thread(object)?
a. yield()
b. stop();
c. resume();
d. suspend();
9. You can use the _ _ _ _ _ _ _ _ _ method to temporarily to release time for other
threads.
a. sleep(int milliseconds)
b. yield()
c. stop()
d. suspend()
10. Which of the following statement is not defined in the Object class?
a. sleep(long milliseconds)
b. wait()
c. notify()
d. notifyAll()
11. When you run the following program, what will happen?
public class Test extends Thread {
public static void main(String[] args) {
http://www.prsolutions08.blogspot.com
a. Nothing is displayed.
b. The program displays test twice.
c. The program displays test once.
d. An illegal java.lang. Illegal Thread State Exception may be thrown because you just
started thread and thread might have not yet finished before you start it again.
12. 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. synchronize
b. synchronizing
c. synchronized
d. Synchronized
15. Which of the following statement is false?
a. A synchronized instance method doesn't acquire a lock on the object for which the
method was invoked.
b. A synchronized instance method acquires a lock on the class of the object for which the
method was invoked.
c. A synchronized statement can be used to acquire a lock on any object, not just this object,
when executing a block of the code in a method.
d. A synchronized statement is placed inside a synchronized block.
18. Which of the following method is a static in java.lang.Thread?
a. run()
b. sleep(long)
c. start()
d. join()
19. Which of the following methods in Thread throws Interrupted Exception?
a. run()
b. sleep(long)
c. start()
d. yield()
20. Suppose there are three Runnable tasks, task1, task2, task3. How do you run them in
a thread pool with 2 fixed threads?
a. condition.await();
b. condition.wait();
c. condition.waiting();
d. condition.waited();
24. Which method on a condition should you invoke to wake all waiting threads.
a. condition.wake();
b. condition.signal();
c. condition.wakeAll();
d. condition.signalAll();
25. You cannot create a blocking queue using _ _ _ _ _ _ _ _ _ _ _ _ _ .
a. ArrayBlockingQueue
http://www.prsolutions08.blogspot.com
b. LinkedBlockingQueue
c. PriorityBlockingQueue
d. PriorityQueue
26. Which of the following is not a correct statement
a. The wait(), notify(), and notifyAll() methods must be invoked from a synchronized method or
a synchronized block.
b. When wait() is invoked, it pauses the thread and releases the lock on the object
simultaneously. When the thread is restarted after being notified, the lock is automatically
reacquired.
c. The notify() method can wake only one waiting thread.
d. An exception would occur if no thread is waiting on the object when the notify()
method is invoked on the object.
29. Which of the following statement is false?
a. Semaphores cannot 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.
31. Which of the following methods can be used to obtain a permit from a Semaphore s?
a. get()
b. ask()
c. acquire()
d. delete()
32. An instance of _ _ _ _ _ _ _ _ _ describes the errors caused by your program and
external circumstances. These errors can be caught and handled by your program.
a. Runtime Exception
b. Exception
c. Error
d. Throwable
33. The following code causes Java to throw _ _ _ _ _ _ _ _ _ .
Th e l i d i ma g e c a n n o t be
nk e
d i sp l a . Th e f ma y h av e b e e n
mo v e y ,erd e n a me d ,i o r d e l e t e d . V e r i
d
le fy
t h a t t h el i po i n t o t co r r ect
f i l an d l o n ck a t i ts he
e on .
a. Runtime Exception
b. Exception
http://www.prsolutions08.blogspot.com
c. Error
d. No Exceptions
34. An instance of _ _ _ _ _ _ _ _ _ describes system errors. If this type of errors occurs,
there is little you can do beyond notifying the user and trying to terminate the
program gracefully.
a. Runtime Exception
b. Exception
c. Error
d. Throwable
35. Which of the following methods can be used to return a permit to a Semaphores?
a. return()
b. release()
c. send()
d. add()
36. A Java exception is an instance of _ _ _ _ _ _ _ _ _ _ .
a. Runtime Exception
b. Exception
c. Error
d. Throwable
37. An instance of _ _ _ _ _ _ _ _ _ describes programming errors, such as bad casting,
accessing an out-of-bounds array, and numeric errors.
a. Runtime Exception
b. Exception
c. Error
d. Throwable
38. An instance of _ _ _ _ _ _ _ _ _ are unchecked exceptions.
a. Runtime Exception
b. Exception
c. throwable
d. Error
39. What exception type does the following program throw?
public class Test {
public static void main(String[] args) {
System.out.println(1 / 0);
}
}
a. ArithmeticException
b. ArrayIndexOutOfBoundsException
c. StringIndexOutOfBoundsException
d. ClassCastException
40. What exception type does the following program throw?
public class Test {
public static void main(String[] args) {
Object o = new Object();
String d = (String)o;
}
}
a. Arithmetic Exception
b. ArrayIndex Out Of Bounds Exception
c. StringIndex Out Of Bounds Exception
d. Class Cast Exception
41. What exception type does the following program throw?
public class Test {
http://www.prsolutions08.blogspot.com
a. Arithmetic Exception
b. ArrayIndex Out Of BoundsException
c. StringIndex Out Of Bounds Exception
d. No exception
42. Analyze the following code:
class Test {
public static void main(String[] args) {
try {
String s = "5.6'';
Integer.parseInt(s); // Cause a NumberFormat Exception
int i = 0;
int y = 2 / i;
}
catch (Exception ex) {
System.out.println("Number Format Exception'');
}
catch (RuntimeException ex) {
System.out.println("Runtime Exception'');
}
}
}
a. Arithmetic Exception
b. ArrayIndex Out Of Bounds Exception
c. StringIndex Out Of Bounds Exception
d. Class Cast Exception
45. Which of the following statement is false?
a. You use the keyword throws to declare exceptions in the method heading.
b. A method may declare to throw multiple exceptions.
c. To throw an exception, use the key word throw.
d. If a checked exception occurs in a method, it need not to be either caught or
declared to be thrown from the method.
46. What exception type does the following program throw?
public class Test {
public static void main(String[] args) {
String s = "abc'';
System.out.println(s.charAt(3));
}
}
a. Arithmetic Exception
b. ArrayIndex Out Of Bounds Exception
c. StringIndex Out Of Bounds Exception
d. Class Cast Exception
47. What exception type does the following program throw?
public class Test {
public static void main(String[] args) {
Object o = null;
System.out.println(o.toString());
}
}
a. Arithmetic Exception
b. ArrayIndex Out Of Bounds Exception
c. StringIndex Out Of Bounds Exception
d. Class Cast Exception
48. A method must declare to throw _ _ _ _ _ _ _ _ .
a. unchecked exceptions
b. checked exceptions
c. Error
d. Runtime Exception
49. Analyze the following code:
class Test {
public static void main(String[] args)
throws MyException {
System.out.println("Welcome to Java");
}
}
class MyException extends Error {
}
http://www.prsolutions08.blogspot.com
a. You should not declare a class that extends Error, because Error raises a fatal error
that terminates the program.
b. You cannot declare an exception in the main method.
c. You declared an exception in the main method, but you did not throw it.
d. The program has a compilation error.
50. Analyze the following program.
class Test {
public static void main(String[] args) {
try {
String s = "5.6";
Integer.parseInt(s); // Cause a NumberFormat Exception
int i = 0;
int y = 2 / i;
System.out.println("Welcome to Java");
}
catch (Exception ex) {
System.out.println(ex);
}
}
}
a. The program displays Welcome to Java three times followed by End of the block.
b. The program displays Welcome to Java two times followed by End of the block.
c. The program displays Welcome to Java two times followed by End of the block two
times.
d. You cannot catch RuntimeException errors.
52. What is displayed on the console when running the following program?
class Test {
public static void main(String[] args) {
try {
System.out.println("Welcome to Java'');
int i = 0;
int y = 2/i;
System.out.println("Welcome to Java'');
}
finally {
System.out.println("End of the block'');
}
System.out.println("End of the block'');
}
}
a. The program displays Welcome to Java three times followed by End of the block.
b. The program displays Welcome to Java two times followed by End of the block.
c. The program displays Welcome to Java two times followed by End of the block two times.
d. The program displays Welcome to Java and End of the block, and then terminates
because of an unhandled exception.
53. Which of the following is not an advantage of Java exception handling?
a. The program displays Welcome to Java three times followed by End of the block.
b. The program displays Welcome to Java two times followed by End of the block.
c. The program displays Welcome to Java three times.
d. The program displays Welcome to Java two times.
55. What is wrong in the following program?
class Test {
public static void main (String[] args) {
try {
System.out.println("Welcome to Java'');
}
}
}
a. Welcome to Java
b. Welcome to Java followed by The finally clause is executed in the next line
c. The finally clause is executed
d. Runtime Error
57. What is displayed on the console when running the following program?
class Test {
public static void main(String[] args) {
try {
System.out.println("Welcome to Java'');
int i = 0;
int y = 2/i;
System.out.println("Welcome to HTML'');
}
finally {
System.out.println("The finally clause is executed'');
}
}
}
a. Welcome to Java.
b. Welcome to Java followed by The finally clause is executed in the next line.
c. The program displays three lines: Welcome to Java, Welcome to HTML, The finally clause is
executed.
d. Runtime Error
58. What is displayed on the console when running the following program?
class Test {
public static void main(String[] args) {
try {
System.out.println("Java'');
int i = 0;
double y = 2.0 / i;
System.out.println("Welcome'');
}
finally {
System.out.println("The finally clause is executed'');
}
}
}
a. Welcome to Java.
b. Welcome to Java followed by The finally clause is executed in the next line.
c. The program displays three lines: Welcome to Java, Welcome to HTML, The finally
clause is executed.
d. Runtime Error
59. The component that processes the listener is called _ _ _ _ _ _ _ _ _ _ _
a. addActionListener(p);
b. jbt.addActionListener(p);
c. jbt.addActionEventListener(p);
d. jbt.addEventListener(p);
http://www.prsolutions08.blogspot.com
a. ItemEvent
b. WindowEvent
c. MouseMotionEvent
d. ComponentEvent
63. Analyze the following code:
class Test {
public static void main(String[] args) {
try {
int zero = 0;
int y = 2/zero;
try {
String s = "5.6'';
Integer.parseInt(s); // Cause a NumberFormatException
}
catch(Exception e) {
}
}
catch(RuntimeException e) {
System.out.println(e);
}
}
}
a. Exception handling deals with unusual circumstances during program execution. Assertions
are intended to ensure the correctness of the program.
b. Exception handling addresses robustness whereas assertion addresses correctness.
c. use assertions for argument checking in public methods.
d. Use assertions to reaffirm assumptions.
66. Pressing a button generates a(n) _ _ _ _ _ _ _ _ _ _ event.
a. ItemEvent
b. MouseEvent
c. MouseMotionEvent
d. ActionEvent
67. Which of the following statement is false?
http://www.prsolutions08.blogspot.com
a. MouseListener
b. ActionListener
c. FocusListener
d. WindowListener
70. Analyze the following code.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JFrame implements ActionListener {
public Test() {
JButton jbtOK = new JButton("OK'');
getContentPane().add(jbtOK);
}
public void actionPerformed(ActionEvent e) {
System.out.println("The OK button is clicked'');
}
public static void main(String[] args) {
JFrame frame = new Test();
frame.setSize(300, 300);
Th e l i d i ma g e c a nn o t be
nke
d i sp l a . T he f e y h av e b e e n
mo v e yd ,e d r me d , i l omar d e l e d . V e r i
th a t h e el n a p o i n t s o t h ee t c o r e c t f y
t i t
f i l a nd l on kca t i
e o n.
frame.setDefaultCloseOperation(JFrame. );
frame.setVisible(true);
}
}
a. The program has a syntax error because no listeners are registered with jbtOK.
b. The program has a runtime error because no listeners are registered with jbtOK.
c. The message ``The OK button is clicked'' is displayed when you click the OK button.
d. The actionPerformed method is not executed when you click the OK button,
because no instance of Test is registered with jbtOK.
71. To be a listener for ActionEvent, an object must be an instance of _ _ _ _ _ _ _ _ _ _ _
_.
a. ActionEvent
b. ActionListener
c. EventObject
d. WindowListener
72. Every event object has the _ _ _ _ _ _ _ _ method.
a. getSource()
b. getActionCommand()
c. getTimeStamp()
d. getWhen()
73. To get the x coordinate of the mouse pointer for the MouseEvent evt, you use _ _ _ _ _
_____.
a. evt.getX()
b. Event.getPoint().x
c. evt.getXY( )
d. Event.getPoint(x,y)
74. To detect whether the right button of the mouse is pressed, you use the method _ _ _
_ _ _ _ _ _ _ in the MouseEvent object evt.
a. evt.isAltDown()
b. evt.isControlDown()
c. evt.isMetaDown()
d. evt.isShiftDown()
75. The method in the ActionEvent _ _ _ _ _ _ _ _ _ _ returns the action command of the
button.
a. getActionCommand()
b. getModifiers()
c. paramString()
d. getID()
76. The handler (e.g., actionPerformed) is a method in _ _ _ _ _ _ _ .
a. a source object
b. a listener object
c. both source and listener object
d. the Object class
77. Analyze the following code.
1. import java.awt.*;
2. import java.awt.event.*;
3. import javax.swing.*;
4.
5. public class Test extends JFrame {
6. public Test() {
7. JButton jbtOK = new JButton("OK'');
8. JButton jbtCancel = new JButton("Cancel'');
9. getContentPane().add(jbtOK);
10. getContentPane().add(jbtCancel);
11. jbtOK.addActionListener(this);
12. jbtCancel.addActionListener(this);
13. }
14.
15. public void actionperformed(ActionEvent e) {
16. System.out.println("A button is clicked'');
17. }
18.
19. public static void main(String[] args) {
20. JFrame frame = new Test();
21. frame.setSize(300, 300);
T l d i ma g e c a nn o t b e
dh e p l ai y e d . T h e f e ma y h a v e b e e n
is nk e il
mo v ed , r me d , or de l e t V er i f y
t t t le n a p o i n t s t th e ce od r. e c t
fh a a n hd e l oi c a t i o n . o
i nk
l
e
22. frame.setDefaultCloseOperation(JFrame. );
23. frame.setVisible(true);
24. }
25. }
a. The program has syntax errors on Lines 11 and 12 because Test does not
implement ActionListener.
b. The program has syntax errors on Line 15 because the signature of actionperformed is
wrong.
http://www.prsolutions08.blogspot.com
c. The program has syntax errors on Line 20 because new Test() is assigned to frame (a
variable of JFrame).
d. The program has runtime errors on Lines 9 and 10 because jbtOK and jbtCancel are added to
the same location in the container.
78. To listen to mouse movement events, the listener must implement the _ _ _ _ _ _ _ _ _
_ interface.
a. MouseListener()
b. MouseMotionListener()
c. WindowListener()
d. ComponentListener()
79. Which of the following statement is false?
a. You need not always specify a listener when creating a Timer object.
b. You can add multiple listeners for a Timer object.
c. To stop a timer, invoke timer.stop().
d. To start a timer, invoke timer.start().
80. Which of the following properties are in JApplet?
a. contentPane
b. iconImage
c. resizable
d. title
81. To check whether a DELETE key is pressed or released, which handler should be used?
a. keyActive(KeyEvent e)
b. keyReleased(KeyEvent e)
c. keyTyped(KeyEvent e)
d. keyInactive(KeyEvent e)
82. To be a listener for ActionEvent, an object must be an instance of _ _ _ _ _ _ _ _ _ _ _
_.
a. ActionEvent
b. ActionListener
c. EventObject
d. WindowListener
83. The listener's method _ _ _ _ _ _ _ _ _ _ is invoked when a mouse button is released.
a. MouseListener
b. KeyListener
c. WindowListener
d. ComponentListener
85. Which of the following statement is false?
a. a character
b. the ASCII code of the character
c. the Unicode code of the character
d. the EBSDIC code of the character
http://www.prsolutions08.blogspot.com
87. What is the value of evt.getKeyCode() or evt.getChar() for the keyTyped() events?
a. A character
b. The ASCII code of the character
c. The Unicode code of the character
Th e l d i ma g e c a nn o t b e
d i sp l i
a T he f e y h av e b e e n
n ke de .
y i l ma
mo v e d , r me d , or d e l e d . V er i
th a t t le n a p o i n t s o t h e t c o r e c t fy
f i l a n dh el oi c a t i t
e n k on .
d.
88. Which of the following statement is false?
a. JOptinPane
b. JApplet
c. JPanel
d. JDialog
90. Which of the following properties in java.awt.Component may effect layout?
a. preferredSize
b. foreground
c. background
d. font
91. Which of the following properties are in FlowLayout?
a. hgap
b. layout
c. visible
d. height
92. Which of the following properties are in GridLayout?
a. hgap
b. alignment
c. layout
d. visible
93. Which of the following properties are in CardLayout?
a. vgap
b. alignment
c. layout
d. visible
94. To use no layout manager in a container c, use _ _ _ _ _ _ _ _ _ .
a. c.setLayout()
b. c.setLayout(new NullLayout())
c. c.setLayout(null)
d. c.setLayout(NullLayout)
95. The preferredSize property is ignored in _ _ _ _ _ _ _ _ _ _ _ _ _ _ .
a. FlowLayout
b. GridLayout
c. BorderLayout
d. For any layout
96. Which of the following properties are in BorderLayout?
a. vgap
b. alignment
http://www.prsolutions08.blogspot.com
c. layout
d. visible
97. Suppose that a container c uses a CardLayout manager p. Which of the following
method is not valid?
a. c.p.first()
b. p.last(c)
c. p.next(c)
d. p.previous(c)
98. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ cannot be shared by a GUI component?
a. A GUI component
b. A Color object
c. A Font object
d. A layout object
99. _ _ _ _ _ _ _ _ _ put a flexible spring around a component.
a. BorderLayout
b. GridLayout
c. BoxLayout
d. SpringLayout
100. Which of the following are the invalid methods in JTabbedPane?
a. getTabbedCount( )
b. getTabPlacement( )
c. getTitleAt(index)
d. getToolTipTextAt(index)
101. You can construct a JSplitPane using _ _ _ _ _ _ _ _ _ _ _ _ .
a. new JSplitPane()
b. new JSplitPane(Component)
c. new JSplitPane(Component [ ])
d. new JSplitPane(Component, Component)
102. A border object is an instance of _ _ _ _ _ _ _ _ _ .
a. Border
b. BevelBorder
c. TitledBorder
d. LineBorder
103. The Box class uses _ _ _ _ _ _ _ _ _ _ _ _ _ .
a. FlowLayout
b. BorderLayout
c. GridLayout
d. BoxLayout
104. _ _ _ _ _ _ _ _ _ _ _ is a Swing layout manager that arranges components on top
of each other.
a. OverlayLayout
b. BorderLayout
c. GridLayout
d. BoxLayout
105. Every layout manager is an instance of _ _ _ _ _ _ _ _ _ _ .
a. FlowLayout
b. BorderLayout
c. GridLayout
d. BoxLayout
107. You can construct a JScrollPane using _ _ _ _ _ _ _ _ _ _ _ _ .
a. new JScrollPane(JFrame)
b. new JScrollPane(Component)
c. new JScrollPane(Component [ ])
d. new JScrollPane(Component, Component)
108. You can construct a JTabbedPane using _ _ _ _ _ _ _ _ _ _ _ _ .
a. New JTabbedPane( )
b. New JTabbedPane(Component)
c. New JTabbedPane(Component [ ])
d. New JTabbedPane(Component, Component)
109. Which of the following method will not create an EtchedBorder?
a. new EtchedBoarder()
b. new EtchedBorder(Color.YELLOW, Color.RED)
c. BorderFactory.createEtchedBorder()
d. BorderFactory.createEtchedBorder(Color.YELLOW, Color.RED)
110. Which of the following method will not create a BevelBorder?
a. new BevelBorder(BevelBorder.LOWERED)
b. BorderFactory.createBevelBorder(BevelBorder.LOWERED)
c. BorderFactory.createBevelBorder(BevelBorder.RAISED)
d. new BevelBorder()
111. Which of the following method will not create a TitledBorder?
a. new TitledBoarder()
b. new TitledBorder(new BevelBorder(BevelBorder.LOWERED))
c. BorderFactory.createTitledBorder("A title")
d. BorderFactory.createTitledBorder(new BevelBorder(BevelBorder.LOWERED), "A title")
112. A JMenuItem is a subclass of _ _ _ _ _ _ _ _ .
a. JButton
b. AbstractButton
c. JContainer
d. JMenu
113. Which of the following method will not create a LineBorder?
a. new LineBorder()
b. new LineBorder(Color.YELLOW, 3)
c. new LineBorder(Color.YELLOW, 3, true)
d. BorderFactory.createLineBorder(Color.YELLOW)
114. The method _ _ _ _ _ _ _ _ _ _ places a menu bar mb into the frame f.
a. f.setJMenu(mb)
b. f.add(mb)
c. f.setJMenuBar(mb)
d. f.addBar(mb)
115. The method _ _ _ _ _ _ _ _ _ _ places a menu mu into a menu bar mb.
a. mb.add(mu)
b. mb.addMenuItem(mu)
c. mb.addItem(mu)
d. mu.mb.addItem()
116. The method _ _ _ _ _ _ _ _ _ _ places a menu item mi into a menu mu.
a. mu.add(mi)
http://www.prsolutions08.blogspot.com
b. mu.addMenuItem(mi)
c. mu.addItem(mi)
d. mu.mb.addItem()
117. A MenuItem object can generate _ _ _ _ _ _ _ _ _ _ events.
a. ActionEvent
b. ItemEvent
c. ComponentEvent
d. ContainerEvent
118. The method _ _ _ _ _ _ _ _ _ _ separates menu items in a menu mu.
a. mu.add("-")
b. mu.addSeparator()
c. mu.Separator()
d. mu.Separator('-')
119. You cannot set a mnemonic property on _ _ _ _ _ _ _ _ _ _ _ .
a. a JmenuBar
b. a JMenuItem
c. a JCheckBoxMenuItem
d. a JRadioButtonMenuItem
120. _ _ _ _ _ _ _ _ _ _ _ _ _ is the action that causes a popup menu to be displayed.
a. Popup trigger
b. Popup action
c. Popup event
d. Popup reaction
121. A JCheckBoxMenuItem is not a subclass of _ _ _ _ _ _ _ _ .
a. JMenuItem
b. AbstractButton
c. JComponent
d. JMenu
122. A JRadioButtonMenuItem is a subclass of _ _ _ _ _ _ _ _ .
a. JMenuItem
b. AbstractButton
c. JComponent
d. JMenu
123. A JPopupMenu is a subclass of _ _ _ _ _ _ _ _ .
a. JMenuItem
b. AbstractButton
c. JComponent
d. JMenu
124. A JMenu is a not subclass of _ _ _ _ _ _ _ _ .
a. JMenuItem
b. AbstractButton
c. JComponent
d. JButton
125. You cannot set an imageIcon property on _ _ _ _ _ _ _ _ _ _ _ .
a. a JmenuBar
b. a JMenuItem
c. a JCheckBoxMenuItem
d. a JRadioButtonMenuItem
126. Which of the following statement is false?
a. A message dialog
b. A confirmation dialog
c. An input dialog
d. An option dialog
130. _ _ _ _ _ _ _ _ _ _ is used to receive input from the user.
a. A message dialog
b. A confirmation dialog
c. An input dialog
d. An option dialog
131. _ _ _ _ _ _ _ _ _ _ _ allows you to create custom buttons.
a. A message dialog
b. A confirmation dialog
c. An input dialog
d. An option dialog
132. Which of the following statements are true?
a. FlowLayout
b. SpringLayout
c. BoxLayout
d. GridLayout
134. Which of the following statement is incorrect?
a. JToolBar has an add method that enables you to add an instance of ActionListener to the
menu.
b. JToolBar has an add method that enables you to add an instance of Action to the
menu.
c. JButton has an add method that enables you to add an instance of ActionListener to the
menu.
d. JButton has an add method that enables you to add an instance of Action to the menu.
http://www.prsolutions08.blogspot.com
136. Waits for the user to click the OK button to close the dialog.
a. A message dialog
b. A confirmation dialog
c. An input dialog
d. An option dialog
137. 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
138. _ _ _ _ _ _ _ _ _ _ are referred to as heavyweight components.
a. AWT components
b. Swing components
c. GUI components
d. Non-GUI components
139. Which of the following are subclasses of java.awt.Component?
a. Association
b. Aggregation
c. Composition
d. Inheritance
141. Which of the following classes is a heavy weight component?
a. JButton
b. JTextField
c. JPanel
d. JFrame
142. What is best to describe the relationship between a container and a layout
manager?
a. Association
b. Aggregation
c. Composition
d. Inheritance
143. Which of the following statement is false?
a. To distinguish new Swing component classes from their AWT counterparts, Swing GUI
component classes are named with a prefix J.
b. All Swing GUI components are lightweight.
c. A user interface object such as (button, list) can appear in one container.
d. A container such as JFrame is also a component.
144. Which component cannot be added to a container? .
a. JPanel
b. JButton
c. JFrame
d. JComponenet
145. What is best to describe the relationship between a container and a SWing GUI
object in the container?
a. Association
b. Aggregation
http://www.prsolutions08.blogspot.com
c. Composition
d. Inheritance
146. What is best to describe the relationship between Component and Color?
a. Association
b. Aggregation
c. Composition
d. Inheritance
147. Which of the following classes are not in the java.awt package?
a. Color
b. Font
c. Component
d. JFrame
148. 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.getContentPane().add(new JButton("OK''));
frame.getContentPane().add(new JButton("Cancel''));
Th e l i d i ma g e c a n n o t b e
nke
d i sp l a . T he f e y h av e b e e n
mo v e dy ,e d r me d , i l omar d e l e d . V e r i
en a et fy
th a t h e l poi nt s o t h e c o r e ct
f i l at n d l io ca t i t
e nk o n.
frame.setDefaultCloseOperation(JFrame. );
frame.setSize(200, 200);
frame.setVisible(true);
}
}
a. 1.
b. 2.
c. 3.
d. 0.
150. 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);
http://www.prsolutions08.blogspot.com
Th e l i d i ma g e c a n n o t b e
d i sp l an k e . T h e f e y h av e b e e n
y ed i l ma
mo v e d , r me d , o r d e l ed . V er i
th a t h e le n a p o i n t s o t h e t c o r e ct f y
t i t
f i l a nd l on kca t i
e o n.
frame.setDefaultCloseOperation(JFrame. );
frame.setVisible(true);
}
}
a. frame.setDefaultCloseOperation(JFrame. )
b. frame.setDefaultCloseOperation(null)
The l k ed i ma g e c a n o t b e
in
di s a y e d . Th e f i l ma y h a v e b e n
mo pv l e d , r e n a me d , oe r d e l e d . V e ri f
te y
t th e l i n o i n ts to t h ec o r ec t
fh a at n d l k tpi o n .
i o ca
le
c. frame.setDefaultCloseOperation(JFrame. )
The l k ed i ma g e c a n ot be
in
di s a y e d . Th e f i l ma y h a v e b e n
mo pv l e d , r e n a me d , oe r d e l e d . V e ri f
t th e l i n o i n t s t o t h e ct e o r e c t y
ha t k p
f a nd l t i on .
i o ca
le
d. frame.setDefaultCloseOperation(JFrame. )
152. Which of the following statement 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)
153. The default layout out of a contentPane in a JFrame is _ _ _ _ _ _ _ _ _ _ .
a. FlowLayout
b. GridLayout
c. BorderLayout
d. GridBagLayout
154. _ _ _ _ _ _ _ _ _ _ _ _ cannot create a color object.
a. new Color(0, 0, 0)
b. new Color(0, 266, 0)
c. new Color(255, 255, 255)
d. new Color(1, 2, 3)
155. 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.
156. 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?
http://www.prsolutions08.blogspot.com
a. a FlowLayout
b. a GridLayout
c. the center area of a BorderLayout
d. the East or West area of a BorderLayout
157. To set a FlowLayout in panel jp, you can use the method _ _ _ _ _ _ _ _ _ _ .
a. jp.setLayout(new FlowLayout());
b. jp.setLayout(new FlowLayout(FlowLayout));
c. jp.setLayout(new FlowLayout(FlowLayout.center));
d. jp.setLayout(FlowLayout());
158. The method _ _ _ _ _ _ _ _ _ _ sets the font (Helvetica, 20-point bold) in
component C.
a. c.getDimension()
b. c.getWidth()
c. c.getHeight()
d. c.getSize()
160. You should override the _ _ _ _ _ _ _ _ _ _ method to draw things on a Swing
component.
a. repaint()
b. update()
c. paintComponent()
d. init()
161. To add a component c to a JPanel p, use _ _ _ _ _ _ _ _ _ .
a. p.add(c)
b. p.getContentPane(c)
c. p.insert(c)
d. p.append(c)
162. The method _ _ _ _ _ _ _ _ _ _ sets the background color to yellow in JFrame f.
a. setBackground(Color.yellow)
b. f.setBackground(Color.YELLOW)
c. setBackground(Color.YELLOW)
d. f.setBackGround(Color.yellow)
163. The method _ _ _ _ _ _ _ _ _ _ sets the foreground color to yellow in JFrame f.
a. setForeground(Color.yellow)
b. setForeground(Color.YELLOW)
c. f.setForeground(Color.yellow)
d. f.setForeGround(Color.yellow)
164. To specify a font to be bold and italic, use the font style value _ _ _ _ _ _ _ _ _
a. Font.PLAIN
b. Font.BOLD
c. Font.ITALIC
d. Font.BOLD + Font.ITALIC
165. The default layout out of a JPanel is _ _ _ _ _ _ _ _ _ _ .
a. FlowLayout
b. GridLayout
c. BorderLayout
d. default Layout
166. To create a JPanel of the BorderLayout, use _ _ _ _ _ _ _ _ _ _ _ _ _ _ .
a. JPanel p = new JPanel()
b. JPanel p = new JPanel(BorderLayout());
c. JPanel p = new JPanel(new BorderLayout());
d. JPanel p = new JPanel().setLayout(new BorderLayout());
167. 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.getContentPane().add(new MyDrawing("Welcome to Java!''));
frame.setSize(300, 300);
Th e l i d i ma g e c a n n o t b e
d i sp l na k e . T h e f e y h av e b e e n
y ed i l ma
mo v e d , r me d , o r d e l ed . V er i
th a t h e el n a p o i n t s o t h e t c o r e ct f y
t i t
f i l a nd l on kca t i
e o n.
frame.setDefaultCloseOperation(JFrame. );
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. (0, 0)
b. (25, 25)
c. (100, 100)
d. (10, 10)
169. Given a Graphics object g, to draw a filled arc with radius 20 centered at (50,
50) and start angle 0 and spanning angle 90, you use _ _ _ _ _ _ _ _ _ _
frame.setDefaultCloseOperation(JFrame. );
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 syntax 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.
172. Analyze the following code.
import java.awt.*;
import javax.swing.*;
public class Test extends JFrame {
public Test() {
getContentPane().add(new MyDrawing("Welcome to Java!''));
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(300, 300);
Th e l i d i ma g e c a n n o t b e
d i sp l an k e . T h e f e y h av e b e e n
y ed i l ma
mo v e d, r me d , o r d e l ed . V er i
th a t h e el n a p o i n t s o t h e t c o r e c t f y
t i t
f i l a n d l on kca t i
e o n.
frame.setDefaultCloseOperation(JFrame. );
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. Size
b. nextVal
c. previousValue
d. prevVal
181. If you create a JSpinner object without specifying a model, the spinner displays
_______.
a. a sequence of integers
http://www.prsolutions08.blogspot.com
a. java.awt.ActionEvent
b. java.awt.event.ItemEvent
c. javax.swing.event.ChangeEvent
d. javax.swing.event.AdjustmentEvent
183. The data in DefaultListModel are stored in _ _ _ _ _ _ _ _ _ _ _ .
a. an array.
b. an ArrayList
c. a LinkedList
d. a Vector
184. The data in DefaultListModel are stored in _ _ _ _ _ _ _ _ _ _ _ .
a. an array.
b. an ArrayList
c. a LinkedList
d. a Vector
185. The component for storing and handling data, known as _ _ _ _ _ _ _ _ _ ,
contains the actual contents of the component.
a. a model
b. a view
c. a controller
d. a Container
186. _ _ _ _ _ _ _ _ _ _ uses a java.util.List to store a sequence of custom defined
data in the model.
a. SpinnerListModel
b. SpinnerNumberModel
c. SpinnerDateModel
d. SpinnerModel
187. JList fires _ _ _ _ _ _ _ _ _ when a new item is selected.
a. java.awt.ActionEvent
b. java.awt.event.ItemEvent
c. javax.swing.event.ChangeEvent
d. javax.swing.event.AdjustmentEvent
188. A listener of a JList must implement _ _ _ _ _ _ _ _ _ .
a. only a string
b. only an icon
c. both string and icon
d. a string or an icon
190. _ _ _ _ _ _ _ _ _ are not the property of JList.
a. visibleRowCount
b. maximumRowCount
c. editable
d. itemCount
191. JComboBox fires _ _ _ _ _ _ _ _ when a new item is selected.
a. java.awt.ActionEvent
b. java.awt.ItemEvent
c. javax.swing.event.ChangeEvent
d. javax.swing.event.AdjustmentEvent
192. You can obtain the server's hostname by invoking _ _ _ _ _ _ _ _ _ on an applet.
a. getCodeBase().host()
b. getCodeBase().getHost()
c. getCodeBase().hostName()
d. getCodeBase().getHostName()
193. To obtain an ObjectInputStream from a socket, use _ _ _ _ _ _ _ _ .
a. socket.getInputStream()
b. socket.getObjectStream()
c. socket.getObjectInputStream()
d. socket.objectInputStream()
194. 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.
195. To create an InputStream on a socket s, you use _ _ _ _ _ _ _ _ _ _ .
a. socket.InetAddress();
b. socket.getInetAddress();
c. socket.obtainInetAddress();
d. socket.retrieveInetAddress();
197. The _ _ _ _ _ _ _ _ _ _ _ _ method in the InetAddress class returns the IP
address.
a. getIP()
b. getIPAddress()
c. getHostAddress()
d. getAddress()
198. To obtain an ObjectOutputStream from a socket, use _ _ _ _ _ _ _ _ .
a. socket.getOutputStream()
b. socket.getObjectStream()
c. socket.getObjectOutputStream()
d. socket.objectOutputStream()
199. When creating a server on a port that is already in use, _ _ _ _ _ _ _ _ _ _ .
a. java.net.BindException occurs.
b. the server is created with no problems.
c. the server is blocked until the port is available.
d. the server encounters a fatal error and must be terminated.
200. 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.
http://www.prsolutions08.blogspot.com
a. one
b. two
c. ten
d. unlimited number of
204. To create an InputStream to read from a file on a Web server, you use the class
_ _ _ _ _ _ _ _ _ .URL;
a. URL;
b. Server;
c. ServerSocket;
d. ServerStream;
205. To create an InputStream to read from a file on a Web server, you use the
method _ _ _ _ _ _ _ _ _ _ in the URL class.
a. getInputStream();
b. obtainInputStream();
c. openStream();
d. connectStream();