You are on page 1of 114

e No.

x MCQ
Book

a Advance
Java

m
2.0
SUTRA
UR ENGINEERING FRIEND
A dvance Java
programming

Computer engineering / IT Branch

first edition : 2019


second edition : 2022

Copyright with Authors :

All publishing rights ( printed & ebook version ) reserved with Ur


Engineering Friend ( a unit of UEF EdTech Pvt. Ltd.). No part of this book
should be reproduced in any form, electrical, mechanical, photocopy or
any other information storage and retrieval system without prior
permission in writing from UEF EdTech Pvt. Ltd.

Published by : UEF EdTech Pvt. Ltd.


business@urengineeringfriend.in
www.urengineeringfriend.in
+91 9142768230

Price : ₹ 500-/

scan to buy

Find us on :

/ Ur Engineering Friend
Preface
We are extremely happy to come out with this book on "Advance Java" for
the students. The importance of Advance Java is well known in various
engineering fields. Overwhelming response to our books on various
subjects inspired us to write this book. This book has been strictly written
as per the syllabus.

This book uses plain lucid language to explain fundamentals of this


subjects. The book provides logical method of explaining various
complicated concepts and stepwise methods to explain the important
topics. Each chapter is well supported with all the necessary illustrations
practical examples and solved questions. All the chapters in the book are
arranged in a proper sequence that permits each topic to build upon
earlier studies. All care has been taken to make students comfortable in
understanding the basic concepts of the subject.

Potential questions have been added at the end of each section to help
the students in picking important questions from every section.

The book not only covers the entire scope of the subject but explains the
philosophy of the subject. This makes the understanding of this subject
more clear and makes it more interesting. This book will be very useful
not only to the students but also to the subject teachers. The students
have to omit nothing and possibly have to cover nothing more.

We wish to express our profound thanks to all those who helped in


making this book a reality. We are also thankful to the staff members of
"Ur Engineering Friend" and others for their efforts to make this book as
good it is. We wish to thank the publisher and the entire team of Ur
Engineering Friend who have taken pain to get this book in time with
quality printing.

Any suggestion for the improvement of this book will be acknowledged


and well appreciated.

Prince Raj Verma


Unit 1 : Abstract Windowing Toolkit

Total no. of Questions - 120

1. Give the Abbreviation of AWT:

a. Applet windowing Toolkit


b. Abstract windowing toolkit
c. Absolute windowing toolkit
d. None of these

2. Which is a component in AWT that can contain another components like


buttons, textfields, labels etc?

a. Window
b. Container
c. Panel
d. Frame

3. How many types of controls does AWT support?

a. 7
b. 6
c. 5
d. 8

4. Which class provides may methods for graphics programming?

a. Java.awt
b. Java.graphics
c. Java.awt.graphics
d. None of these

5. Which is the container that doesn’t contain title bar and menu bars. It can
have other components like button, text field etc?

a. Window
b. Frame
c. Panel
d. Container

6. Which object can be constructed to show any number of choices in the visible
window?

a. Choice
b. Menu
c. List
d. Checkbox

7. By which method we can set or change the text in a label in AWT?

a. setText()
b. getText()
c. addText()
d. all of these

8. on which side applet always executed?

a. Server side
b. Client side

9. Which method of the applet class displays the result of applet code on
screen?
a. Run() method
b. Paint() method
c. drawstring() method
d. main() method

10. Applet can be embedded in ______

a. HTML document
b. Word document
c. Gif file
d. Rtf file

11. Which of the following is true about applet?

a. Applets do not have a main() method.


b. Applets must run under applet viewer or web browser
c. The user I/O is not performed using java’s stream I/O class
d. All of these

12. Executable applet is ____________

a. .applet file
b. .java html
c. .java file
d. .class file

13. Which of the following is used to interpret and execute Java Applet Classes
Hosted by HTML?

a. Applet Viewer
b. Applet Screen
c. Applet watcher
d. Applet show
14. Java applet are used to create _______ applications

a. Graphical
b. User interactive
c. Both a & b
d. None of the above

15. Which of these functions is called to display the output of an applet?

a. Display()
b. Paint()
c. displayApplet()
d. show()

16. Which of these methods is a part of Abstract Window Toolkit ( AWT )?

a. Display()
b. Paint()
c. Show()
d. All of these

17. Which object can be constructed to show any number of choices in the
visible window?

a. Labels
b. Choice
c. List
d. Checkbox

18. Which of the following class is derived from the container class?

a. Component
b. Panel
c. Menu component
d. List

19. When we invoke repaint() for a java.awt.component object, the AWT


invokes the method:

a. Draw()
b. Update()
c. Show()
d. Paint()

20. Which method executes only once ?

a. Start()
b. Stop()
c. Init()
d. Destroy()

21. What does the following line of code do?

TextField text = new TextField(20);


a. Creates text object that can hold 20 rows of text
b. Creates text object that can hold 20 columns of text
c. Creates the object text and initializes it with the value 20
d. This is invalid code

22. Which of these classes can be added to any container class, using the add
method defined in the container class?

a. Button
b. checkboxMenuItem
c. menu
d. menubar
23. which of the following methods can be used to change the size of a
java.awt.component object?

a. Dimension()
b. Setsize()
c. Area()
d. Size()

24. Which of the following methods can be used to remove a


java.awt.component object from the display()?

a. Disappear()
b. Delete()
c. Remove()
d. Hide()

25. These two ways are used to create a Frame

1. By creating the object of Frame class ( association )


2. By extending frame class ( inheritance )

a. True
b. False

26. The title of the frame can be set in AWT using the method.

a. setHeading
b. setTitle
c. Create Title
d. setTitle

27. Which are passive controls that do not support any interaction with the user?

a. Choice
b. List
c. Labels
d. Checkbox

28. How many ways can we align the label in a container?

a. 1
b. 2
c. 3
d. 4

29. By which method we can set or change the text in an Label In AWT?

a. setText()
b. getText()
c. addText()
d. all of these

30. The various controls supported by AWT are:

a. Labels, push buttons


b. Checkbxes, choice lists
c. Scrollbars, test fields, text area
d. All of these

31. Which layout manager places components in one of the five regions : north,
south , east , west and center?

a. Absolute layout
b. Grid layout
c. Border layout
d. Flow layout

32. Arranges the components horizontally:


a. Border layout
b. Card layout
c. Grid layout
d. Flow layout

33. The most commonly used layout managers are ______.

a. Flow layout
b. Border layout
c. Grid layout
d. All of these

34. Default layout manager for subclasses of window is _____

a. Card layout
b. Gridbag layout
c. Frame
d. Border layout

35. Each menu is associated with a _______ list of menu items.

a. Checkbox
b. Drop-down
c. Choice
d. None of these

36. Which class can be used to represent a checkbox with a textual label that
can appear in a menu?

a. Menu bar
b. Menuitem
c. Checkboxmenuitem
d. Menu
37. Which abstract class is the super class of all menu related classes?

a. MenuComponent
b. MenuBar
c. MenuItem
d. CheckBoxMenuItem

38. Menu items are added to ______

a. Menus
b. Menubar
c. Frame
d. Both a & b

39. Dialog box does not have minimize and maximize button

a. True
b. False

40. A dialog box is referred to as modeless if the user does not have to close it
in order to continue using the application that owns the dialog box.

a. True
b. False

41. The ______ class displays a dialog window from which the user can select a
file.

a. Dialog
b. Filedialog
c. File
d. None of these

42. Find out the error in the given program and write down the correct answer.
import java.awt.*;
import java.awt.event.*;
class FrameJavaExample
{
public static void main (String args[])
{
Frame frame = new Frame("Frame Java Example");
//set the size of the frame
frame.setSize(300,250);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});

}
}

Ans : __________________________________________________________

43. Which one of the following is the correct syntax for defining a label in
AWT ?

a. Label (String s)
b. Label ( String s, int style )
c. Both a & b
d. None of these

44. Match the following tag names with the descriptions in the following lists:

1. EMBED tag
2. APPLET tag
3. OBJECT tag

a. Use to deploy applets to a multi-browser environment.


b. Use to deploy applets that are to be used only with the Mozilla family
of browsers
c. Use to deploy applets that are to be used only with Internet Explorer

Ans - _____________________________________________________

45. How will you initialize an applet ?

Ans - By including the initialization code in the init() method.

46. How do you set security in applets ?

Ans – by using SetSecurityManager() method.

47. When is update method called?

a. Whenever we minimize, maximize, restart the applet and explicitly


calling the repaint() method in the code
b. Repaint() method will implicitly call the update() method.
c. Both a & b
d. None of these

48. Which method is called by applet class to load an image?

Ans - getImage(URL object, filename) is used for this purpose.

49. How does applet recognize the height and width?

Ans - Using getParameters() method.

50. What is the relationship between clipping and repainting?

Ans - When a window is repainted by the AWT painting thread, it sets


the clipping regions to the area of the window that requires repainting.

51. Why does it take so much time to access an Applet having Swing
components the first time?
Ans - Because behind every swing component are many Java objects and
resources.

This takes time to create them in memory. JDK 1.3 from Sun has some
improvements which may lead to faster execution of Swing applications.

52. What is the order of method invocation in an Applet ?

a. Init() >> start() >> paint() >> destroy() >> stop()


