Professional Documents
Culture Documents
x MCQ
Book
a Advance
Java
m
2.0
SUTRA
UR ENGINEERING FRIEND
A dvance Java
programming
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.
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.
a. Window
b. Container
c. Panel
d. Frame
a. 7
b. 6
c. 5
d. 8
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
a. setText()
b. getText()
c. addText()
d. all of these
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
a. HTML document
b. Word document
c. Gif file
d. Rtf file
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
a. Display()
b. Paint()
c. displayApplet()
d. show()
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
a. Draw()
b. Update()
c. Show()
d. Paint()
a. Start()
b. Stop()
c. Init()
d. Destroy()
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()
a. Disappear()
b. Delete()
c. Remove()
d. Hide()
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
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
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
a. Flow layout
b. Border layout
c. Grid layout
d. All of these
a. Card layout
b. Gridbag layout
c. Frame
d. Border layout
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
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
Ans - _____________________________________________________
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.
Ans: True
a)Window Open
b)Window Close
c)WindowActivated,Deactivated
d)All of these
Ans:Boolean
57. Find out the error in following code and rewrite the corred code
importjava.awt.*;
framedemofr=new frameDemo();
fr.setSize(400,500);
fr.setVisible(true);
fr.setLayout(new FlowLayout());
Ans:
importjava.awt.*;
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
a)Button(String s)
c)both a and b
d)none of these
a)3
b)4
c)7
d)1
61. Find out the error in following program and rewrite the code
importjava.awt.*;
{
frDemofr=new frDemo();
fr.setSize(400,500);
fr.setVisible(true);
fr.setLayout(new FlowLayout());
add(btn1);
Ans: CheckboxGroup
Ans:java.awt
66. How can we use the drawString method in Awt Write down the correct
Syantax.
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.
a) FlowLayout.Left
b) LEFT.FLOWLAYOUT
c) FlowLayout.LEFT
d) none of these
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)
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
a) Horizontal Layout
b) Flow Layout
c) Grid Layout
d) GridBag Layout
a) Horizontal Layout
b) Grid Layout
c) Tabular Layout
d) GridBag Layout
79. No. of parameters is passed to GridLayout manager is ______
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
83. In card layout which method is used to add the cards on the panel ?
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 ?
86. In card layout which method is used to flip to the specified card with the
given 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 ?
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
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
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
a) resizing corners
b) borders
c) Title bars
d) all of these
a) text field
b) a picture
c) window
d) panel
a) setLayout(new FlowLayout())
b) setLayout(new GridbagLayout())
c) setLayout(new BorderLayout(3,4))
d) none of these
a) Card Layout
b) Border Layout
c) Flow Layout
d) GridBag Layout
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 ?
a) fr.addMenu(menubar)
b) fr.setMenuBar(mbar);
c) both a & b
d) none of these
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 ?
107. In which type of dialog box user have to close it first in order to continue
using the application ?
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 – grouping
111. In Graphics class Which method is used to set the graphics currentcolor to
the specified color?
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) Parent class
b) Sub class
c) Abstract class
d) Virtual class
121. Pluggable look and feel and lightweight components are the features
supported by ________
a. Swing
b. AWT
c. Core java
d. None of these
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
a. AbstractButton
b. JToggleButton
c. JComponent
d. None of these
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
a. Glsass
b. Content
c. Container
d. All of the above
a. Setimg
b. setIcon
c. serLabelIcon
d. none of this
a. JList
b. JComboBox
c. JLabel
d. All of the above
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
1. canvas is a component
2. scrollpane is a container
a. True
b. False
a. Button
b. Textfield
c. Label
d. List
a. Flowlayout
b. Gridlayout
c. Border layout
d. Gridbag layout
a. True
b. False
a. Model
b. View
c. Controller
d. None of these
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
a. Display()
b. Paint()
c. displayApplet()
d. PrintApplet()
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 – Japplet
a. ImageInsert Class
b. ImageIcon class
c. PutImage class
d. None of these
Ans – 5 pixels
a. Table
b. JTable
c. YTable
d. All of these
Ans – Applet
a. AbstractButton
b. RadioButton
c. CheckBoxItem
d. None of these
a. Java.awt
b. Java.swing
c. Javax.swing
d. None of these
a. Java.awt
b. Java.swing
c. Javax.swing
d. None of these
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
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
Ans – Swing
Ans – Jcomponent
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
a. JCheckBox
b. JToggleButton
c. Both a & b
d. None of these
a. 3
b. 1
c. 2
d. 4
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
a) RadionButton
b) Checkbox
c) CheckboxGoup
d) All of these
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
a) JFrame
b) JTree
c) JComboBox
d) JTable
a) Label , TextField
b) Label , Checkbox
c) Both a & b
d) None of these
Ans – JcomboBox
188. Which is default layout Manager for Japplet?
a) FlowLayout
b) BorderLayout
c) GridLayout
d) CardLayout
a) addTab
b) insertTab
c) putTab
d) none of these
a) setDefaultCloseOperation()
b) setCloseOperation()
c) closeFrame()
d) none of these
a) JTree
b) JComboBox
c) iframe
d) JTable
a) JMenuBar
b) Canvas
c) JCheckBox
d) JTree
193. Which of the following is not true about swing components ?
a) JToggleButton
b) JCheckBox
c) JAbstractButton
d) JRadioButton
a) DefaultMutableTreeNode
b) AddTreeNode
c) InsertTreeNode
d) All of these
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 – Boolean
201. Which method is used to set the value of the progress bar ?
202. In progress bar which method is useful in displaying the data after periodic
interval ?
Ans – Thread.sleep(1000);
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
222. Which of these packages contains all the event handling interfaces?
a. Java.lang
b. Java.awt
c. Java.awt.event
d. Java.event
a. Same class
b. Other class
c. Anonymous class
d. All of these
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
a. Componentlistener
b. Containerlistener
c. Actionlistener
d. Inputlistener
a) Componentlistener
b) Containerlistener
c) Actionlistener
d) Inputlistener
a. Actionevent
b. Componentevent
c. adjustmentEvent
d. WindowEvent
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()
a. ComponentListener
b. ContainerListener
c. ActionListener
d. ItemListener
a. keyPressed()
b. Keyreleased()
c. KeyTyped()
d. KeyEntererd()
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
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()
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()
a. ComponentEvent
b. ContainerEvent
c. ItemEvent
d. InputEvent
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()
a. getX()
b. getXCoordinate()
c. getCoordinateX()
d. getPointX()
a. WindowEvent
b. ComponentEvent
c. ItemEvent
d. InputEvent
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()
a. TextEvent Class
b. MouseEvent Class
c. WIndowEvent Class
d. KeyEvent Class
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. 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
Ans - java.Awt.event
Ans - ___________________________
261. which one of the following methods belongs to event object class
a)getHost()
b)getSource()
c)toString()
d)Both b and c
Ans - getId()
268. which object is generated wnen component receive keyboard focus input
Ans - getActionCommand
271. which method returns the time at which the event occurs
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()
CTRL-MASK
SHIFT-MASK
META-MASK
ALT-MASK
Ans - key-RELEASED
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()
Ans - getClickedCount()
`Ans - TextEventClass()
286. which window event constructor construct a window object with the
specified previous and new windowState
Ans - WindowEvent(WindowSource,intid,intoldState,intnewState)
Ans - getOldState()
289. which class implements an interface with the set of dummy code
Ans - AdapterClass()
Ans – ActionListener
Ans – java.util
Ans – FocusEvent
293. Which method returns the value which indicates the type of key being
pressed at the time of event ?
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 – addKeyListener()
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
a. getSource()
b. toString()
c. both a & b
d. none of these
a. gains
b. loses
c. both a & b
d. none of these
Ans – WindowEvent
Ans – AWTEvent
Ans – ActionListener
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
Ans - TEXT_VALUE_CHANGED
a. Event Listening
b. MVC
c. Applet
d. None of these
Ans - MOUSE_WHEELMOVE
314. The MouseListener's _______________ method is called after mouse
button is released
315. The signature for the registration method for an ActionEvent should be
316. Till now two models have been introduced in java for:
318. What kind of event is fired when the user selects an item from a menu?
a. Button
b. List
c. MenuItem
d. All of these
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()
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.*;
MClick(){
this.addMouseListener(this);
{
System.out.println(e.getWhen());
}}
Ans - Error not override MouseListener methods ,class name not found
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
Button b1;
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));
}}}
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.*;
private Choice c;
c= new Choice();
c.addItem("First");
c.addItem("Second");
c.addItem("Third");
c.addItemListener(this);
this.add(c); }
public void ____________(ItemEvent ev)
{ state = "Selected";
}
System.out.println("ChoiceDemo:" + ev.getItem() +" " +state);
}}
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.*;
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();
setBackground(c)
}}
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.*;
add(vertSB);
add(horzSB);
vertSB.addAdjustmentListener(this);
horzSB.addAdjustmentListener(this);
addMouseMotionListener(this); }
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)
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.*;
os.add("Windows XP");
os.add("Windows Vista");
os.add("Solaris");
os.add("Mac OS");
browser.add("Internet Explorer");
browser.add("Firefox");
browser.add("Opera");
browser.select(1);
// add lists to
window add(os);
add(browser);
os.addActionListener(this);
browser.addActionListener(this);
{ repaint();
} // Display
current selections. public void paint(Graphics g)
{ int idx[];
idx = os.getSelectedIndexes();
msg += browser.getSelectedItem();
g.drawString(msg, 6, 140); } }
335. For the following code select the method that can be used to handle event.
import java.applet.*;
import java.awt.*;
t1 =new TextField(10);
t1.addTextListener(this); }
public void ______________________________
{ msg = t1.getText();
repaint(); }
{ 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.*;
t1=new TextField(10);
t2=new TextField(10);
t3=new TextField(10);
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);
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.*;
add(yes);
add(no);
add(maybe);
yes.addActionListener(this);
no.addActionListener(this);
maybe.addActionListener(this); }
public
void ------------------(ActionEvent ae)
{
msg = "You pressed Yes.";
else if(str.equals("No"))
} else
{ msg =
"You pressed Undecided.";
} repaint();
{ g.drawString(msg, 6,
100); } }
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.*;
int x=10,y=20;
addKeyListener(this);
requestFocus(); }
{ showStatus("key down"); }
(KeyEvent ke)
{ showStatus("Key Up"); }
{ msg+=ke.getKeyChar();
repaint(); }
import java.awt.*;
importjava.applet.*;
{ m1=new Checkbox("A");
m2=new Checkbox("B");
m3=new Checkbox("C");
add(m1);
add(m2);
add(m3);
m1.addItemListener(this);
m2.addItemListener(this); }
if(ie.getSource()==m2)
setBackground(Color.green); } }
import java.awt.* ;
import java.applet.*;
{ 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=
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());
}}
a. Keytyped()
b. KeyPressed()
c. KeyReleased()
d. keyDragged()
351. Which package contains the classes and interfaces required for Java
networking?
a. Java.io
b. Java.util
c. Java.net
d. Java.awt
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
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
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
a. IP address of server
b. Port Number
c. Both a and b
d. None of these
a. True
b. False
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
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
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
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
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
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
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
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()
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()
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
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
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
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
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
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
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. }
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. }
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()
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()
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
Ans – 110
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
a. Class A
b. Class B
c. Class C
d. Class D
a. 1 to 126
b. 127 to 191
c. 192 t0 223
d. 224 to 239
a. 1 to 126
b. 127 to 191
c. 192 t0 223
d. 224 to 239
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
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
a. SocketImpFactory
b. ContentHandlerFactory
c. URLStreamHandlerFactory
d. None of these
a. getLocalHost()
b. getByName()
c. getAllByName()
d. getHostName()
447. What kind of exception main function throws while using InetAddress
class ?
Ans – UnknownHostException
a. TCP
b. UDP
c. IP
d. Both b & c
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
Ans – 43.
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
a. Single
b. Two
c. Multiple
d. None of these
Ans – 32 bits
Ans - java.security
Ans – Email
470. The server listens for a connection request from a client using the
following statement:
Ans - Socket s = ServerSocket.accept()
Ans – DatagramSocket
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
Ans – InetAddress
Ans – HTTP
Ans – permission
Ans – stateless
485. Select the proper method to retrieve the host name of local machine
Ans – http
class InetAddressTest {
}}
491. Which datagram method returns the byte array of data contained in
the datagram?
Ans - getCodeBase().getHost()
Ans - a concurrent
494. A technique that creates a subletting effect; one server answers ARP
requests for multiple hosts?