[go: up one dir, main page]

0% found this document useful (0 votes)
17 views156 pages

Advance Java Exam Sutra MCQ Book - Ur Engineering Friend

Uploaded by

rms744746
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views156 pages

Advance Java Exam Sutra MCQ Book - Ur Engineering Friend

Uploaded by

rms744746
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 156

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


Syllabus

Component , Container , Window , Panel , Frame


Unit 1 Windowed programs and applets
AWT Controls : Lables , buttons , checkbox ,
checkbox group , radio button , scroll bars , text
Abstract
field , text area.
Windowing Layout manager : Flow layout , border layout , Grid
Toolkit layout , Gridbag layout , Menubars , Dialog boxes ,
File dialog

Introduction to Swing : Swing features , difference


Unit 2 between Swing and AWT
Swing components : JApplet , Icons and Labels , Text
Swing fields and combos
JButton , Jcheckbox and JRadioButton
Advanced Swing components : Tabbed panes , Scroll
panes , Trees , Tables , Progress bar , Tool tips
MVC architecture

The event delegation model : Event sources , Event


Unit 3 listeners
Event classes : Action event , Item event , key event ,
mouse event , text event , window event
Event
Adapter class
Handling Inner class
Event listener interfaces : Actionlistener interface ,
ItemListener inteface , KeyListener interface ,
MouseListener interface , MouseMotionListener
interface , TextListener Interface , WindowsListener
interface
Syllabus

Socket Overview : Client / Server , Reserved Sockets ,


Unit 4 Proxy servers , Internet addressing
Java and the Net : The networking classes and
Interfaces
Networking
InetAddress : Factory methods , Instance methods
Basics TCP/IP Client sockets : Whois
URL : Format , The URI Class
URL Connection : TCP / IP Server sockets
Datagrams : Datagram packets , Datagram server
and client

Introduction to JDBC , ODBC


Unit 5 JDBC architecture : Two tier and three tier models
Types of JDBC drivers
Interacting Driver interfaces and Driver manager class :
with Connection Interface Statement , Prepared
Statement Interface , ResultSet Interface
Database
The essential JDBC Program

Life cycle of a Servlets


Unit 6 Creating simple servlets : The Servlet API ,
javax.servelt package , Servlet interface ,
Servelts ServletConfig interface , ServletContext interface ,
ServletRequest interface , ServletResponse interface
, Generic Servlet class
The javax.servlet.http package : HttpeServletRequest
Interface , HttpServletResponse Interface ,
HttpSession Interface , Cookie class , HttpServlet
class , HttpSessionEvent class ,
HttpSessionBindingEvent class
Handling HTTP requests and responses , Handling
HTTP GET Request , Handling HTTP POST Request
Cookies and session tracking
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


Unit 5 : Interacting with Database

Total no. of Questions – 100

501. JDBC stands for ______

a. Java Database Connectivity


b. Java Database Control
c. Java Database Components
d. None of these

502. Which statements about JDBC are true?

a. JDBC is an API to connect to relational-, object and XML data sources.


b. JDBC stands for Java Database Connectivity
c. JDBC is an API to access relational databases, spreadsheets and flat
files
d. JDBC is an API to bridge the object-relational mismatch between OO
programs and relational databases.

503. Which package contains the JDBC classes?

a. Java.jdbc and javax.jdbc


b. Java.jdbc and java.jdbc.sql
c. Java.sql and javax.sql
d. Java.rdb and javax.rdb

JDBC technology based drivers generally fit into how many categories?
a. 4
b. 3
c. 2
d. 5

504. Which type of driver provides JDBC access via one or more ODBC
drivers?

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

505. Which type of driver converts JDBC calls into the network protocol used
by the database management system directly?

a) Type 1 driver
b) Type 2 driver
c) Type 3 driver
d) Type 4 driver

506. Which type of driver of JDBC is called pure driver?

a) Type 1 driver
b) Type 2 driver
c) Type 3 driver
d) Type 4 driver

507. Which type of driver of JDBC is called partly Java driver?