b. Start() >> paint() >> init() >> stop() >> destroy()
c. Init() >> start() >> paint() >> stop() >> destroy()
d. All of these

53. The panel class is derived from the___class

Ans: Container class

54. Panel contains no border,nomenubar and no title bar

Ans: True

55. Which Event is Suported by Frame class

a)Window Open

b)Window Close

c)WindowActivated,Deactivated

d)All of these

56. Which type of datatype is passed to voidSetVisible Method

Ans:Boolean

57. Find out the error in following code and rewrite the corred code

importjava.awt.*;

public class frameDemo


{

public class void main(Sringargs[])

framedemofr=new frameDemo();

fr.setSize(400,500);

fr.setVisible(true);

fr.setLayout(new FlowLayout());

Ans:

Frame Demo class Should be inherited from the frame class.

importjava.awt.*;

public class frameDemo extends Frame

public class void main(Sringargs[])

framedemofr=new frameDemo();

fr.setSize(400,500);

fr.setVisible(true);

fr.setLayout(new FlowLayout());

}
}

58. Which one of the following is not a valid alignment for label component

a)LEFT.CENTER

b)LEFT.RIGHT

c)Left.MIDDLE

d)LABEL.LEFT

59. What is the Correct syantax to define a button in Awt.

a)Button(String s)

b)Button(String s,int alignment)

c)both a and b

d)none of these

60. In How Many Ways we can define a Button in Awt.

a)3

b)4

c)7

d)1

61. Find out the error in following program and rewrite the code

importjava.awt.*;

public class frDemo extends Frame

public class void main(Sringargs[])

{
frDemofr=new frDemo();

fr.setSize(400,500);

fr.setVisible(true);

fr.setLayout(new FlowLayout());

Button btn1=new Button("Button1");

add(btn1);

Ans:We have to use the frDemo object as fr.add(btn1);

62. Which component acts just like a radio button

Ans: CheckboxGroup

63. In How many ways we can use Scrollbar

Ans: 2(horizontal and vertical).

64. What is the correct syantax to define TextArea

Ans: TextArea(int n, int m).

65. The Graphics class is suported by the package___

Ans:java.awt

66. How can we use the drawString method in Awt Write down the correct
Syantax.

Ans: void drawstring (String s, int x, int y)

67. Write down the correct syantax to run applet program using applet veiwer.

Ans:javac FirstApplet.java
appletviewer FirstApplet.html

68. Which method allows us to live some space between underline window on
the applet and layout manager.

Ans: getInsets()

69. Which layout is used when we want to perform various set graphical control
at the same time

Ans: CardLayout.

70. The correct syntax to denote alignment is ___________

a) FlowLayout.Left

b) LEFT.FLOWLAYOUT

c) FlowLayout.LEFT

d) none of these

71. A ___________ dictates the style of arranging the components in a


container.

a) border layout
b) grid layout
c) panel
d) layout manager

72. Which method used to place some text in the text field?

a) getText(String str)
b) setText(String str)
c) putText(String str)
d) None of the above
73. Which method used to change the foreground (text) color of components
like text field?

a) setBackground(Color clr)
b) setForeground(Color clr)
c) setColor(Color clr)
d) setEditable(boolean state)

74. getLabel() method used to retrieve the label of a button.

a) Yes
b) No
c) Can be yes or no
d) Can not say

75. Which of the following option match for the given program?

import java.awt.*;
public class Layouts extends Frame {
Layouts() {
java.awt.Container container = new Container();
container.setLayout(new GridLayout(3, 2));
container.add(new java.awt.Button("A"));
container.add(new java.awt.Button("B"));
java.awt.Container container2 = new Container();
container2.setLayout(new GridLayout(1, 1));
container.add(container2);
container2.add(new java.awt.Button("C"));
container.add(new java.awt.Button("D"));
container2.add(new java.awt.Button("E"));
add(container);
pack();
}
public static void main(String[] args) {
new Layouts().show();
}
}
Ans – B

76. In which layout there are four components at the four sides and one
component occupying large area at the center ?

a) Border Layout
b) Flow Layout
c) Grid Layout
d) GridBag Layout

77. Which layout manager is the invalid one in AWT ?

a) Horizontal Layout
b) Flow Layout
c) Grid Layout
d) GridBag Layout

78. Which of the layout manager arranges component in a grid ?

a) Horizontal Layout
b) Grid Layout
c) Tabular Layout
d) GridBag Layout
79. No. of parameters is passed to GridLayout manager is ______

Ans – 2 ( one for row and one for column )

80. Which layout should be used to create this UI ?

a) Horizontal Layout
b) Grid Layout
c) Tabular Layout
d) GridBag Layout

81. ___________ layout manager allows us to have more than one layout.

a) Horizontal Layout
b) Card Layout
c) Grid Layout
d) GridBag Layout

82. Which layout is conceptually thought as a collection of cards lying on a


panel ?
a) Horizontal Layout
b) Card Layout
c) Grid Layout
d) GridBag Layout

83. In card layout which method is used to add the cards on the panel ?

Ans – add() method

84. Which of the following is the valid constructor to use card layout in your
program ?

a) CardLayout()
b) CardLayout( int hgap int vgap )
c) Both a & b
d) None of these

85. Which method is used to flip to the previous card of the given container ?

a) Public void first ( Container parent )


b) Public void last ( Container parent )
c) Public void previous ( Container parent )
d) All of these

86. In card layout which method is used to flip to the specified card with the
given name ?

Ans - public void show(Container parent, String name):

87. In card layout which method is used to remove the specified component
from the layout.
a) hideLayout ( Container parent )
b) removeLayout ( Container parent )
c) removeLayoutComponent(Component cm)
d) All of these

88. Which layout manager is considered as the most flexible and complex
layout manager ?

a) Card Layout
b) Border Layout
c) Flow Layout
d) GridBag Layout

89. Which one of the following denotes increase and decrease in horizontal or
vertical preferred size of the component ?

a) Weight x and weight y


b) Int x and int y
c) Gridx and gridy
d) Ipadx and ipady

90. ____________ denote the extra space occupied by the component


horizontally or vertically when the output window is resized.

a) Weight x and weight y


b) Int x and int y
c) Gridx and gridy
d) Ipadx and ipady

91. In gridbag layout ________ value denotes how the components should
expand within the display area.
a) fill
b) Int x and int y
c) Gridx and gridy
d) Ipadx and ipady

92. Which layout manager should be used to create this type of User Interface ?

a) Card Layout
b) Border Layout
c) Flow Layout
d) GridBag Layout

93. What is the correct constructor for gridbag layout ?

Ans - GridBagLayout()

94. Which class can be used to represent a checkbox with a textual label that
can appear in a menu. Select the one correct answer.

a) Select
b) Checkbox
c) List
d) CheckboxMenuItem

95. A label is a simple control which is used to display _________________on


the window

Ans – Text ( non-editable )

96. A superclass of Textfield and TextArea classes that is used to create single-
line , multiline textfields rexpectively is_____.

Ans – TextComponent
97. BorderLayout class has __________regions to add components to it

a) two
b) three
c) four
d) five

98. By default the Frame has a ________________________________

a) resizing corners
b) borders
c) Title bars
d) all of these

99. Canvas is a _____________

a) text field
b) a picture
c) window
d) panel

100. Choose the incorrect statement :

a) setLayout(new FlowLayout())
b) setLayout(new GridbagLayout())
c) setLayout(new BorderLayout(3,4))
d) none of these

101. Default layout manager for panel is ___________

a) Card Layout
b) Border Layout
c) Flow Layout
d) GridBag Layout

102. Default layout manager for frame is ___________

a) Card Layout
b) Border Layout
c) Flow Layout
d) GridBag Layout

103. For creating the complete menu bar the constructors we use ______

a) Public MenuBar()
b) Public Menu(String title )
c) Public MenuItem(String title )
d) All of these

104. Which one of the following is the correct syntax to add menu bar in any
frame ?

Frame fr = new Frame();

MenuBar mbar = new MenuBar();

a) fr.addMenu(menubar)
b) fr.setMenuBar(mbar);
c) both a & b
d) none of these

105. The dialog boxes contains minimize and maximize buttons.

a) False
b) True
106. In which type of dialog box user does not have to close it in order to
continue using the application ?

a) Modal dialog box


b) Modeless Dialog box
c) Both a & b
d) None of these

107. In which type of dialog box user have to close it first in order to continue
using the application ?

a) Modal dialog box


b) Modeless Dialog box
c) Both a & b
d) None of these

108. Which method is used to set the mode of the file dialog.

Ans –SetMode(int)

109. The ________ class displays a dialog window from which the user can
select a file.

Ans – File Dialog

110. Panel is for _______________ components.

Ans – grouping

111. In Graphics class Which method is used to set the graphics currentcolor to
the specified color?

Ans - public abstract void setColor(Color c)


112. Which constructor is used to create dialog box ?

a) Dialog ( Dialog owner )


b) Dialog ( Dialog owner , String title )
c) Dialog ( Dialog owner , String title , Boolean modal )
d) All of these

113. Signature for file dialog box is ______________-

Ans – public class FileDialog extends Dialog

114. In file dialog which method indicates whether file dialog box is for loading
from a file or saving to a file ?

a) getDirectory()
b) getFile()
c) getMode()
d) none of these

115. Which method sets the selected file for this file dialog window to be the
specified file.

a) getDirectory()
b) getFile()
c) setFile()
d) none of these

116. In file dialog which constant value indicates that the purpose of the file
dialog window is to locate a file to which to write.

a) SAVE
b) LOAD
c) Both a & b
d) none of these

117. In applet, which of the following tag is used for accepting user defined
parameter?

Ans – param

118. How do you change the current layout managers for a container?

a) Use setLayout() method


b) Use changeLayout() method
c) Use updateLayout() method
d) none of these

119. Frame is a standard window,which is ____________________of Window


class from AWT hierarchy.

a) Parent class
b) Sub class
c) Abstract class
d) Virtual class

120. Font class is available in ______________

Ans – java.awt package


Unit 2 : Swing

Total no. of Questions – 100

121. Pluggable look and feel and lightweight components are the features
supported by ________

a. Swing
b. AWT
c. Core java
d. None of these

122. Swing is based on _____ architecture

a. Client server
b. Model view controller
c. layered
d. None of these

123. Swing is not a part of JFC that is used to create GUI application.

a. True
b. False

124. The java foundation classes ( JFC ) is a set of GUI components which
simplify the development of desktop applications.

a. True
b. False
125. Following letter used a prefix to swing component.

a. A
b. S
c. G
d. J

126. _____ is one of the features of object oriented programming that allows the
creation of hierarchical classifications.

a. Polymorphism
b. Class
c. Inheritance
d. Object

127. In swing JButton class is derived from _________

a. AbstractButton
b. JToggleButton
c. JComponent
d. None of these

128. The JTextComponent derives two components JTextField and ______

a. JComboBox
b. JTextArea
c. JSlider
d. All of the above

129. In swing class hierarchy the class present at the root is ___

a. Component
b. Window
c. Container
d. Object

130. ________ pane can be used to add component to container.

a. Glsass
b. Content
c. Container
d. All of the above

131. To represent icon file in swing label, we use

a. Setimg
b. setIcon
c. serLabelIcon
d. none of this

132. which of the following component allows multiple selection?

a. JList
b. JComboBox
c. JLabel
d. All of the above

133. The subclass of JToggleButton is _____

a. JButton
b. JCheckBox
c. JRadioButton
d. Both b & c

134. The swing component classes that are used in encapusulates a mutually
exclusive set of buttons?

a. Abstractbutton
b. ButtonGroup
c. JButton
d. ImageIcon

135. Which method of the component class is used to set the position and size
of a component?

a. setPosition
b. setBounds
c. setSize
d. none of these

136. select the correct option

1. canvas is a component
2. scrollpane is a container

a. 1 is true and 2 is false


b. 1 is false and 2 is true
c. I & 2 both are false
d. 1 & 2 both are true

137. The difference between scrollbar and scrollpane is __________

a. Scrollbar is component and scrollpane is container


b. Scrollbar is container and scrollpane is component
c. Scrollbar and scrollpane both are components and not containers
d. Scrollbar and scrollpane both are containers and not components

138. Frame class extends window

a. True
b. False

139. Which is the container class?


a. Window
b. Frame
c. Dialog
d. All of the above

140. Following is uneditable control

a. Button
b. Textfield
c. Label
d. List

141. Jpanel and Applet use _____ as their default layout.

a. Flowlayout
b. Gridlayout
c. Border layout
d. Gridbag layout

142. MVC stands for ____

a. Model version control


b. Model view controller
c. Mini view controller
d. Major view controller

143. MVC architecture is used by swing ____

a. True
b. False

144. In swing _____ gives the visual representation of the component.

a. Model
b. View
c. Controller
d. None of these

145. In swing the event handling task is carried out by _______

a. Model
b. View
c. Controller
d. None of these

146. _____ represents enterprise data and the business rules that gives access to
enterprise data.

a. Model
b. View
c. Controller
d. None of these

147. Which of these functions is called to display the output of an applet?

a. Display()
b. Paint()
c. displayApplet()
d. PrintApplet()

148. Components are added to which pane of swing JApplet .

a. Content pane
b. Window
c. Container
d. None of these

149. Which of the following component is not supported by AWT but supported
in Swing ?
a. Table
b. Tabbed pane
c. Both a & b
d. None of these

150. Double-buffering built in, tool tips, dockable tool bars, keyboard
accelerators, custom cursors, etc. are new features of

Ans – Swing

151. for using Swing control one must import ___________ package.

Ans - import javax.swing.*

152. getContentPane() method of which class

Ans – Japplet

153. How To Apply Image To Button ?

a. ImageInsert Class
b. ImageIcon class
c. PutImage class
d. None of these

154. In FlowLayout manager the default space between each component is

Ans – 5 pixels

155. In Swing, tables are implemented by the ______________ class

a. Table
b. JTable
c. YTable
d. All of these

156. Items are added in JComboBox using method......


a. addItem()
b. getItem()
c. both a & b
d. none of these

157. JApplet class is Derived form

Ans – Applet

158. JRadioButton is a subclass of ________.

a. AbstractButton
b. RadioButton
c. CheckBoxItem
d. None of these

159. In which package JTabbedPane class is present ?

a. Java.awt
b. Java.swing
c. Javax.swing
d. None of these

160. In which package JTree class is present ?

a. Java.awt
b. Java.swing
c. Javax.swing
d. None of these

161. Which method is used for getting the language in internationalization?

a. getDisplayLanguage()

b. GetdisplayLanguage()
c. GetDisplayLanguage()
d. None
162. What are the types of Applets ?

a. Trusted
b. Untrusted
c. Both a & b
d. None of these

163. JFrame myFrame = new JFrame (); Any command (such as the one listed
above) which creates a new object of a specific class (in this case a new JFrame
object called myFrame) is generally called a ..

a. Constructor
b. Layout Manager
c. Parameter
d. GUI

164. All collection classes are available in __________-

a. Java.util package
b. Java.lang package
c. Java.io package
d. Java.awt package

165. Suppose you are developing a Java Swing application and want to toggle
between various views of the design area. Which of the views given below are
present for the users to toggle?

a. Requirements View
b. Design View
c. Source View
d. Management View

166. What is the name of the Swing class that is used for frames?
a. SwingFrame
b. Frame
c. Window
d. None of these

167. What is the name of the Swing class that is used for frames?

a. SwingFrame
b. Frame
c. Window
d. JFrame

168. Plugable Look & Feel is the feature of

Ans – Swing

169. setBorder() method is used to set a border for ________

Ans – Jcomponent

170. Swing components are ____

a. Light weight
b. Platform independent
c. Both a & b
d. None of these

171. In _________ each component renders itself using the drawing primitives
of the Graphics object.

a. AWT
b. Swing
c. Both a & b
d. None of these

172. There is a debugging support for rendering of created swing components.


a. True
b. False

173. Choose the correct statement.

a. AWT supports limited number of GUI components


b. The AWT component is converted by the native code of the operating
system.
c. Swings components can have tooltip placed over them.
d. All of these

174. The swing is a light weight component because _____________

Ans – it is the responsibility of JVM to invoke the native methods.

175. JRadioButton is a sub-class of ____________

a. JCheckBox
b. JToggleButton
c. Both a & b
d. None of these

176. In swing how many ways to define a frame .

a. 3
b. 1
c. 2
d. 4

177. The method ______________ sets the foreground color to yellow in


Jframe.

Ans - f.setForeground (Color.YELLOW)

178. The method _______________creates a IconImage for file c:\image\us.gif

Ans - new ImageIcon("c:\image\us.gif");


179. The Swing component classes that are used in encapsulate a mutually
exclusive set of buttons are?

a) ButtonGroup
b) ButtonSets
c) Both a & b
d) None of these

180. When layout manager is disabled , which method is used to determine the
shape and position of Component?

a) SetBounds
b) SetSize
c) SetCoordinates
d) None of these

181. which package we need to import while writng swing JRadioButton class

Ans - import javax.swing.*;

182. Which Among the below is not an AWT class

a) RadionButton
b) Checkbox
c) CheckboxGoup
d) All of these

183. Which swing component is not editable ?

a) JLabel
b) JButton
c) JCheckBox
d) All of these
184. Which component displays information in hierarchical manner with parent-
child relationship?

a) JFrame
b) JTree
c) JComboBox
d) JTable

185. Which component in swing represents data in rows and columns?

a) JFrame
b) JTree
c) JComboBox
d) JTable

186. Which components are needed to get following shown output

a) Label , TextField
b) Label , Checkbox
c) Both a & b
d) None of these

187. Which is Controll in swing a combination of a text field and a dropdown


list

Ans – JcomboBox
188. Which is default layout Manager for Japplet?

a) FlowLayout
b) BorderLayout
c) GridLayout
d) CardLayout

189. Which method is used to add tabs to a JTabbedPane?

a) addTab
b) insertTab
c) putTab
d) none of these

190. Which method is used to close a swing frame?

a) setDefaultCloseOperation()
b) setCloseOperation()
c) closeFrame()
d) none of these

191. Which of the following are not swing component ?

a) JTree
b) JComboBox
c) iframe
d) JTable

192. Which of the following is not a swing class ?

a) JMenuBar
b) Canvas
c) JCheckBox
d) JTree
193. Which of the following is not true about swing components ?

a) Provides more GUI components


b) Swing provides debugging support
c) Heavy weight component
d) Uses JVM to invoke the native methods