a) Type 1 driver
b) Type 2 driver
c) Type 3 driver
d) Type 4 driver
508. Which driver is efficient and always preferable for using JDBC
applications?

a) Type 1 driver
b) Type 2 driver
c) Type 3 driver
d) Type 4 driver

509. The JDBC-ODBC bridge is _____

a. Three-tired
b. Multithreaded
c. Best for any platform
d. All of the above

510. Which driver is called as thin-driver in JDBC?

a) Type 1 driver
b) Type 2 driver
c) Type 3 driver
d) Type 4 driver

511. Which driver type of JDBC is used in either applet or servlet?

a. Type 1 and 2
b. Type 1 and 3
c. Type 3 and 4
d. Type 4 only

512. Which of the following is false as far as type 4 driver is concern?

a. Type 4 driver is native protocol pure java driver


b. Type 4 drivers are 100% java compatible
c. Type 4 drivers uses socket class to connect to the database
d. Type 4 drivers can not be used with Netscape.

513. Which of the following JDBC drivers is known as a partially java driver?

a. JDBC-ODBC bridge driver


b. Native-API driver
c. Network Protocol driver
d. Thin driver

514. Which class has strong support of the JDBC architecture?

a. The JDBC driver manager


b. The JDBC driver test suite
c. The JDBC-ODBC bridge
d. All of these

515. In order to transfer data between a database and an application written in


the java programming language, the JDBC API provides which of these
methods?

a. Methods on the result set class for retrieving SQL Select results as Java
types
b. Methods on the prepared statement class for sending java types as SQL
statement parameters.
c. Methods on the callable statement class for retrieving SQL OUT
parameters as java types
d. All of these

516. The JDBC API has always supported persistent storage of objects defined
in the java programming language through the methods getObject and
setObject.
a. True
b. False

517. What is, in terms of JDBC, a data source?

a. A datasource is the basic service for managing a set of JDBC drivers


b. A data source is the java representation of a physical data source
c. A datasource is a registry point for JNDI-services
d. A data source is a factory of connections to a physical data source

518. Which of the following describes the correct sequence of the steps
involved in making a connection with a database?

1. Loading the driver


2. Process the result
3. Making the connection with the database
4. Executing the SQL statements
a. 1,3,4,2
b. 1,2,3,4
c. 2,1,3,4
d. 4,1,2,3

519. Which of the following methods are needed for loading a database driver
in JDBC?

a. registerDriver() method
b. Class.forName()
c. Both a & b
d. getConnection()

520. Which type of statement can execute parameterized queries?

a. preparedStatement
b. parametrizedStatement
c. CallableStatement
d. All of these

521. What is used to execute parameterized query?

a. Statement Interface
b. PreparedStatement Interface
c. ResultSet Interface
d. None of the above

522. Which of the following encapsulates an SQL statement which is passed to


the database to be parsed, compiled, planned and executed?

a. DriverManager
b. JDBC driver
c. Connection
d. Statement

523. Which of the following is used to call a stored procedure?

a. Statement
b. PrepareStatement
c. CallableStatement
d. CalledStatement

524. What happens if you call deleteRow() on a ResultSet Object?

a. The row you are positioned on is deleted from the ResultSet, but not
from the database
b. The row you are positioned on is deleted from the ResultSet and from
the database
c. The result depends on whether the property synchronize with
DataSource is set to true or false
d. You will get a compile error
525. The JDBC-ODBC bridge supports multiple concurrent open statements per
connection.

a. True
b. False

526. All raw data types should be read and uploaded to the database as an array
of _____

a. Byte
b. Int
c. Boolean
d. Char

527. Are prepared statements actually compiled?

a. Yes
b. No

528. When the message “No suitable driver” occurs?

a. When the driver is not registered by class.forname() method


b. When the user name, password and the database does not match
c. When the JDBC database URL passed is not constructed properly
d. When the type 4 driver is used

529. Database system compiles query when it is ____

a. Executed
b. Initialized
c. Prepared
d. Invoked

530. _______ is an open source DBMS product that runs in window as well as
Linux.
a. JSP/SQL
b. MySQL
c. Microsoft Access
d. SQL Server