194. The immediate super class of JCheckbox is ______________

a) JToggleButton
b) JCheckBox
c) JAbstractButton
d) JRadioButton

195. _________________ is used to create a tree node with no root node.

a) DefaultMutableTreeNode
b) AddTreeNode
c) InsertTreeNode
d) All of these

196. In Table the ________ denotes the header of each column.

Ans – columnheader

197. Which one of the following is the correct constructor for progressbar ?

a) JProgressBar()
b) JProgressBar(int min , int max)
c) Both a & b
d) None of these

198. How to create a progress bar with minimum and maximum value ?

Ans – Progressbar(int min , int max)


199. In progress bar which method is used to determine whether the string
should be displayed ?

a) Void SetStringPainted(Boolean status)


b) Void setStringColored(Boolean status)
c) Void setValue(int)
d) Void setString(string s)

200. Which type of data is passed as a parameter to SetStringPainted() method ?

Ans – Boolean

201. Which method is used to set the value of the progress bar ?

a) Void SetStringPainted(Boolean status)


b) Void setStringColored(Boolean status)
c) Void setValue(int value)
d) Void setString(string s)

202. In progress bar which method is useful in displaying the data after periodic
interval ?

Ans – Thread.sleep(1000);

203. MVC stands for ________

a) Model view center


b) Medium view controller
c) Model View Controller
d) None of these

204. In MVC which component manages the state and conducts all
transformations on that state ?

a) Model
b) View
c) Controller
d) None of these

205. In MVC which component manages the visual display of the state
represented by the model ?

a) Model
b) View
c) Controller
d) None of these

206. In MVC which component managing the user interaction with the model ?

a) Model
b) View
c) Controller
d) None of these
Unit 3 : Event Handling

Total no. of Questions – 130

222. Which of these packages contains all the event handling interfaces?

a. Java.lang
b. Java.awt
c. Java.awt.event
d. Java.event

223. Where can the event handling code be written?

a. Same class
b. Other class
c. Anonymous class
d. All of these

224. Which of these class is super class of all the events?

a. EventObject
b. Eventclass
c. ActionEvent
d. ItemEvent

225. Which package provides many event classes and Listener interfaces for
event handling?

a. Java.awt
b. Java.awt.graphics
c. Java.awt.event
d. None of the above

226. Which of these interfaces handles the event when a component is added to
the container?

a. componentListener
b. ContainerListener
c. FocusListener
d. InputListener

227. Which of these interfaces define a method actionPerformed() ?

a. Componentlistener
b. Containerlistener
c. Actionlistener
d. Inputlistener

228. Which of these interfaces define four methods?

a) Componentlistener
b) Containerlistener
c) Actionlistener
d) Inputlistener

229. Which of these event will be generated if we close an applet’s widow?

a. Actionevent
b. Componentevent
c. adjustmentEvent
d. WindowEvent

230. Which of these event is generated when a button is pressed?


a. ActionEvent
b. KeyEvent
c. WindowEvent
d. AdjustmentEvent

231. Which of these methods can be used to obtain the command name for
invoking ActionEvent object ?

a. getCommand()
b. getActionCommand()
c. getActionEvent()
d. getActionEventCommand()

232. Which of these interfaces define a method itemStateChanged() ?

a. ComponentListener
b. ContainerListener
c. ActionListener
d. ItemListener

233. Which of these methods will be invoked if a character is entered?

a. keyPressed()
b. Keyreleased()
c. KeyTyped()
d. KeyEntererd()

234. Which of these constants defined in WindowEvent class?

a. WINDOW_ACTIVATED
b. WINDOW_CLOSED
c. WINDOW_DEICONIFIED
d. ALL OF THESE
235. Which of these events is generated by scroll bar?

a) ActionEvent
b) KeyEvent
c) WindowEvent
d) AdjustmentEvent

236. Which of these constant value will change when the button at the end of
scrollbar was clicked to increase its value?

a. BLOCK_DECREMENT
b. BLOCK_INCREMENT
c. UNIT_DECREMENT
d. UNIT_INCREMENT

237. Which of these methods is defined in MouseMotionAdapter class?

a. mouseDragged()
b. mousePressed()
c. mouseReleased()
d. mouseClicked()

238. which of these methods can be used to obtain the coordinates of a mouse?

a. getPoint()
b. getCoordinates()
c. getMouseXY()
d. getMouseCoordinates()

239. Which of these is super class of all Adapter classes ?

a. Applet
b. ComponentEvent
c. Event
d. InputEvent

240. Which of these methods can be used to obtain the coordinates of a mouse?

a. getPoint()
b. getCoordinates()
c. getMouseXY()
d. getMouseCoordinates()

241. MouseEvent is subclass of which of these classes?

a. ComponentEvent
b. ContainerEvent
c. ItemEvent
d. InputEvent

242. Which of these are integer constants of TextEvent class?

a. TEXT_CHANGED
b. TEXT_FORMAT_CHANGED
c. TEXT_VALUE_CHANGED
d. TEXT_SIZE_CHANGED

243. Which of these methods is used to obtain the object that generated a
windowEvent?

a. getMethod()
b. getWindow()
c. getWindowEvent()
d. getWindowObject()

244. Which of these methods is used to get x coordinate of the mouse?

a. getX()
b. getXCoordinate()
c. getCoordinateX()
d. getPointX()

245. Which of these is superclass of WindowEvent class?

a. WindowEvent
b. ComponentEvent
c. ItemEvent
d. InputEvent

246. Which event gets generated when the key is typed?

a. KEY_PRESSED
b. KEY_TYPED
c. KEY_RELEASED
d. None of these

247. What method is used to distinguish between single, double and triple
mouse clicks?

a. getButton()
b. getPoint()
c. getClickCount()
d. getX()

248. The getNewState() method belongs to ____

a. TextEvent Class
b. MouseEvent Class
c. WIndowEvent Class
d. KeyEvent Class

For scrollbars ____ event class is used.

a. ActionEvent
b. TextEvent
c. AdjustmentEvent
d. ContainerEvent

249. Which of the following is the highest class in the event-delegation model?

a. Java.util.EventListener
b. Java.util.EventObject
c. Java.awt.AWTEvent
d. Java.awt.event.AWTEvent

250. When two or more objects are added as listeners for the same event, which
listener is first invoked to handle the event?

a. The first object that was added as a listener


b. The last object that was added as listener
c. There is no way to determine which listener will be invoked first
d. It is impossible to have more than one listener for a given event

251. Which of these are integer constants defined in ActionEvent class?

a. ALT_MASK
b. CTRL_MASK
c. SHIFT_MASK
d. All of the mentioned
252. Which of these methods can be used to change location of an event?

a. ChangePoint()
b. TranslatePoint()
c. ChangeCordinates()
d. TranslateCordinates()
253. Which of these are integer constants of ComponentEvent class?

a. COMPONENT_HIDDEN
b. COMPONENT_MOVED
c. COMPONENT_RESIZE
d. All of the mentioned

254. ______object generate te events

Ans - Event Source

255. if you click a button an ___ object is generated

Ans - Action Event

256. The Task of an handling an event is carried out by__

Ans - Event Listener

257. Whichpacakage contains defination of all event classes and listener


interfaces

Ans - java.Awt.event

258. Which class is at the top of event class hirarchy

Ans - Event Object class

259. Event object class belongs to ___ pacakage

Ans - java.util pacakage

260. Which one of the following is a not a part of java.awt.event spacakage

Ans - ___________________________

261. which one of the following methods belongs to event object class

a)getHost()

b)getSource()
c)toString()

d)Both b and c

262. which methods belonging to java.awt.eventpacakage return the nature of


event

Ans - getId()

263. which event object is generated when a component is activated

Ans - Action Event

264. which class object is generated when a component is resized,move,hide


and visible

Ans - Component Event

265. which object is generated when component are added or removed of


container

Ans - Container Event

266. which object is generated when an item form an list is selected

Ans - Item Event

267. which object is generated window object is maximized or minimized

Ans - window Event

268. which object is generated wnen component receive keyboard focus input

Ans - Focus Event

269. which object is generated when mouse is clicked or dragged or mouse


moved.

Ans - Mouse Event


270. which method is useful for obtaining a command String which is specified
during the generation of Event

Ans - getActionCommand

271. which method returns the time at which the event occurs

Ans - long getWhen()

272. which one of the following validated constructor of ItemEvent Class

Ans - ItemEvent

273. which method returns the state Changed type which generated the event

Ans - getStateChange()

274. which method returns the Item where the Event Occured

Ans - getItemMethod()

275. Which method returns the character when the key is pressed

Ans - getKeyChar()

276. Key Constants

CTRL-MASK

SHIFT-MASK

META-MASK

ALT-MASK

277. which Event object is generated when the key is released

Ans - key-RELEASED

278. which Event object is generated when the key is Pressed

Ans - key-PRESSED
279. which Event object is generated when the key is Typed

Ans - key-TYPED

280. which method return which of the mouse button has state changed.

Ans - __________________

281. which method return the x-y position event related to the source
component

Ans - getPoint()

282. which method returns horizontal x position of the event relative to the
source component

Ans - getX()

283. which method returns vertical y position of the event relative to the source
component

Ans - getY()

284. which method returns the number of mouse clicked

Ans - getClickedCount()

285. which event indicated that object text is chaged

`Ans - TextEventClass()

286. which window event constructor construct a window object with the
specified previous and new windowState

Ans - WindowEvent(WindowSource,intid,intoldState,intnewState)

287. which method returns the previous state of window

Ans - getOldState()

288. which method return the old state of window


Ans - getOld()

289. which class implements an interface with the set of dummy code

Ans - AdapterClass()

290. The ___________ interface is used to handle button events:

Ans – ActionListener

291. EventObject class is defined in which of these libraries?

Ans – java.util

292. Which type of event object is generated when component receives


keyboard focus for input ?

Ans – FocusEvent

293. Which method returns the value which indicates the type of key being
pressed at the time of event ?

Ans – int getModifiers()

294. Which method returns the item where the event occurred ?

a. getItemSelectable()
b. getItem()
c. getStateChange()
d. none of these

295. Which method returns the item selectable object where this event
originated ?

a. getItemSelectable()
b. getItem()
c. getStateChange()
d. none of these

296. Which method returns the state change type which generated the event ?

a. getItemSelectable()
b. getItem()
c. getStateChange()
d. none of these

297. In item event class which constant marks the last integer id for the range of
item ?

a. LAST_Item
b. Last_Item
c. ITEM_LAST
d. Item_last

298. In Mouse event class which method returns the absolute x,y position at that
event ?

Ans – Point getLocationOnScreen()

299. Which of these methods are used to register a keyboard event


listener?

Ans – addKeyListener()

300. Which option is correct to adding Jtree in an Applet?

Ans - Create a Jtree Object, Create a JScrollPane object, Add the tree to
the scrollpane and Add the scroll pane to the content pane of the applet.

301. An event is generated when the internal state of the event source is
___________.

a. detected
b. origin
c. changed
d. none of these

302. EventObject contains two important methods:________ and___________

a. getSource()
b. toString()
c. both a & b
d. none of these

303. Focus events are fired whenever a component _____________the focus

a. gains
b. loses
c. both a & b
d. none of these

304. Generated when a window is activated, de-activated, closed, de activated,


de-iconified, iconified, opened or quit

Ans – WindowEvent

305. getID() method is provided by __________ class.

Ans – AWTEvent

306. How to remove the event listener?

Ans - Using removeTypeListener( ) method.

307. Interface used to handle menu events is

Ans – ActionListener

308. MouseEvent is subclass of which of these classes?


a. OutputEvent
b. InputEvent
c. ItemEvent
d. None of these

309. Name the method defined in EventObject class that returns the Object
generated from the
event.select the one correct answer.

a. getSource()
b. getId()
c. getId()
d. none of these

310. TextEvent defines the following integer constatnt:

Ans - TEXT_VALUE_CHANGED

311. The constructor which the Text Event class defines.

Ans - TextEvent(Object source, int event_type)

312. The delegation model is used as a standard for

a. Event Listening
b. MVC
c. Applet
d. None of these

313. The MouseEvent class does not defines the _____________integer


constant.

Ans - MOUSE_WHEELMOVE
314. The MouseListener's _______________ method is called after mouse
button is released

Ans - public void mouseClicked(MouseEvent e)

315. The signature for the registration method for an ActionEvent should be

Ans- public void addActionListener(ActionListener l )

316. Till now two models have been introduced in java for:

Ans - Receiving and processing events

317. What is a listener in the context to event handling?

Ans - A listener is an object that notified when event had occurred.

318. What kind of event is fired when the user selects an item from a menu?

Ans – Action Event

319. When a component obtains keyboard focus, which method is invoked?

Ans - void focusGained(FocusEvent fe)

320. Which class is used for this Processing Method processActionEvent( )?

a. Button
b. List
c. MenuItem
d. All of these

321. Which Method Is used to register a mouse Motion Listner

a. addMouseMotionListener()
b. addMouseListener
c. both a & b
d. none of these
322. Which of the following is the highest class in the event delegation class
hierarchy?

Ans - java.util.EventObject

323. Which of these constant value will change when the button at the end of
scroll bar was clicked
to increase its value?

a. UNIT_INCREMENT
b. UNIT_INCREASE
c. UNIT_STEP
d. None of these

324. Which of these methods can be used to know the degree of adjustment
made by the user?

a. getValue()
b. getID()
c. getModifiers
d. All of these

325. Which of these methods is used to know the full URL of an URL object?

Ans – getHost()

326. Which of these not a constants defined in ComponentEvent class?

a. COMPONENT_HIDDEN
b. COMPONENT_VISIBLE
c. COMPONENT_SIZED
d. All of these
327. ___________class provides an empty implementation of all methods in an
Event Listener
interface?

Ans – Adapter

328. What will happen when you attempt to compile and run the following
code?

Import java.awt.*;

import java.awt.event.*;

public class mouseClick extends Frame implements MouseListener {

public static void main(String argv[]) {

mouseClick s = new MClick();

MClick(){
this.addMouseListener(this);

public void mouseClicked(MouseEvent e)

{
System.out.println(e.getWhen());

}}

Ans - Error not override MouseListener methods ,class name not found

329. Abstract Methods of MouseMotion Listener Interface.

Ans - mouseMoved(MouseEvent) mouseDragged(MouseEvent)


330. Choose the correct missing statement from the given code

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

public class eventdemo2 extends Applet implements ActionListener {


TextField t1,t2;

Button b1;

public void init() {

t1=new TextField(5);

t2=new TextField(5);

b1=new Button("FACTORIAL");

add(t1);

add(t2);

add(b1);

public void
actionPerformed(ActionEvent a)

{ if(a.getSource()==b1)

{ int fact=1;

Int n1=Integer.parseInt(t1.getText());
while(n1!=0)

{ fact=fact*(n1);

n1=n1-1;

}
t2.setText(Integer.toString(fact));

}}}

/* <applet code=eventdemo2.class width=250


height=200> </applet> */

Ans - b1.addActionListener(this);

331. For the following code select the method that can be used to handle event
import java.awt.*;
import java.applet.*;

import java.awt.event.*;

public class ChoiceDemonstration extends Applet


implements ItemListener{

private Choice c;

public void init() {

c= new Choice();
c.addItem("First");

c.addItem("Second");

c.addItem("Third");

c.addItemListener(this);
this.add(c); }
public void ____________(ItemEvent ev)

{ String state ="deselected";


if(ev.getStateChange()== ItemEvent.SELECTED)

{ state = "Selected";

}
System.out.println("ChoiceDemo:" + ev.getItem() +" " +state);

}}

Ans - itemStateChanged(ItemEvent ev)

332. For the following code select the method that can be used to handle event
so that we get proper output. import java.awt.*; import java.awt.event.*; import
java.applet.*;

public class DemoAdjustmentEvent extends Applet implements


AdjustmentListener {

Scrollbar sbRed, sbGreen, sbBlue;

public void init() {

sbRed=new Scrollbar(Scrollbar.VERTICAL,20,10,0,255);
sbGreen=new Scrollbar(Scrollbar.VERTICAL,20,10,0,255);

sbBlue=new Scrollbar(Scrollbar.VERTICAL,20,10,0,255);

add(sbRed); add(sbGreen);

add(sbBlue);
sbRed.addAdjustmentListener(this);

sbGreen.addAdjustmentListener(this);
sbBlue.addAdjustmentListener(this);
}

public void______________________________

{ int
r=sbRed.getValue();

int g=sbGreen.getValue();

int b=sbBlue.getValue();

Color c=new Color(r,g,b);

setBackground(c)

}}

/*<applet code="DemoAdjustmentEvent.class" width=300


height=300></applet>*

Ans - adjustmentValueChanged(AdjustmentEvent ae)

333. For the following code select the method that can be used to handle event.
import java.awt.*;
import java.awt.event.*;

import java.applet.*;

/* <applet code="SBDemo" width=300


height=200> </applet> */

public class SBDemo extends Applet implements AdjustmentListener,


MouseMotionListener

String msg = "";


Scrollbar vertSB, horzSB;

public void init() {

int width = Integer.parseInt(getParameter("width"));

int height = Integer.parseInt(getParameter("height"));

vertSB = new Scrollbar(Scrollbar.VERTICAL,0, 1, 0, height);

horzSB = new Scrollbar(Scrollbar.HORIZONTAL,0, 1, 0, width);

add(vertSB);

add(horzSB);
vertSB.addAdjustmentListener(this);

horzSB.addAdjustmentListener(this);
addMouseMotionListener(this); }

public void ____________________(AdjustmentEvent ae) {


repaint();

public void mouseDragged(MouseEvent me)

int x = me.getX();

int y = me.getY();
vertSB.setValue(y);

horzSB.setValue(x);

repaint();

}
public void mouseMoved(MouseEvent me)

{
} public void paint(Graphics g)

{ msg = "Vertical: " + vertSB.getValue();

msg += ", Horizontal: " + horzSB.getValue();

g.drawString(msg, 6, 160);

g.drawString("*", horzSB.getValue(),
vertSB.getValue());

}}

Ans – adjustmentValueChanged

334. For the following code select the method that can be used to handle event.
import
java.awt.event.*;

import java.awt.*;

import java.applet.*;

/* <applet code="ListDemo" width=300 height=180> </applet> */

public class ListDemo extends Applet implements


ActionListener

List os, browser;

String msg = "";

public void init()


{ os = new List(4, true);
browser = new List(4, false);

// add items to os list

os.add("Windows XP");

os.add("Windows Vista");

os.add("Solaris");

os.add("Mac OS");

// add items to browser list

browser.add("Internet Explorer");

browser.add("Firefox");

browser.add("Opera");

browser.select(1);

// add lists to
window add(os);

add(browser);

// register to receive action events

os.addActionListener(this);
browser.addActionListener(this);

public void _________________

{ repaint();
} // Display
current selections. public void paint(Graphics g)

{ int idx[];

msg = "Current OS: ";

idx = os.getSelectedIndexes();

for(int i=0; i<idx.length; i++)

msg += os.getItem(idx[i]) + " ";


g.drawString(msg, 6, 120);

msg = "Current Browser: ";

msg += browser.getSelectedItem();
g.drawString(msg, 6, 140); } }

Ans- actionPerformed(ActionEvent ae)

335. For the following code select the method that can be used to handle event.

import java.applet.*;
import java.awt.*;

public class S1Q29 extends Applet implements TextListener{

Label l; TextField t1 ; String msg="";

public void init(){

t1 =new TextField(10);

l = new Label("Enter String");


add(t1);

t1.addTextListener(this); }
public void ______________________________

{ msg = t1.getText();

repaint(); }

public void paint(Graphics g)

{ g.drawString(msg,100,100); } } /*
<applet code=checkbackg.class height=150 width=150> </applet>*/

Ans - textChanged(TextEvent e)

336. For the following code select the method that can be used to handle event.
import java.awt.*;
import java.applet.*;

import java.awt.event.*;

/*<applet code=exp.java width=400 height=400> </applet>*/

public class exp extends Applet implements ItemListener

{ Choice c; TextField t1,t2,t3; Label l1,l2,l3;

public void init()

t1=new TextField(10);

t2=new TextField(10);
t3=new TextField(10);

l1=new Label("Enter num");

l2=new Label("Second num");

l3=new Label("Result");
c=new Choice();

c.add("addition");

c.add("subtraction");

add(l1);

add(t1);
add(l2);

add(t2);

add(l3);

add(t3);

add(c);

c.addItemListener(this);

public void __________(ItemEvent e)

String s=c.getSelectedItem();

if(s.equals("addition"))

{ int n1=Integer.parseInt(t1.getText());

int n2=Integer.parseInt(t2.getText());

int n3=n1+n2;
t3.setText(Integer.toString(n3));

}
if(s.equals("subtraction"))

{ int
n1=Integer.parseInt(t1.getText());

int n2=Integer.parseInt(t2.getText());

int n3=n1-n2;
t3.setText(Integer.toString(n3));

}}}

Ans – itemStateChanged

337. For the following code select the method that can be used to handle event.
import java.awt.*;
import java.awt.event.*;

import java.applet.*;

/* <applet code="ButtonDemo" width=250 height=150> </applet> */

public class ButtonDemo extends Applet implements ActionListener {


String msg = ""; Button yes, no, maybe; public void init()

{ yes = new Button("Yes"); no = new


Button("No");

maybe = new Button("Undecided");

add(yes);

add(no);

add(maybe);
yes.addActionListener(this);

no.addActionListener(this);
maybe.addActionListener(this); }

public
void ------------------(ActionEvent ae)

{ String str = ae.getActionCommand(); if(str.equals("Yes"))

{
msg = "You pressed Yes.";

else if(str.equals("No"))

{ msg = "You pressed No.";

} else

{ msg =
"You pressed Undecided.";

} repaint();

public void paint(Graphics g)

{ g.drawString(msg, 6,
100); } }

Ans - actionPerformed(ActionEvent ae)

338. For the following code select the method that can be used to handle event.
import java.awt.*;
import java.awt.event.*;

import java.applet.*;
import javax.swing.*;

/*<applet code="simple" width=300 height=100>- </applet>*/

public class simple extends JApplet implements


KeyListener {

String msg=" ";

int x=10,y=20;

public void init() {

addKeyListener(this);
requestFocus(); }

public void keyPressed(KeyEvent ke)

{ showStatus("key down"); }

public void _______________

(KeyEvent ke)

{ showStatus("Key Up"); }

public void keyTyped(KeyEvent


ke)

{ msg+=ke.getKeyChar();

repaint(); }

public void paint(Graphics g) { g.drawString(msg,x,y);


}}

Ans - keyReleased(KeyEvent ke)


339. For the following code select the method that can be used to handle event.
importjava.awt.event.*;

import java.awt.*;

importjava.applet.*;

public class checkbackg extends Applet implements ItemListener {

Checkbox m1,m2,m3; public void init()

{ m1=new Checkbox("A");

m2=new Checkbox("B");

m3=new Checkbox("C");

add(m1);

add(m2);

add(m3);
m1.addItemListener(this);

m2.addItemListener(this); }

public void __________________ {


if(ie.getSource()==m1) setBackground(Color.red);

if(ie.getSource()==m2)
setBackground(Color.green); } }

/*<applet code=checkbackg.class height=150 width=150>


</applet>*/

Ans - itemStateChanged(ItemEvent ie)


340. For the following code select the method that can be used to handle event.
importjava.awt.event.*;

import java.awt.* ;

import java.applet.*;

public class checkbackg extends Applet implements ItemListener

Checkbox m1,m2,m3; public void init()

{ m1=new
Checkbox("A");

m2=new Checkbox("B");

m3=new Checkbox("C");

add(m1);

add(m2);

add(m3);
m1.addItemListener(this);

m2.addItemListener(this);

} public void
__________________(ItemEvent ie) { if(ie.getSource()==m1)
setBackground(Color.red);
if(ie.getSource()==m2) setBackground(Color.green);

} } /*<applet code=

Ans - itemStateChanged(ItemEvent ie)


341. For the following code select the method that can be used to hanle event.
import java.awt.*;
import java.applet.*;

/*<applet code= “scrolldemo” width =300 height=200> </applet>*/

Public class scrolldemo entends Applet implements AdjustmentListener {


Label l; Scrollbar vsb,hsb;
Public void init()

{ l=new Label(“Scrollbar demo”);

vsb=new Scrollbar(Scrollbar.VERTICAL,0,1,0,100);

hsb=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,100);
add(vsb);

add(hsb);

vsb.addAdjustmentListener(this);

hsb.addAdjustmentListener(this);

} public
void _____________________(AdjustmentEvent ae)

{ l.setText(“Vertical
Scrollbar”+vsb.getValue()+” “+”Horizontal Scrollbar”+hsb.getValue());

}}

Ans - adjustmentValueChanged(AdjustmentEvent ae)

342. getKeyChar() and getKeyCode() methods belongs to


_____________________

Ans - KeyListener interface


343. getSource( ) method of ActionEvent retrieves:

Ans - Component object which generated event.

344. How can a dialog box be closed?

Ans - Using WindowListener

345. Identify wrong method of KeyListener

a. Keytyped()
b. KeyPressed()
c. KeyReleased()
d. keyDragged()

346. keyTyped(KeyEvent e) Called when a key on the keyboard is


________________________

Ans - pressed and then released


Unit 4 : Networking Basics

Total no. of Questions – 146

351. Which package contains the classes and interfaces required for Java
networking?

a. Java.io
b. Java.util
c. Java.net
d. Java.awt

352. Which methods are commonly used in ServerScoket class?

a. Public OutputStream getOutputStream()


b. Public Socket accept()
c. Public synchronized void close()
d. None of these

353. Which class is used to create servers that listen for either local client or
remote client programs?

a. Serversockets
b. Httpserver
c. Httpresponse
d. None of the above

354. Which methods are commonly used in serversocket class?


a) Public OutputStream getOutputStream()
b) Public Socket accept()
c) Public synchronized void close()
d) None of these

355. Which of these is a protocol for breaking and sending the packets to an
address across a network?

a. TCP/IP
b. DNS
c. Socket
d. Proxy Server

356. How many ports of TCP/IP are reserved for specific protocols?

a. 10
b. 1024
c. 2048
d. 512

357. How many bits are in a single IP address?

a. 8
b. 16
c. 32
d. 64

358. URL stands for Uniform Resource Locator and represents on the world
wide web, such as a Webpage.

a. True
b. False

359. Which of these classes is used to encapsulate the IP address and DNS?
a. DatagramPacket
b. URL
c. InetAddress
d. ContentHandler

360. The DatagramSocket and DatagramPacket classes are not used for
connection-less socket programming.

a. True
b. False

361. The client in socket programming must know which informations?

a. IP address of server
b. Port Number
c. Both a and b
d. None of these

362. Datagram is basically an information but there is no guarantee of its


content, arrival or arrival time.

a. True
b. False

363. Which of these is a full form of DNS?

a. Data Network Service


b. Data Name Service
c. Domain Network Service
d. Domain Name Service

364. Port number 80 is reserved for ____ protocol.

a. FTP
b. HTTP
c. SMTP
d. Telnet

365. While using the getLocalHost() method the exception _____ is thrown

a. UnknownHostException
b. NullHostException
c. LostHostException
d. IOException

366. The class ____ is used for accessing the attributes of remote resource.

a. URLConnection
b. URL
c. URI
d. None of these

367. The correct way o using server socket is ____

a. ServerSocket( int port )


b. ServerSocket( int port, int maxQueue)
c. ServerSocket( int port, it maxQueue, InetAddress localAddress)
d. All of these

368. Which method of URL class represents a URL and it has complete set of
methods to manipulate URL in java?

a. Java.net.URL
b. Java.net.URLConnection
c. Java.net.URI
d. None of the above
369. Which of these package contains classes and interfaces for networking?
a) java.io
b) java.util
c) java.net
d) java.network

370. Which of these is a protocol for breaking and sending packets to an address
across a network?
a) TCP/IP
b) DNS
c) Socket
d) Proxy Server

371. How many ports of TCP/IP are reserved for specific protocols?
a) 10
b) 1024
c) 2048
d) 512

372. How many bits are in a single IP address?


a) 8
b) 16
c) 32
d) 64

373. Which of these class is used to encapsulate IP address and DNS?


a) DatagramPacket
b) URL
c) InetAddress
d) ContentHandler
374. What will be the output of the following Java program?

import java.net.*;
class networking
{
public static void main(String[] args) throws UnknownHostException
{
InetAddress obj1 = InetAddress.getByName("Ur Engineering
Friend.com");
InetAddress obj2 = InetAddress.getByName("Ur Engineering
Friend.com");
boolean x = obj1.equals(obj2);
System.out.print(x);
}
}

a. 0
b. 1
c. True
d. False

375. What will be the output of the following Java program?

import java.net.*;
public class networking
{
public static void main(String[] args) throws UnknownHostException
{
InetAddress obj1 = InetAddress.getByName("cisco.com");
InetAddress obj2 = InetAddress.getByName("Ur Engineering
Friend.com");
boolean x = obj1.equals(obj2);
System.out.print(x);
}
}

a. 0
b. 1
c. True
d. False

376. What will be the output of the following Java program?

import java.io.*;
import java.net.*;
public class URLDemo
{
public static void main(String[] args)
{
try
{
URL url=new URL("https://www.urengineeringfriend.in/java-mcq");
System.out.println("Protocol: "+url.getProtocol());
System.out.println("Host Name: "+url.getHost());
System.out.println("Port Number: "+url.getPort());
} catch(Exception e){System.out.println(e);}
}
}

a. Protocol: http
b. Host Name: www.urengineeringfriend.in
c. Port Number: -1
d. All of the mentioned

377. Which of these interface abstractes the output of messages from httpd?
a) LogMessage
b) LogResponse
c) Httpdserver
d) httpdResponse

378. Which of these class is used to create servers that listen for either local or
remote client programs?
a) httpServer
b) ServerSockets
c) MimeHeader
d) HttpResponse

379. Which of these is a standard for communicating multimedia content over


email?
a) http
b) https
c) Mime
d) httpd

380. Which of these methods is used to make raw MIME formatted string?
a) parse()
b) toString()
c) getString()
d) parseString()

381. Which of these class is used for operating on request from the client to the
server?
a) http
b) httpDecoder
c) httpConnection
d) httpd

382. Which of these method of MimeHeader is used to return the string


equivalent of the values stores on MimeHeader?
a) string()
b) toString()
c) convertString()
d) getString()

383. What will be the output of the following Java program?

1. import java.net.*;
2. class networking
3. {
4. public static void main(String[] args) throws Exception
5. {
6. URL obj = new URL("https://www.Ur Engineering
Friend.com/javamcq");
7. URLConnection obj1 = obj.openConnection();
8. System.out.print(obj1.getContentType());
9. }
10. }
Note: Host URL is written in html and simple text.
a) html
b) text
c) html/text
d) text/html

384. Which of these is an instance variable of class httpd?


a) port
b) cache
c) log
d) All of the mentioned

385. Which of these methods of httpd class is used to read data from the stream?
a) getDta()
b) GetResponse()
c) getStream()
d) getRawRequest()

386. Which of these method of httpd class is used to get report on each hit to
HTTP server?
a) log()
b) logEntry()
c) logHttpd()
d) logResponse()

387. Which of these methods are used to find a URL from the cache of httpd?
a) findfromCache()
b) findFromCache()
c) serveFromCache()
d) getFromCache()
388. Which of these variables stores the number of hits that are successfully
served out of cache?
a) hits
b) hitstocache
c) hits_to_cache
d) hits.to.cache

389. Which of these method of httpd class is used to write UrlCacheEntry object
into local disk?
a) writeDiskCache()
b) writetoDisk()
c) writeCache()
d) writeDiskEntry()

390. Which of these method is used to start a server thread?


a) run()
b) start()
c) runThread()
d) startThread()

391. Which of these method is called when http daemon is acting like a normal
web server?
a) Handle()
b) HandleGet()
c) handleGet()
d) Handleget()

392. What does URL stands for?


a) Uniform Resource Locator
b) Uniform Resource Latch
c) Universal Resource Locator
d) Universal Resource Latch

393. Which of these exceptions is thrown by URL class’s constructors?


a) URLNotFound
b) URLSourceNotFound
c) MalformedURLException
d) URLNotFoundException

394. Which of these methods is used to know host of an URL?


a) host()
b) getHost()
c) GetHost()
d) gethost()

395. Which of these methods is used to know the full URL of an URL object?
a) fullHost()
b) getHost()
c) ExternalForm()
d) toExternalForm()

396. Which of these class is used to access actual bits or content information of
a URL?
a) URL
b) URLDecoder
c) URLConnection
d) All of the mentioned

397. What will be the output of the following Java code?

1. import java.net.*;
2. class networking
3. {
4. public static void main(String[] args) throws
MalformedURLException
5. {
6. URL obj = new URL("https://www.Ur Engineering
Friend.com/javamcq");
7. System.out.print(obj.getProtocol());
8. }
9. }

a) http
b) https
c) www
d) com

398. What will be the output of the following Java program?

1. import java.net.*;
2. class networking
3. {
4. public static void main(String[] args) throws
MalformedURLException
5. {
6. URL obj = new URL("https://www.Ur Engineering
Friend.com/javamcq");
7. System.out.print(obj.getPort());
8. }
9. }
a) 1
b) 0
c) -1
d) garbage value

399. What will be the output of the following Java program?

1. import java.net.*;
2. class networking
3. {
4. public static void main(String[] args) throws
MalformedURLException
5. {
6. URL obj = new URL("https://www.Ur Engineering
Friend.com/javamcq");
7. System.out.print(obj.getHost());
8. }
9. }

a) Ur Engineering Friend
b) Ur Engineering Friend.com
c) www.Ur Engineering Friend.com
d) https://www.Ur Engineering Friend.com/javamcq

400. What will be the output of the following Java program?

1. import java.net.*;
2. class networking
3. {
4. public static void main(String[] args) throws
MalformedURLException
5. {
6. URL obj = new URL("https://www.Ur Engineering
Friend.com/javamcq");
7. System.out.print(obj.toExternalForm());
8. }
9. }

a) Ur Engineering Friend
b) Ur Engineering Friend.com
c) www.Ur Engineering Friend.com
d) https://www.Ur Engineering Friend.com/javamcq

401. Which of these is a wrapper around everything associated with a reply


from an http server?
a) HTTP
b) HttpResponse
c) HttpRequest
d) httpserver

402. Which of these transfer protocol must be used so that URL can be accessed
by URLConnection class object?
a) http
b) https
c) Any Protocol can be used
d) None of the mentioned

403. Which of these methods is used to know when was the URL last modified?
a) LastModified()
b) getLastModified()
c) GetLastModified()
d) getlastModified()()
404. Which of these methods is used to know the type of content used in the
URL?
a) ContentType()
b) contentType()
c) getContentType()
d) GetContentType()

405. Which of these data member of HttpResponse class is used to store the
response from an http server?
a) status
b) address
c) statusResponse
d) statusCode

405. What will be the output of the following Java program?

1. import java.net.*;
2. class networking
3. {
4. public static void main(String[] args) throws Exception
5. {
6. URL obj = new URL("https://www.Ur Engineering
Friend.com/javamcq");
7. URLConnection obj1 = obj.openConnection();
8. System.out.print(obj1.getContentType());
9. }
10. }

Note: Host URL is written in html and simple text.


a) html
b) text
c) html/text
d) text/html

406. What will be the output of the following Java program?

1. import java.net.*;
2. class networking
3. {
4. public static void main(String[] args) throws Exception
5. {
6. URL obj = new URL("https://www.Ur Engineering
Friend.com/javamcq");
7. URLConnection obj1 = obj.openConnection();
8. System.out.print(obj1.getLastModified);
9. }
10. }

Note: Host URL was last modified on june 18 tuesday 2013.


a) june
b) 18-6-2013
c) Tue 18 Jun 2013
d) Tue Jun 18 2013

407. Which of these is a bundle of information passed between machines?


a) Mime
b) Cache
c) Datagrams
d) DatagramSocket

408. Which of these class is necessary to implement datagrams?


a) DatagramPacket
b) DatagramSocket
c) All of the mentioned
d) None of the mentioned

409. Which of these method of DatagramPacket is used to find the port number?
a) port()
b) getPort()
c) findPort()
d) recievePort()

410. Which of these method of DatagramPacket is used to obtain the byte array
of data contained in a datagram?
a) getData()
b) getBytes()
c) getArray()
d) recieveBytes()

411. Which of these methods of DatagramPacket is used to find the length of


byte array?
a) getnumber()
b) length()
c) Length()
d) getLength()

412. Which of these class must be used to send a datagram packets over a
connection?
a) InetAdress
b) DatagramPacket
c) DatagramSocket
d) All of the mentioned
413. Which of these method of DatagramPacket class is used to find the
destination address?
a) findAddress()
b) getAddress()
c) Address()
d) whois()

414. Which of these is a return type of getAddress() method of DatagramPacket


class?
a) DatagramPacket
b) DatagramSocket
c) InetAddress
d) ServerSocket

415. Which API gets the SocketAddress (usually IP address + port number) of
the remote host that this packet is being sent to or is coming from.
a) getSocketAddress()
b) getAddress()
c) address()
d) none of the mentioned

416. Which components belongs to client server programming ?

a. Client pc or web client


b. Application server
c. Database server
d. All of these

417. Reserved port number for POP3 is _______

Ans – 110

418. A __________ sits between the client and a real server .


Ans – Proxy server

419. What is the purpose of having a proxy server ?

Ans – It improves the information by caching the information.

420. In IP address class which class is used for Medium size organizations ?

a. Class A
b. Class B
c. Class C
d. Class D

421. In IP address class which class is used for Large size organizations ?

a. Class A
b. Class B
c. Class C
d. Class D

422. In IP address class which class is used for small size organizations ?

a. Class A
b. Class B
c. Class C
d. Class D

423. In IP address class which class is used for multicast groups ?

a. Class A
b. Class B
c. Class C
d. Class D

424. In IP address class which class is reserved for experimental purposes ?


a. Class A
b. Class E
c. Class C
d. Class D

425. In IP address class what is the correct range of class B ?

a. 1 to 126
b. 127 to 191
c. 192 t0 223
d. 224 to 239

426. In IP address class what is the correct range of class A ?

a. 1 to 126
b. 127 to 191
c. 192 t0 223
d. 224 to 239

427. Using Ip address _________ can b identified in the network.

a. Node
b. Proxy server
c. Data base server
d. None of these

428. What layer in the TCP/IP stack is equivalent to the Transport layer of the
OSI model?
a) Application
b) Host to host
c) Internet
d) Network Access
429. You want to implement a mechanism that automates the IP configuration,
including IP address, subnet mask, default gateway, and DNS information.
Which protocol will you use to accomplish this?
a) SMTP
b) SNMP
c) DHCP
d) ARP

430. The DoD model (also called the TCP/IP stack) has four layers. Which
layer of the DoD model is equivalent to the Network layer of the OSI model?
a) Application
b) Host to Host
c) Internet
d) Network Access

431. Which of the following protocols uses both TCP and UDP?
a) FTP
b) SMTP
c) Telnet
d) DNS

432. Length of Port address in TCP/IP is _________


a) 4bit long
b) 16bit long
c) 32bit long
d) 8 bit long

433. TCP/IP layer is equivalent to combined Session, Presentation and


_________
a) Network layer
b) Application layer
c) Transport layer
d) Physical layer

434. How many levels of addressing is provided in TCP/IP protocol?


a) One
b) Two
c) Three
d) Four

435. Virtual terminal protocol is an example of _________


a) Network layer
b) Application layer
c) Transport layer
d) Physical layer

436. TCP/IP is related to __________


a) ARPANET
b) OSI
c) DECNET
d) ALOHA

437. A device operating at network layer is called __________


a) Router
b) Equalizer
c) Bridge
d) Repeater

438. A device operating at physical layer is called __________


a) Router
b) Equalizer
c) Bridge
d) Repeater
439. _______ are denoted by streams.

Ans – TCP Sockets

440. _______ are denoted by datagrams

Ans – UDP Sockets

441. Which class is used to establish connection between application programs


and URL ?

Ans – URLConnection

442. Which interface is for defining the factory for implementing the sockets ?

a. SocketImpFactory
b. ContentHandlerFactory
c. URLStreamHandlerFactory
d. None of these

443. Which interface is for defining the factory for content handlers ?

a. SocketImpFactory
b. ContentHandlerFactory
c. URLStreamHandlerFactory
d. None of these

444. Which interface is for implementing URL Stream protocol handlers ?

a. SocketImpFactory
b. ContentHandlerFactory
c. URLStreamHandlerFactory
d. None of these

445. Which methods belongs to InetAddress class ?


a. getLocalHost()
b. getByName()
c. getAllByName()
d. all of these

446. Which methods does not belongs to InetAddress class ?

a. getLocalHost()
b. getByName()
c. getAllByName()
d. getHostName()

447. What kind of exception main function throws while using InetAddress
class ?

Ans – UnknownHostException

448. Which of the following is unreliable and connection less protocol ?

a. TCP
b. UDP
c. IP
d. Both b & c

449. Which of the following is reliable and connection-oriented protocol ?

a. TCP
b. UDP
c. IP
d. None of these

450. Which of the following is unreliable and connection less protocol that
transfer the data in the form of packets ?

a. TCP
b. UDP
c. IP
d. None of these

451. Which of the following is unreliable and connection less protocol that
transfer the data in the form of datagrams ?

a. TCP
b. UDP
c. IP
d. None of these

452. In which protocol control information is being sent before transmitting any
data ?

a. TCP
b. UDP
c. IP
d. None of these

453. In which protocol control information is not being sent before transmitting
any data ?

a. TCP
b. UDP
c. IP
d. None of these

454. What do you mean by hand shaking in TCP ?

Ans – Sending of control information before transmitting any data , this


process is known as hand shaking.
455.The WHOIS protocol is a TCP-based protocol designed to work on the port
________ .

Ans – 43.

456. The general format of URL is _______

Ans – Scheme : Address

457. Which method returns an input stream from the other side of the socket ?

a. getInputStream()
b. getOutputStream()
c. both a & b
d. none of these

458. What are the constructors used for datagram packets ?

a. DatagramPacket(byte[] barr, int length )


b. DatagramPacket(byte[] barr, int length, InetAddress addresss, int port)
c. Both a & b
d. None of these

459. TCP/IP reserves the ____________ ports for specific protocols

Ans – lower 1024

460. A ServerSocket can connect to ________ clients.

a. Single
b. Two
c. Multiple
d. None of these

461. A socket identifies __________ in network.


Ans - a communication end point

462. A_______ is responsible for determining whether code executing in


the Java runtime environment has permission to perform a security-
sensitive operation.

Ans – policy object

463. byte[] getData() method of DatagramPacket class


returns_____________________

Ans - Byte array of data contained in datagram

464. Communication using TCP protocol is __________and _________

Ans - connection-oriented, concurrent

465. How many bits are in a single IPv4 address?

Ans – 32 bits

466. In which class the constructors are not visible`