531. To execute a statement, we invoked method _______

a. executeUpdate method
b. executeRel method
c. executestmt method
d. executeConn method

532. method on resultset that tests whether or not there remains at least one
unfetched tuple in result set, is said to be

a. fetch method
b. current method
c. next method
d. access method

533. the ResultSet.next method is used to move to the next row of the ResultSet,
making it the current row.

a. True
b. False

534. ResultSet object can be moved forward only and it is updatable.

a. True
b. False

535. Which JDBC drivers will run your program?

a. The JDBC-ODBC bridge


b. The JDBC driver manager
c. The JDBC driver test suite
d. None of the above

536. JDBC is a java API that is used to connect and execute query to the
database.

a. True
b. False

537. What are the major components of the JDBC?

1. DriverManager, Driver, Connection, Statement, and ResultSet


2. DriverManager, Driver, Connection, and Statement
3. DriverManager, Statement, and ResultSet
4. DriverManager, Connection, Statement, and ResultSet

538. Select the packages in which JDBC classes are defined?

1. jdbc and javax.jdbc


2. rdb and javax.rdb
3. jdbc and java.jdbc.sql
4. sql and javax.sql

539. Thin driver is also known as?

1. Type 3 Driver
2. Type-2 Driver
3. Type-4 Driver
4. Type-1 Driver
540. Which of the following method is used to perform DML statements in
JDBC?

1. executeResult()
2. executeQuery()
3. executeUpdate()
4. execute()

541. How many transaction isolation levels provide the JDBC through the
Connection interface?

1. 3
2. 4
3. 7
4. 2

542. Which of the following method is static and synchronized in JDBC API?

1. getConnection()
2. prepareCall()
3. executeUpdate()
4. executeQuery()

543. Parameterized queries can be executed by?

1. ParameterizedStatement
2. PreparedStatement
3. CallableStatement and Parameterized Statement
4. All kinds of Statements

544. Which of the following is not a valid statement in JDBC?

1. Statement
2. PreparedStatement
3. QueryStatement
4. CallableStatement

545. Identify the isolation level that prevents the dirty in the JDBC Connection
class?

1. TRANSACTION_READABLE_READ
2. TRANSACTION_READ_COMMITTED
3. TRANSACTION_READ_UNCOMMITTED
4. TRANSACTION_NONE

546. What does setAutoCommit(false) do?

1. It will not commit transactions automatically after each query.


2. It explicitly commits the transaction.
3. It never commits the transactions.
4. It does not commit transaction automatically after each query.

547. Stored procedure can be called by using the ????..?

1. CallableStatement
2. Statement
3. CalledStatement
4. PreparedStatement

548. What should be the correct order to close the database resource?What
should be the correct order to close the database resource?

1. Connection, Statements, and then ResultSet


2. ResultSet, Connection, and then Statements
3. Statements, ResultSet, and then Connection
4. ResultSet, Statements, and then Connection

549. A good way to debug JDBC-related problems is to enable???..?

1. JDBC tracing
2. Exception handling
3. Both a and b
4. Only b

550. JDBC-ODBC driver is also known as?

1. Type 4
2. Type 3
3. Type 1
4. Type 2

551. Which of the following driver is the fastest one?

1. JDBC-ODBC Bridge Driver


2. Native API Partly Java Driver
3. Network Protocol Driver
4. JDBC Net Pure Java Driver

552. Which of the following is not a type of ResultSet object?

1. TYPE_FORWARD_ONLY
2. CONCUR_WRITE_ONLY
3. TYPE_SCROLL_INSENSITIVE
4. TYPE_SCROLL_SENSITIVE

553. What is JDBC Savepoint?

1. An intermediate or checkpoint in a transaction


2. A point where we can store queries
3. A point where the JDBC application starts execution
4. A memory where we can store transaction

554. How many stages are used by Java programmers while using JDBC in their
programs?

1. 3
2. 2
3. 5
4. 6

555. Which of the following is the correct to register a JdbcOdbcDriver?

1. jdbc.odbc.JdbcOdbcDriver obj = new sun.jdbc.odbc.JdbcOdbcDriver();


2. odbc.JdbcOdbcDriver obj = new sun.odbc.JdbcOdbcDriver();
3. jdbc.JdbcOdbcDriver obj = new sun.jdbc.JdbcOdbcDriver();
4. jdbc.odbc.JdbcOdbc obj = new sun.jdbc.odbc.JdbcOdbc();

556. How many ways to register a driver?

1. 2
2. 3
3. 4
4. 5

557. Identify the DSN in the following statement:

DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger")

1. jdbc
2. odbc
3. scott
4. oradsn

558. Which statement is correct if we want to connect the Oracle database using
the thin driver provided by Oracle Corp.?

1. getConnection("jdbc::thin@localhost:1521:oracle", "scott", "tiger");


2. getConnection("jdbc:thin@localhost:1521:oracle", "scott", "tiger");
3. getConnection("jdbc::thin@localhost:1522:oracle", "scott", "tiger");
4. getConnection("jdbc::oracle@localhost:1521:thin", "scott", "tiger");

559. What are the types of ResultSet in JDBC?

1. Forward ResultSet
2. Scrollable ResultSet
3. Only a
4. Both a and b

560. Which data type is used to store files in the database table?

1. BLOB
2. CLOB
3. File
4. Both a and b

561. DatabaseMetaData interface is used to get?????..?

1. Comprehensive information about the database as a whole.


2. Comprehensive information about the table as a whole.
3. Comprehensive information about the column as a whole.
4. Both b and c

562. Which of the following driver converts the JDBC calls into database-
specific calls?
1. JDBC-ODBC Bridge Driver (Type 1)
2. Native API-partly Java Driver (Type 2)
3. Net Protocol-pure Java Driver (Type 3)
4. Native Protocol-pure Java Driver (Type 4)

563. Which of the following interface provides the commit() and rollback()
methods?

1. Statement Interface
2. ResultSet Interface
3. Connection Interface
4. RowSet Interface

564. JDBC API supports____________ and __________ architecture model for


accessing the database.

1. Two-tier
2. Three-tier
3. Both a and b
4. Only b

565. A Java program cannot directly communicate with an ODBC driver


because

Ans - ODBC written in C language

566. Abbreviate the term DSN

Ans - Data Source Name

567. API stands for

Ans - application program interface


568. API which controls access to the row result of a given Statement and holds
data retrieved
from a database after you execute an SQL query using Statement objects.

Ans - java.sql.ResultSet

569. Application Server used in ____________________

Ans - Three-Tier Mode

570. Backbone of JDBC Architecture is ________________

Ans - Driver Manager

571. boolean isLast() method defines _______

Ans - Determines whether the ResultSet cursor points to the last row of
the ResultSet

572. Callable Staement used to --------

Ans - calling procedure

573. Callable statement object in JDBC is used to execute a call to

Ans – Stored procedure

574. Choose the correct syntax for getConnection() method

Ans - public static Connection getConnection(String url, String name,


String password)
SQLException

575. Connection object can be initialized using the _______ method of the
DriverManager Class.

Ans - getConnection()
576. createStatement() method without any parameter is used to create a
statement with

Ans - a forward only and read only ResultSet

577. DriverManager.getConnection(_______ , ______ , ______) What are the


two parameters that
are included ?

Ans - URL or machine name where server runs, User ID, Password

578. For execution of INSERT SQL query in JDBC, ............. method must be
used.

Ans - executeUpdate()

579. For execution of SELECT SQL query in JDBC, ___________________


method must be used.

Ans - executeQuery()

580. If you need to use a stored procedure with output parameters, which of the
following
statement type should be used to call the procedure?

a. Callable statement
b. Prepared statement
c. Both a & b
d. None of these

581. If a PreparedStatement is a SQL SELECT statement, you execute the


statement using
________.

a. Callable statement.executeQuery()
b. Prepared statement.executeQuery()
c. Both a & b
d. None of these

582. In which type of driver must Odbc drivers be loaded on client machine?

a. Types 2
b. Type 1
c. Type 3
d. None of these