Ans - Inetaddress class

467. Permission class belongs to which package?

Ans - java.security

468. Pretty Good Privacy (PGP) is used in security of

Ans – Email

469. TCP is Which Type of Protocol ?

Ans - Connection oriented protocol

470. The server listens for a connection request from a client using the
following statement:
Ans - Socket s = ServerSocket.accept()

471. To create an InputStream on a Socket s, you use __________.

Ans - InputStream in = s.getInputStream();

472. To obtain an ObjectOutputStream from a socket,use__________

Ans - new ObjectOutputStream(socket.getOutputStream())

473. Which class is used to implement datagrams with UDP protocol.

Ans – DatagramSocket

474. Which constructor of DatagramSocket class is used to create a


datagram socket and bind it with the given port number?

Ans - DatagramSocket(int port)

475. Which method is used to know the full URL of an URL object?

Ans - toExternalForm()

476. Which of the following is mediator between real web server and client
application

Ans – Proxy

477. Which of these class is used to encapsulate IP address and DNS?

Ans – InetAddress

478. ______is networking protocol for hypermedia, collaborative &


distributed information system.

Ans – HTTP

479. __________method is used to examine the address and port


information by the socket.
Ans – getInetAddress()

480. ________________ is abstract class for representing access to a


system resource

Ans – permission