583. Invoking Class.forName() method may throw _________

Ans – ClassNotFoundException

584. JDBC-ODBC bridge product provide _________ access via


____________.

a. JDBC Driver
b. ODBC driver
c. Both a & b
d. None of these

586. Name the type number belongs to JDBC ODBC Bridge driver?

a. Types 2
b. Type 1
c. Type 3
d. None of these

587. ODBC minimum SQL grammar contains

a. Insert
b. Update
c. Delete only
d. All of these

588. Which JDBC driver Types are used for over communications networks?

a. Types 2
b. Type 4
c. Type 3
d. Both b & c

589. Which of the following is the correct order of keywords for SQL SELECT
statements?

a. SELECT , WHERE . FROM


b. SELECT , FROM , WHERE
c. Both can be correct
d. None of these

590. __________ interface is used to know the capabilities or information


about a database
Management system DBMS with JDBC Driver.

`Ans - Database Metadata

591. ________________ is a table of data which represents a data from


database

Ans – ResultSet

592. Choose the correct option to establish a connection to database named


student and
display its contents.

Ans -
593. Choose missing statements in following code from given options. import
java.sql.*;

Class DemoFetch {

public static void main(String args[]) {

Connection con;

Statement stmt;
ResultSet rs;

String qry, url;

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
url="Jdbc:Odbc:studdsn";

con=DriverManager.getConnection(url,"","");
stmt=con.createStatement();

qry="select * from stud";

rs=_______________;
System.out.println("Roll No\tName\tPercentage");

while(rs.next()) {

int rno=rs.getInt("roll");
String nm=rs.getString("sname");
double per=rs.getDouble("per");
System.out.println(rno+"\t"+nm+"\t"+per);

} con.close(); }

catch(Exception e){

}}}

Ans - stmt.executeQuery(qry)

594. The parameters of the PreparedStatement object are _____when the user
clicks on the Query
button

Ans – Initialized

595. This statement Tells the DB to empty transaction log & bring DB back to
the state, before the changes in transaction log were executed

Ans – rollback()

596. To establish connection with database which method of DriverManager


class is used?

Ans – getConnection()

597. To establish the connection with the specified url?

Ans - public static Connection getConnection(String url)

598. what will be output of given code

//Load the database Driver


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //Establish connection with
the database
Connection Con=DriverManager.getConnection("jdbc:odbc:Stud1")
//Create the statement
object Statement stmt=con.createStatement();

//Formulate the query

String sql="delete from StudTable where Name=”Abc'"; //Execute the query


i=stmt.executeUpdate(sql);
System.out.println("Record deleted...."+i);

con.close();

Ans – Record will be deleted

599. What will be output of this program import java.sql.*;

public class JDBCExample {

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


Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Connecting to database...");

conn = DriverManager.getConnection(jdbc:odbc:stud”);

stmt = conn.createStatement();

String sql = "CREATE TABLE REGISTRATION " + "(id INTEGER not


NULL, " + " first VARCHAR(255),”+"last VARCHAR(255),"+ " age
INTEGER, " + " PRIMARY KEY ( id ))";

stmt.executeUpdate(sql);

}}

Ans - It will create a table with name registration


600. When using ODBC, which of the following processes ODBC requests and
submits specific SQL
statements to a given type of data source?

Ans - Driver.

601. Which type of Statement can execute parameterized


queries?
a. PreparedStatement
b. ParameterizedStatement
c. ParameterizedStatement and CallableStatement
d. All kinds of Statements (i.e. which implement a sub interface of
Statement)

602. How can you retrieve information from a ResultSet?


a. By invoking the method get(..., String type) on the ResultSet, where
type is the database type
b. By invoking the method get(..., Type type) on the ResultSet, where
Type is an object which represents a database type
c. By invoking the method getValue(...), and cast the result to the
desired Java type.
d. By invoking the special getter methods on the ResultSet:
getString(...), getBoolean (...), getClob(...),...

603. What is, in terms of JDBC, a DataSource?


a. A DataSource is the basic service for managing a set of JDBC
drivers
b. A DataSource is the Java representation of a physical data source
c. A DataSource is a registry point for JNDI services
d. A DataSource is a factory of connections to a physical data source
604. What statements are correct about JDBC transactions (2
correct answers)?
a. A transaction is a set of successfully executed statements in the
database
b. A transaction is finished when commit() or rollback() is called on
the Connection object,
c. A transaction is finished when commit() or rollback() is called on the
Transaction object
d. A transaction is finished when close() is called on the Connection
object.

605. How can you execute a stored procedure in the


database?
a. Call method execute() on a CallableStatement object
b. Call method executeProcedure() on a Statement object
c. Call method execute() on a StoredProcedure object
d. Call method run() on a ProcedureCommand object

606. What happens if you call the method close() on a ResultSet object?

a. the method close() does not exist for a ResultSet. Only Connections
can be closed.
b. the database and JDBC resources are released
c. you will get a SQLException, because only Statement objects can
close ResultSets
d. the ResultSet, together with the Statement which created it and the
Connection from which the Statement was retrieved, will be closed
anrelease all database and JDBC resources
607. What happens if you call deleteRow() on a ResultSet
object?
a. The row you are positioned on is deleted from the ResultSet, but not
from the database.
b. The row you are positioned on is deleted from the ResultSet and
from the database
c. The result depends on whether the propert synchronizeWithDataSource
is set to true or false
d. You will get a compile error: the method does not exist because you
can not delete rows from a ResultSet

608. What statements are correct about batched insert and updates? (2 answers)
a. To create a batch of insert and update statements, you create an
object of type Batch, and call the method addStatement(String
statement) for each statement you want to execute in the batch
b. Batch insert and updates are only possible when making use of
parameterized queries.
c. To do a batched update/insert, you call addBatch(String statement)
on a Statement object for each statement you want to execute in the
batch
d. To execute a batched update/insert, you call the executeBatch()
method on a Statement object

609. Which of the following methods are needed for loading a


database driver in JDBC?
a. registerDriver() method
b. Class.forName()
c. Both A and B
d. getConnection()
610. Which of the following is false as far as type 4 driver is
concern?
a. Type 4 driver is “native protocol, pure java” driver
b. Type 4 drivers are 100% Java compatible
c. Type 4 drivers uses Socket class to connect to the database
d. Type 4 drivers can not be used with Netscape

611. Which statement is static and synchronized in JDBC


API?
a. executeQuery()
b. executeUpdate()
c. getConnection()
d. prepareCall()

612. The JDBC ODBC bridge is


a. Three tiered
b. Multithreaded
c. Best for any platform
d. All of the above

613. When the message “No Suitable Driver” occurs?


a. When the driver is not registered by Class.forname() method
b. When the user name, password and the database does not match
c. When the JDBC database URL passed is not constructed properly
d. When the type 4 driver is used
Unit 6 : Servlets

Total no. of Questions – 120

630. The Java ___ specification defines an application programming interface


for communication between the web server and the application program.

a. Servlet
b. Randomize
c. Applet
d. Script

631. Which method is used to specify before any lines that uses the PintWriter?

a. setPageType()
b. setContextType()
c. setContentType()
d. setResponseType()

632. what are the functions of servlet container?

a. Lifecycle management
b. Communication support
c. Multithreading support
d. All of the above

633. What is bytecode?

a. Machine-specific code
b. Java code
c. Machine-independent code
d. None of these

634. What type of servlets use these methods doGet(), doPost(), doHead(),
doDelete(), doTrace() ?

a. Generic Servlets
b. HttpServlets
c. All of the above
d. None of these

635. Web server is used for loading the init() method of servlet.

a. True
b. False

636. Which package represent interfaces and classes for servlet API?

a. Javax.servlet
b. Javax.servlet.http
c. Both a & b
d. None of these

637. What is the lifecycle of a servlet?

a. Servlet class is loaded


b. Servlet instance is created
c. Init, service, destroy method is invoked
d. All of these

638. What is the difference between servlet and applet?

a. Servlets execute on servers while applets execute on browser


b. Servlets create static pages while applets create dynamic pages
c. Servlets can exec ute single request while applets execute multiple
requests
d. None of these

639. A deployment descriptor descirbes

a. Web component response setting


b. Web component settings
c. Web component request settings
d. All of these

640. Which object is created by the web container at time of deploying the
project?

a. servletConfig
b. servletContext
c. both a & b
d. none of these

641. In HTTP request method Get request is secured because data is exposed in
URL bar

a. True
b. False

642. Which class can handle any type of request so that is protocol-
independent?

a. GenericServlet
b. HTTPServlet
c. Both a & b
d. None of these
643. Servlet technology is used to create web application

a. True
b. False

644. The doGet() method extracts values of the parameter’s types number by
using _______

a. Response.getAttribute()
b. Response.getParameter()
c. Request.getParameter()
d. Request.setParameter()

645. Dynamic interception of requests and responses to transform the


information is done by ____

a. Servlet filter
b. Servlet config
c. Servlet container
d. Servlet context

646. The life cycle of a servlet is managed by ________

a. http and https


b. servlet context
c. servlet itself
d. servlet container

647. which method take a string not a URL?

a. sendRedirect
b. forward
c. both
d. none
648. which method shows the client what server is receiving?

a. doGet
b. doOption
c. doTrace
d. doPost

649. What type of servlets use these methods doGet(), doPost(), doHead(),
doDelete(), doTrace()?

a. Generic servlets
b. Httpservlets
c. All of these
d. None of these

650. Which of the following are session tracking techniques?

a. URl rewriting, using sessionobject, using cookies, using hidden fields


b. URL rewriting, using servlet object, using response object, using
cookies
c. URL rewriting, using session object, using response object, using
hidden field

651. Which methods are used to bind the objects on HttpSession instance and
get the objects?

a. setAttribute
b. getAttribute
c. both a & b
d. none of these

652. sessions is a part of the session tracking and it is for maintaining the client
state at server side.
a. True
b. False

653. Which cookies it is valid for single session only and it is removed each
time when the user closes the browser?

a. Persistent cookies
b. Non-persistent cookies
c. All of these
d. None of these

654. Which method in session tracking is used in a bit of information that is sent
by a web server to a browser and which can later be read back from browser?

a. HttpSession
b. URL rewriting
c. Cookies
d. Hidden form fields

655. How constructor can be used for a servlet?


a) Initialization
b) Constructor function
c) Initialization and Constructor function
d) Setup() method

656. Can servlet class declare constructor with ServletConfig object as an


argument?
a) True
b) False

657. What is the difference between servlets and applets?


i. Servlets execute on Server; Applets execute on browser
ii. Servlets have no GUI; Applet has GUI
iii. Servlets creates static web pages; Applets creates dynamic web pages
iv. Servlets can handle only a single request; Applet can handle multiple
requests
a) i, ii, iii are correct
b) i, ii are correct
c) i, iii are correct
d) i, ii, iii, iv are correct

658. Which of the following code is used to get an attribute in a HTTP Session
object in servlets?
a) session.getAttribute(String name)
b) session.alterAttribute(String name)
c) session.updateAttribute(String name)
d) session.setAttribute(String name)

659. Which method is used to get three-letter abbreviation for locale’s country
in servlets?
a) Request.getISO3Country()
b) Locale.getISO3Country()
c) Response.getISO3Country()
d) Local.retrieveISO3Country()

660. Which of the following code retrieves the body of the request as binary
data?
a) DataInputStream data = new InputStream()
b) DataInputStream data = response.getInputStream()
c) DataInputStream data = request.getInputStream()
d) DataInputStream data = request.fetchInputStream()

661. When destroy() method of a filter is called?


a) The destroy() method is called only once at the end of the life cycle of a
filter
b) The destroy() method is called after the filter has executed doFilter
method
c) The destroy() method is called only once at the begining of the life
cycle of a filter
d) The destroyer() method is called after the filter has executed

662. Which of the following is true about servlets?


a) Servlets execute within the address space of web server
b) Servlets are platform-independent because they are written in java
c) Servlets can use the full functionality of the Java class libraries
d) Servlets execute within the address space of web server, platform
independent and uses the functionality of java class libraries

663. How is the dynamic interception of requests and responses to transform the
information done?
a) servlet container
b) servlet config
c) servlet context
d) servlet filter

664. Which are the session tracking techniques?


i. URL rewriting
ii. Using session object
iii.Using response object
iv. Using hidden fields
v. Using cookies
vi. Using servlet object
a) i, ii, iii, vi
b) i, ii, iv, v
c) i, vi, iii, v
d) i, ii, iii, v

665. In which method of the servlet, connection is created?

Ans- init()

666. A cookie contains _____________

Ans - State information of user like name, address

667. A JSP is transformed into a

Ans - Java servlet

668. An object of Which is created by the web container at time of deploying


the project?

Ans- ServletContext

669. Cookie class consist __________________.

Ans - name and value

670. Cookies sent from ______ to _________

Ans - Server,Client

671. Dynamic interception of requests and responses to transform the


information is done by

Ans - Servlet filter

672. Following method is not valid life cycle method of JSP

Ans - jspStop()

673. The execution of servlet is managed by ______


Ans – Servlet Container such as Tomcat

674. Servlets are platform dependent . It cannot run on different servers.

a. True
b. False

675. Which of the following method used in servlet ?

a. Init()
b. Service()
c. Destroy()
d. All of these

676. Which class is a predefined implementation of servlet interface ?

Ans – GenericServlet

677. Which of the following method handles HTTP GET request ?

a. doGET
b. doPUT
c. doPOST
d. doDELETE

678. Which of the following method handles HTTP PUT request ?

a. doGET
b. doPUT
c. doPOST
d. doDELETE

679. Which of the following method handles HTTP POST request ?

a. doGET
b. doPUT
c. doPOST
d. doDELETE

680. Which of the following method handles the DELETE request ?

a. doGET
b. doPUT
c. doPOST
d. doDELETE

681. Which of the following exceptions are thrown to solve the servlet problem
?

a. ServletException
b. IOException
c. Both a & b
d. None of these

682. The servletRequest and ServletResponse are defined in which package ?

a. Javax.servlet
b. Java.http
c. Java.container
d. None of these

683. In servlet ___________ method is used to obtain the output stream.

Ans – getWriter()

684. Which interface defines all the lifecycle methods ?

a. Servlet
b. ServletConfig
c. ServletContext
d. ServletRequest
685. Which interface is used to obtain the initialization parameters ?

a. Servlet
b. ServletConfig
c. ServletContext
d. ServletRequest

686. Which interface is used to read the data from the client request ?

a. Servlet
b. ServletConfig
c. ServletContext
d. ServletRequest

687. In servlet, which method is used to obtain the description of the servlet ?

a. String getServletInfo()
b. getServletConfig()
c. ServletDesc()
d. None of these

688. In servlet which method returns the names of the initialization parameters ?

Ans – Enumeration getInitParameterNames()

689. Which method is used to return the port number of the server ?

a. Int getServerPort()
b. Int getServerInfor()
c. Both can be correct
d. None of these

690. In servlet which method is used to read the binary data from the request ?

Ans –getInputStream()
691. How can we get context init parameter and run some code before rest
of the application can service a client?

Ans - ServletContextListener

692. How does tomcat executes a JSP?

Ans - By one of Tomcat's thread

693. Identify correct syntax of service() method of servlet class

Ans - void service(ServletRequest req, ServletResponse res)

694. In Http request method which is non-idempotent?

a. GET method
b. POST method
c. Both a & b
d. None of these

695. The doGet() Extracts values of the parameter type and number by using
___________

Ans - request.getParameter()

696. What programming language(s) or scripting language(s) does Java Server


Pages (JSP) support?

Ans – Java only

697. Where the session data will store ?

Ans - Session objects.

698. Which interface define a getSession() method?

a. HTTP Service
b. HTTPServletRequest
c. Both a & b
d. None of these

699. Which life cycle method is used to process a client's request?

a. Start()
b. Service()
c. Both a & b
d. None of these

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

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

You might also like