481. ________________ method of DatagramSocket class is used to


receive DatagramPacket.

Ans - receive(DatagramPacket packet)

482. getByname() method returns

Ans – Host name

483. Http is which type of Protocol

Ans – stateless

484. Select the fullform of DNS

Ans - Domain Name System

485. Select the proper method to retrieve the host name of local machine

Ans - static InetAddress.getLocalHost( )throws UnknownHostException

486. Socket connection = server.accept( ); In the above statement, server


is an object of ___________class and accept() method throws
________exception.

Ans - ServerSocket, IOException

487. The connection establishment in TCP is called

Ans - three- way handshaking


488. To access the URLConnection Class object which of the transfer
protocol is used?

Ans – http

489. What is correct code to get ip address of host machine ?

Ans - import java.net.*;

class InetAddressTest {

public static void main(String args[]) throws UnknownHostException {


InetAddress Address = InetAddress.getLocalHost();
System.out.println(Address);

}}

490. What is the use of writeUTF( ) method?

Ans - This method writes a string into underlying output stream

491. Which datagram method returns the byte array of data contained in
the datagram?

Ans - byte[] getData ()

492. You can obtain the server's hostname by invoking _________ on an


applet.

Ans - getCodeBase().getHost()

493. ________ server can process multiple request at a time

Ans - a concurrent
494. A technique that creates a subletting effect; one server answers ARP
requests for multiple hosts?

Ans- Proxy Server

You might also like