AJAVA_MCQ
AJAVA_MCQ
5171
e-Exam Manage Questions for Advanced Java Programming (17625) for topic 1 Go Back to Subjects
1 JPanel and Applet use ___________________ as their default layout 1 N R 1 Flow Layout
2 W hich are various AW T controls from follow ing? 1 N R 1 Labels, Push buttons, Check boxes, Choice lists.
3 W hich of the follow ing component class cannot be add on applet 1 N R 1 Menu
4 A checkbox is a control that consists of a ____________ 1 N R 1 Combination of a small box and a Label
5 A Frame's _______________ designates the area of the frame excluding the title,menu 1 N R 1 ContentPane
10 A superclass of Textfield and TextArea classes that is used to create single-line , multili 1 N R 1 Textcomponent
15 All Component on Container can be removed by calling follow ing method 1 N R 1 removeAll()
23 AW T is used for creating a GUI in Java. AW T stands for 1 N R 1 Abstract W indow Toolkit
26 A____________ is component that presents a rectangular area in w hich a component 1 N R 1 Scroll Pane
33 By w hich method You can set or change the text in a Label? 1 N R 1 setText()
48 Double-buffering built in, tool tips, dockable tool bars, keyboard accelerators, custom cu1 N R 1 Sw ing
54 Flow Layout does not support this value of alignment… 1 N R 1 Flow Layout.BASELINE
57 for using Sw ing control one must import______________________________pacakge 1 N R 1 import javax.sw ing.*
61 How can the Checkbox class be used to create a radio button in AW T? 1 N R 1 By associating Checkbox objects w ith a CheckboxGroup
62 How do you change the current layout managers for a container? 1 N R 1 Use the setLayout() method
65 How w ould you set the color of a graphics context called g to cyan? 1 N R 1 g.setColor(Color.cyan);
66 Identify the correct constructor of Font class? 1 N R 1 Font( String name, int fontstyle,int pointsize)
71 In Flow Layout manager the default space betw een each component is 1 N R 1 5 Pixel
72 In Graphics class W hich method is used to set the graphics current color to the specifie 1 N R 1 public abstract void setColor(Color c)
73 In how many w ays w e can define the scrollbar? 1 N R 1 All of the above
76 In Sw ing ____________is a component that displays row s and columns of data. 1 N R 1 table
81 Java supports input/output of data through the classes included in the 1 N R 1 Java.io
_______ package:
86 List can be created for multiple selection by using follow ing constructor. 1 N R 1 List(int num,boolean multiselect)
91 Name the class used to represent a GUI application w indow , w hich is optionally resiza 1 N R 1 Frame
101 Select the proper constructor of FileDialog 1 N R 1 FileDialog(Frame parent, String boxName)
102 Select the proper syntax to addcomponent in an applet 1 N R 1 Component add(Component comoObj)
105 State true of false i) AW T is an extended version of sw ing ii) Paint( ) of 1 N R 1 i-false, ii-false
Applet class cannot be overridden
111 The AW T container is an instance of the ___________ class w hich holds various comp1 N R 1 Container
112 The CardLayout class defines the follow ing constructors: 1 N R 1 CardLayout() // First Cardlayout(int hor, int ver) //second
113 The CardLayout class manages the components in such a manner that 1 N R 1 Only one
117 The default layout manager for the content pane of a sw ing based applet is 1 N R 1 Border-Layout
118 The follow ing specifies the advantages of It is lightw eight. It supports pluggable look a1 N R 1 Sw ing
120 The method setLabel can be used w ith w hat type of Object ? 1 N R 1 TextField.
121 The method ____gets the text of the button jtb is 1 N R 1 jtb.getText( )
122 the method _________ places a menu mu into a menu bar mb. 1 N R 1 mb.add(mu)
123 The method ______________ sets the foreground color to yellow in 1 N R 1 f.setForeground (Color.YELLOW )
Jframe
124 The method _______________creates a IconImage for file c:\image\us.gif 1 N R 1 new ImageIcon("c:\image\us.gif&q
125 The method ____________________gets the text (or caption) of the label jlbl 1 N R 1 jlbl.getText()
126 The setBackground() method is part of the follow ing class in java.aw t package: 1 N R 1 Component
127 The string parameter to the JButton constructor 1 N R 1 tells w hat text w ill appear on the button
128 The Sw ing component classes that are used in encapsulate a mutually exclusive set of 1 N R 1 ButtonGroup
129 The syntax for draw Rect() method is 1 N R 1 draw Rect(int top, int left, int w idth, int height)
132 The various controls supported by sw ing are: 1 N R 1 all of the above
133 The __________ arranges components in row s and columns and makes all component 1 N R 1 GridLayout manager
137 These four methods commonly used in? 1)public void add(Component c) 2)public void s 1 N R 1 Component class
138 To create w indow w ith title bar w hich of the follow ing class is used? 1 N R 1 Frame
140 To display text on the applet ______ method is used. 1 N R 1 draw String()
141 To draw a line in applet, w e use follow ing method 1 N R 1 draw Line()
144 To set title to the frame w indow ___________ method is used. 1 N R 1 void setTitle(String str)
146 W hat are controls or components? 1 N R 1 Controls or components allow users to interact w ith applica
148 W hat Are The Types of Dialogbox ? 1 N R 1 modal and Modeless Dialogbox
149 W hat are the variables defined in Dimension 1 N R 1 height and w idth
150 W hat Checkbox method allow s you to tell if a Checkbox is checked? 1 N R 1 getState()
151 W hat does the follow ing line of code do? TextField text = new 1 N R 1 Creates text object that can hold 10 colu
TextField(10);
153 W hat is default alignment of components using Flow Layout 1 N R 1 Flow Layout.CENTER
154 w hat is default layout manager for panels and applets 1 N R 1 Flow Layout
156 W hat is the difference betw een a TextArea and a TextField? 1 N R 1 A TextArea can handle multiple lines of text
157 W hat is the minimum and maximum of JProgressBar 1 N R 1 minimum -0 Maximum -100
158 W hat is the use of follow ing method in JDialog? Container getContentPane() 1 N R 1 This method returns,a Content Pane for t
160 W hat is use of second parameter in given constructor Label(String,int) 1 N R 1 sepcifies the alignment of text in label in terms of pixel
161 w hat layout manager should you use so that every component occupies the same size i 1 N R 1 GridLayout
162 W hat letter precedes Sw ing component names that have a corresponding AW T compo1 N R 1 J
163 W hat method is used to prevent a user from changing the size of a 1 N R 1 setResizable( false )
Frame() object?
164 W hat methods are used to get and set the text label displayed by a 1 N R 1 getLabel( ) and setLabel( )
Button object?
166 W hen layout manager is disabled , w hich method is used to determine the shape and p1 N R 1 setBounds
167 W hen w e invoke repaint() for a java.aw t.Component object, the AW T 1 N R 1 update()
invokes the method:
168 w hich method is used to set the visibility of the frame? 1 N R 1 1.setVisible(true)
169 w hich package w e need to import w hile w ritng sw ing JRadioButton class 1 N R 1 import javax.sw ing.*;
170 W hich abstract class is the super class of all menu related classes. 1 N R 1 MenuComponent
172 W hich are the Alignment Constant of Label ? 1 N R 1 All The Above
173 W hich are the subclasses of the container class? 1 N R 1 W indow s,Panel,ScrollPane.
176 W hich class can be used to represent a checkbox w ith a textual label that can appear i 1 N R 1 CheckboxMenuItem
177 W hich class creates a node in Jtree? 1 N R 1 DefaultMutableTreeNode
179 W hich class encapsulates a blank w indow upon w hich w e can draw ? 1 N R 1 Canvas
180 W hich class is on the top of the AW T event hierarchy? 1 N R 1 java.aw t.AW TEvent
181 W hich class is used to create a pop-up list of items from w hich the user may choose? 1 N R 1 Choice
183 W hich class is used to represent a single line textbox w ith passw ord character facility?1 N R 1 TextField
184 W hich class provides many methods for graphics programming? 1 N R 1 java.aw t.Graphics
186 W hich component displays information in hierarchical manner w ith parent-child relatio1 N R 1 JTree
187 W hich component in sw ing represents data in row s and columns? 1 N R 1 JTable
189 W hich components are needed to get follow ing show n output 1 Y1 R 1 Label,TextField
Figure:-
190 w hich Container use a Border Layout as their default layout? 1 N R 1 All of the above
193 W hich h costructor creates a TextArea w ith 10 row s and 20 columns ? 1 N R 1 new TextArea(10 , 20 )
194 W hich is Controll in sw ing a combination of a text field and a dropdow n list 1 N R 1 JComboBox
195 W hich is correct method for adding button component into North region of border layou 1 N R 1 add(b1, BorderLayout.NORTH)
199 W hich is the correct constructor for JProgressBar 1 N R 1 All of the above
200 W hich is the correct constructor of GridLayout 1 N R 1 GridLayout(int numrow s, int numcols)
202 W hich is the method is used to count the number of items in the list 1 N R 1 getItemCount()
204 W hich is various methods of TextField control from follow ing? 1 N R 1 getText(),setText(),setEchoChar()
205 W hich layout arranges the components as a deck of cards such that only one compone 1 N R 1 CardLayout
206 W hich layout should you use to organize the components of a container in a tabular for1 N R 1 GridLayout
211 W hich method is used to change size and position of Components? 1 N R 1 void setBounds(int x,int y,int w idth,int height)
212 W hich method is used to change the name of a menu item 1 N R 1 void setLabel(String new Name)
216 W hich method is used to set the dimensions of the w indow . 1 N R 1 void setSize(int new W idth, int new Height)
217 W hich method is used to set the layout of the Applet? 1 N R 1 setLayout();
218 W hich method sets the size and position of a component 1 N R 1 setBounds()
220 W hich object can be constructed to show and select any number of choices in the visib 1 N R 1 List
221 W hich of the follow ing applet tags is legal to embed an applet class named Test into a 1 N R 1 < applet code = Test.class w idth = 20
222 W hich of the follow ing are not sw ing componant? 1 N R 1 both a & b
223 W hich of the follow ing are passed as an argument to the paint( ) 1 N R 1 A Graphics object
method?
224 W hich of the follow ing are subclasses of Container Class? 1 N R 1 ScrollPane,Vector,String
225 W hich of the follow ing are subclasses of java.aw t.Component? 1 N R 1 Container
226 W hich of the follow ing are true? 1 N R 1 Panel extends Container.
227 w hich of the follow ing class is Derived from Container Class? 1 N R 1 Panel
228 W hich of the follow ing class act as a super class in class hierachy? 1 N R 1 Component
229 W hich of the follow ing components allow multiple selections? 1 N R 1 List
230 W hich of the follow ing components does not have visible borders? 1 N R 1 Panel
232 W hich of the follow ing controls does not support interaction w ith user? 1 N R 1 Label
233 W hich of the follow ing creates a List w ith 5 visible items and multiple selection enable1 N R 1 new List(5, true)
239 W hich of the follow ing is not true about Dialog Boxes? 1 N R 1 Dialog boxes contains menu bars.
240 W hich of the follow ing is not true about Sw ing Components? 1 N R 1 Heavy w eight components
241 W hich of the follow ing is not valid alignment constant for Label? 1 N R 1 MIDDLE
242 W hich of the follow ing is not valid constructor for JCheckBox? 1 N R 1 JCheckBox(String text, boolean selected, CheckboxGroup gr
243 W hich of the follow ing is not valid style constant for Font? 1 N R 1 NORMAL
245 W hich of the follow ing is the immidiate superclass of the 1 N R 1 Object
MenuComponent class?
246 W hich of the follow ing is true about AW T and Sw ing Component? 1 N R 1 AW T Components create a process w here as Sw ing Compo
247 W hich of the follow ing is used to interpret and execute Java Applet 1 N R 1 Appletview er
Classes hosted by HTML ?
248 W hich of the follow ing layout managers need to create a Panel? 1 N R 1 CardLayout
250 W hich of the follow ing may contain a menu bar? 1 N R 1 frame
251 W hich of the follow ing method is use to add a button “b” to the south of the applet usi 1 N R 1 add(b,BorderLayout.SOUTH);
252 W hich of the follow ing method is used to change the Label caption? 1 N R 1 setText(String s)
253 W hich of the follow ing method is used to retrive icon of JButton 1 N R 1 Icon getIcon()
254 W hich of the follow ing methods are invoked by the AW T to support paint and repaint o1 N R 1 repaint( )
255 W hich of the follow ing methods can be used to change the size of a java.aw t.Compone1 N R 1 setSize()
256 W hich of the follow ing methods can be used to remove java.aw t component object fro1 N R 1 remove()
257 W hich of the follow ing statements about GUI components is w rong ? 1 N R 1 The AW T classes are deprecated
258 W hich of the follow ing statements is for placing the frames upper left corner to (200,11 N R 1 frame.setLocation(200,100)
259 W hich of the follow ing sw ing components donot have an Icon parameter in its constru1 N R 1 JTextField
260 W hich of the follw ing is constructor of Jtable? 1 N R 1 JTable(Object data[][], Object colHeads[])
261 W hich of the method can be used to output a string in an applet? 1 N R 1 draw String()
262 W hich of the method Choice class returns a string containing the name of the item. 1 N R 1 String getSelectedItem()
264 W hich Of these Compenent can be added to frame? 1 N R 1 All of the Above
267 W hich of these methods can be used to obtain the reference to the container that gener1 N R 1 getContainer()
268 W hich of these methods can be used to output a string in an applet? 1 N R 1 draw String()
270 W hich of these methods cannot be called on TextArea? 1 N R 1 String getItem(int index)
271 W hich of these methods is used to setting the w inw ods dimension 1 N R 1 void setSize(Dimension new _size)
273 W hich of these package is used for graphical user interface ? 1 N R 1 java.aw t
274 W hich of these packages contains all the classes and methods required for event handli1 N R 1 java.aw t.event
275 W hich one is the valid constructor of JCheckBox. 1 N R 1 JCheckBox(Sting s, Icon I, Boolean State)
276 W hich one method is used to set the visibility of the frame? 1 N R 1 setVisible(true)
277 W hich package use for import the sw ing components? 1 N R 1 javax.sw ing.*;
278 W hich TextComponent method is used to set a TextComponent to the read-only state?1 N R 1 setEditable
279 w hich type of button is belongs to a group such that only one button in the group may 1 N R 1 CheckboxGroup
280 W hich of these events is generated w hen a button is pressed? 1 N R 1 B.) ActionEvent
281 W hy are sw ing component termed as lightw eight ? 1 N R 1 they do not depend on native platform
282 W hy w e use Applet? 1 N R 1 Option A) and B) FROM this
283 W indow is super class of ____________ 1 N R 1 Frame
284 W indow , frame and dialog use ________ as their default layout. 1 N R 1 BorderLayout
286 You Can set the alignment of the string w ithin the label by calling 1 N R 1 setAlignment()
_______________________
287 You w ant to construct a text area that is 80 character-w idths w ide and 1 N R 1 new TextArea( 10,80)
10 character-heights tall. W hat code do you use ?
290 _________is the Superclass of TextField and the TextArea classes: 1 N R 1 TextComponent
291 _________Positions are the components into five regions east, w est, north , south, cen1 N R 1 BorderLayout
292 __________ is a Sw ing class that allow s the user to enter a single line of text. 1 N R 1 JTextField
293 __________ is a Sw ing layout manager that arranges components in a row or a colum 1 N R 1 GridLayout
295 __________ method is used to add the menubar on frame w indow . 1 N R 1 setMenuBar()
298 ____________ class is used to create set of mutually exclusive checkboxes. 1 N R 1 CheckboxGroup
305 ___________________ AW T component is used to create popup list of string items from
1 N R 1 Choice
309 _____________________ is the default layout manager for APPLET. 1 N R 1 Flow Layout
311 ________________________ Constructs a new scroll bar w ith the specified orientatio 1 N R 1 Scrollbar(int)
312 ___________________________ component may have different size row s may have d1 N R 1 GridLayout
313 ___________________________ method is used to append the string str to end of the 1 N R 1 append ()
316 ………………………. method is used to lock text box components. 1 N R 1 setEditable(boolean flag)
318 Most Sw ing components are __________ components because they are rendered and 1 N R 1 lightw eight
319 Figure:- 1 Y1 A 2 public class HelloSw ing { public HelloSw
Name"); JLabel l2 = new JLabel(&q
JTextField(); JTextField t2 = new JTextFi
JButton("Submit"); JBut
320 The Jtable used to display data in form of? 1 N U 2 JTable object displays row s and columns of data.
322 //Find out the error. import javax.sw ing.JFrame; import javax.sw ing.JTree; import 1 N A 2 Error in statement in w hich JTree is crea
javax.sw ing.Sw ingUtilities; import javax.sw ing.tree.DefaultMutableTreeNode; public
class TreeExample extends JApplet { JTree tree; public void init() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
DefaultMutableTreeNode vegetableNode = new
DefaultMutableTreeNode("Vegetables"); DefaultMutableTreeNode fruitNode = new
DefaultMutableTreeNode("Fruits"); root.add(vegetableNode); root.add(fruitNode); tree
= new JTree(); add(tree); } } /*<applet code=”TreeExample” w idth=300
height=300>
</applet>*/
323 //Identify the correct output for the given code. import java.aw t.*; import java.applet.*1 Y2 A 2
//Identify the error import java.aw t.*; import javax.sw ing.*; /*<applet code="JTableD
324 BorderLayout()); final String[] colHeads = { "Roll No", "Name", "Branch" 1 N A 2 Error in statement in w hich JTable is cre
}; final Object[][] data = { { “11”,"Mayur", “CO” }, { “22”,"Ritesh", “IF”
}, { "33", “Rahul”, “CM” } }; JTable table = new JTable(data); int v =
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h =
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPane jsp = new
JScrollPane(table, v, h); contentPane.add(jsp, BorderLayout.CENTER); } }
325 //Select the correct option for the follow ing code. import java.aw t.*; import 1 N A 2 background w ith combination of r,g an
java.applet.*; import java.aw t.event.*; /*<applet code=scrolldemo w idth=200
height=300> </applet>*/ public class scrolldemo extends Applet implements
AdjustmentListener { Scrollbar s1,s2,s3; TextField r,g,b; Color c; public void init() {
s1=new Scrollbar(Scrollbar.HORIZONTAL,0,0,0,256); s2=new
Scrollbar(Scrollbar.HORIZONTAL,0,0,0,256); s3=new
Scrollbar(Scrollbar.HORIZONTAL,0,0,0,256); r=new TextField(5); g=new TextField(5);
b=new TextField(5); add(s1); add(r); add(s2); add(g); add(s3); add(b);
s1.addAdjustmentListener(this); s2.addAdjustmentListener(this);
s3.addAdjustmentListener(this); } public void
adjustmentValueChanged(AdjustmentEvent ae) {
r.setText(Integer.toString(s1.getValue()));
g.setText(Integer.toString(s2.getValue()));
b.setText(Integer.toString(s3.getValue())); c=new
Color(s1.getValue(),s2.getValue(),s3.getValue()); setBackground(c); }
}
326 1. W hich components are used in the follow ing output? Figure:- 1 Y1 U 2 Label, TextField, Button
327 1.import java.aw t.*; 2.import java.applet.*; 3.public class sample3 extends Applet 1 N A 2 Line number 10
4.{ 5.public void init() 6.{ 7.Choice country=new Choice(); 8.country.add("india");
9.country.add("america");
10.country.add("shrilanka",true); 11.country.add("japan");
12.add(country); 13.} 14.}
1.public class sample5 extends Applet 2.{ 3.public void init() 4.{
5.//CheckboxGroup cg=new CheckboxGroup(); 6.Checkbox c1,c2,c3,c4;
329 1.W hich is missing statement in follow ing program? import java.aw t.*; import java.ap1 N A 2 setLayout(new BorderLayout()
330 2. Consider the follow ing program. Find w hich statement contains 1 N A 2 A. Error in statement in w hich JTable is
error.importjava.aw t.*; import javax.sw ing.*; /* <applet code="JTableDemo" w
idth=400 height=200> </applet> */ public class JTableDemo extends JApplet {
public void init() { Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout()); final Object[][] data = { { "Ramesh",
"111", "50000"
}, 15 { "Sagar", "222", "52000" }, { "Virag", "333", "40000" }, { "Amit", "444",
"62000" }, { "Anil", "555", "60000" }, }; JTable table = new JTable(data,colHeads);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h =
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPanejsp = new
JScrollPane(table, v, h); contentPane.add(jsp, BorderLayout.CENTER); } }
331 2. W hat is the purpose of JTable? 1 N U 2 JTable object displays row s and columns of data.
332 2.W hat should be w ritten in blank space. import java.aw t.*; import java.aw 1 N A 2 cbg
t.event.*; import java.applet.*; /* <applet code="CBGroup" w idth=250
height=200> </applet> */ public class CBGroup extends Applet { String msg = "";
Checkbox W in98, w inNT; CheckboxGroup cbg; public void init() { cbg = new
CheckboxGroup(); W in98 = new
Checkbox("W indow s 98/XP", , true); w inNT = new Checkbox("W indow s
NT/2000", , false); add(W in98); add(w inNT); W in98.addItemListener(this); w
inNT.addItemListener(this); } }
333 3. Observe the follow ing code and find w hich statement contains error.import java.aw 1 N A 2 C.Error in adding and registering listener
334 3. Select the proper command to run the follow ing code import java.aw t.*; import 1 N A 2 appletview er combodemo11.java
java.aw t.event.*; import javax.sw ing.*; import java.applet.*; /* <applet
code="combodemo11" w idth=300 height=100> </applet> */ public class
combodemo11 extends JApplet
{ public void init() { Container co = getContentPane(); co.setLayout(new Flow
Layout()); JComboBoxjc=new JComboBox(); jc.addItem("cricket");
jc.addItem("football"); jc.addItem("hockey"); jc.addItem("tennis"); co.add(jc); } }
336 A JFrame supports three operations w hen the user closes the w indow . W hich of the ch1 N U 2 LOW ER_ON_CLOSE
337 A menu bar represents 1 N U 2 A list of menus w hich can be added to the top of a top-level
338 A Sw ing component can be view ed based on w hat state it’s in, how it looks, and w hat1 N U 2 Controller
339 A toggle button looks just like a push button, but it acts differently because __________1 N U 2 it has tw o states: enabled and disabled
340 A user w ant’s to create an Applet w ith menubar consisting three menu items and 1 N A 2 . import java.aw t.*; import java.applet.
one checkable menu item select correct coding?
342 An Applet has its Layout Manager set to the default of Flow Layout. W hat code w ould b1 N A 2 setLayout(new GridLayout(2,2));
343 Analyse the follow ing code import javax.sw ing.*; Import javax.sw ing.border.*; Impor 1 N A 2 The program has compile error.
344 Analyse the follow ing code? import javax.sw ing.*; import java.aw t.*; public class Tes 1 N A 2 Four buttons are displayed w ith the sam
345 Arranges the compents as a deck of cards such that only one 1 N U 2 B.CardLayout
Consider follow ing output. Find the missing statement in the follow ing program to get a
Figure:-
369 1 Y1 U 2 mb.add(jmenu);
372 Consider follow ing program and state how meny main menu and sub menu displayed in1 N A 2 3 Main,3 Sub menu
Consider follow ing program.Select the missing statement from options. import javax.sw
373 w idth=200 height=200> </applet>*/ public class TableDemo extends JApplet { 1 N A 2 Table table = new JTable(data,col);
public void init() { Container cp=getContentPane(); cp.setLayout(new
BorderLayout()); String data[][] =
{{"Neeta","CO","A"},{"Mahesh","CE","B"},{"Akanksha","IF","C"},
{"Neha","ME","A"}}; String col[] = {"Name","Branch","Grade"}; int
v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int
h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALW AYS; JScrollPane jsp=new
JScrollPane(table,v,h); cp.add(jsp,BorderLayout.CENTER); } }
374 Consider the follow ing program W hat w ill be displayed in the output? import java.aw t1 N A 2 Applet w ithout any controls.
375 Consider the follow ing program W hich statemnet is prepare for blank space import java1 N A 2 add(new Button(""+n));
376 Consider the follow ing program. W hat should be the correction done in the program to 1 N A 2 package not imported correctly
377 Consider the follow ing program. Find the error. import java.aw t.*; import java.applet.*1 N A 2 All of above
Consider the follow ing program. Find w hich missing statement. import java.aw t.*; imp DefaultMutableTreeNode top = new Defa
379 Consider the follow ing program. Find w hich statement contains error. import java.aw t 1 N A 2 Class should not be public.
380 Consider the follow ing program. Find w hich statement contains error. import java.aw t 1 N A 2 No error.
381 Consider the follow ing program. Find w hich statement contains error. import java.aw 1 N A 2 Error in statement in w hich JTable is cre
t.*; import javax.sw ing.*; /* <applet code="JTableDemo" w idth=400 height=200>
</applet> */ public class JTableDemo extends JApplet { public void init() { Container
contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); final
String[] colHeads = { "emp_Name", "emp_id", "emp_salary" }; final Object[][] data
= { { "Ramesh", "111", "50000"
}, { "Sagar", "222", "52000" }, { "Virag", "333", "40000" }, { "Amit", "444", "62000"
}, { "Anil", "555", "60000" }, }; JTable table = new JTable(data); int v =
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h =
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPanejsp = new
JScrollPane(table, v, h); contentPane.add(jsp, BorderLayout.CENTER); } }
382 Consider the follow ing program. Find w hich statement contains error. import java.apple1 N A 2 Error in the statement creating panel obj
Consider the folow ing code.Select the proper scrollbar constant for blank line in code . i
383 </applet> */ public class ScrollDemo extends JApplet { public void init() 1 N U 2 Both I and ii
{ Container cp=getContentPane(); cp.setLayout(new BorderLayout()); JTextArea
ja=new JTextArea(); int v=ScrollPaneConstants.____________________________ ;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALW AYS;
JScrollPane jsp=new JScrollPane(ja,v,h);
cp.add(jsp,BorderLayout.CENTER); } }
384 Debug the follow ing code and find out w hich statement contains error. import java.aw 1 N A 2 statement w here setMenuBar() method
385 Debug the follow ing code and find w hich statement contains error. import javax.sw 1 N A 2 Error in statement to create button group
ing.*; import java.aw t.*; public class JRadioButtonDemo extends JApplet {
JRadioButton r1,r2,r3; Container c; public void init() { c=getContentPane();
c.setLayout(new Flow Layout()); r1=new JRadioButton("Red"); r2=new
JRadioButton("Green"); r3=new JRadioButton("Blue"); JRadioButtonGroup b=new
JRadioButtonGroup (); b.add(r1);b.add(r2);b.add(r3); c.add(r1);c.add(r2);c.add(r3);
} } /*
<applet code=JRadioButtonDemo.class w idth=500 height=500>
</applet>*/
386 Dectate Error in folloing code , Specify line number if any; 1. import java.applet.*; 2. im1 N A 2 Line number 10 and 3
388 Fill in the blanks so that the follow ing draw s a Frame containing "Hello". import 1 N A 2 extends, paint, draw String
java.aw t.*; class HelloFrame ___________ Frame { public void ___________(
Graphics g ) { g.___________("Hello", 10,
50 ); } } public class Tester { public static void main ( String[] args ) { helloFrame
frm = new helloFrame(); frm.setSize( 150, 100 ); frm.setVisible( true ); } }
389 Fill in the blanks so that this program displays a Frame: import java.aw t.*; public 1 N A 2 Frame, setSize, setVisible
class microGUI { public static void main ( String[]
args ) { Frame frm = new ___________(); frm.___________( 150, 100
); frm.___________( true ); } }
Find error from follow ing code import java.aw t.*; import java.aw t.event.*; import
javax.sw ing.*; import javax.sw ing.tree.*; /*
<applet code="JTreeEvents" w idth=400 height=200> </applet> */ public class
JTreeEvents extends JApplet { JTree tree; JTextField jtf; public void init() { // Get
content pane Contain contentPane = getContentPane(); contentPane.setLayout(new
BorderLayout()); DefaultMutableTreeNode top = new
DefaultMutableTreeNode("Options"); DefaultMutableTreeNode a = new
392 Find missing statement from given code: public class ButtonLabelDemo extends 1 Y1 A 2 l1=new Label("one"); l2=new
Applet { Label l1,l2; Button b1; public void init() { ** ** ** Button("OK");
//Adding the controls to the applet add(l1); add(l2); add(b1); } } Figure:-
393 find out missing line in follow ing code. Import java.aw t.*; import java.sw ing.* public 1 N U 2 Container cp=getContentPane()
394 Find out missing statement in follow ing code: import java.aw t.*; import 1 N A 2 add(l1); add(l2);
java.applet.*; /* <applet code=exp4.class w idth=200 height=200>
</applet> */ public class exp4 extends Applet { List l1,l2; public void init() { l1=new
List(4); l2=new List(4,true); l1.add("abc"); l1.add("def"); l1.add("ghi");
l1.add("lmk"); l2.add("1"); l2.add("2"); l2.add("3"); l2.add("4"); } }
395 Find the error in the follow ing code. import java.aw t*; import java.aw t.event.*; impor1 N A 2 A and B
396 Find the error. /*<applet code="MyJTabbedPane" w idth=900 height=900> </applet>* 1 N A 2 b)JTabPane Constructor is incorrect
397 Find the missing statement from the follow ing program. import java.aw t.*; import 1 Y1 U 2 Missing add statement
java.aw t.event.*; import javax.sw ing.*; import java.applet.*; /* <applet
code="ctest" w idth=300 height=100>
</applet> */ public class ctest extends JApplet { public void init() { Container co =
getContentPane(); co.setLayout(new Flow Layout()); JComboBox jc=new
JComboBox(); jc.addItem("cricket"); jc.addItem("football"); jc.addItem("hockey");
jc.addItem("tennis"); } }
Figure:-
398 Find the missing statement in the follow ing code import java.aw t.*; class MenuDemo e1 N A 2 setMenuBar(mb);
399 Find the missing statement. import javax.sw ing.*; class MyFrame extends JFrame { pu 1 N U 2 public static void main(String[] args)
400 find the ouptut of the follow ing : import javax.sw ing.*; class Demo extends JApplet { p1 Y2 A 2 S1Q43O1
401 Follow ing program output display w hich type of layout manager : 1 N A 2 CardLayout
import java.aw t.*; import java.applet.*; import java.aw t.event.*; /*
<applet code=cl.class w idth=200 height=200> </applet> */ public class cl extends
Applet { CardLayout cardLayout; Panel panel; Button button1, button2, button3;
public void init() { panel = new Panel(); add(panel); cardLayout = new
CardLayout(0,0); panel.setLayout(cardLayout); button1 = new Button("Button1");
button2 = new Button("Button2"); button3 = new Button("Button3");
panel.add("Button1", button1); panel.add("Button2", button2); panel.add("Button3",
button3); }
403 For the below code, how is a JTable object created? String[] colHeads 1 N U 2 JTable jt=new JTable(data,colHeads);
= { "Name", "Extension", "ID#" }; Object[][] data = {{ "Gail", "4567", "865" },{
"Ken", "7566", "555" }};
404 From follow ing list W hich is not Sw ing class? 1 N U 2 JImageIcon
405 Give proper command to compile & run follow ing program code? import java.applet.*; i1 N A 2 C:\javac A1.java C:\appletview er A1.jav
406 Given the follow ing code import java.aw t.*; public class SetF extends Frame { public s1 N A 2 s.setBackground(Color.pink);
407 How many components are used for form validation i.e input username and passw ord 1 N U 2 2 Label,1 Button,2 Textfield
408 How many controls are show n on Applet after executing follow ing program import 1 N U 2 3
java.aw t.*; import java.aw t.event.*; import java.applet.*; /* <applet
code="app2.class" height=100 w idth=200>
</applet>*/ public class app2 extends Applet { Checkbox cb1,cb2; TextField tf1;
String str,str1; public void init() { Label c=new Label("COLORS"); cb1=new
Checkbox(); cb2=new Checkbox("W HITE"); tf1=new TextField("ABC"); add(cb1);
add(c); add(tf1); } }
409 How to add image on button 1 N A 2 ImageIcon ii = new ImageIcon(“India.gif”); JButton Jb= new
412 Identify controls used in follow ing output 1 Y1 U 2 TextFiled and Scrollbars
Figure:-
413 Identify default output for given code import java.aw t.event.*; import java.applet.*; 1 Y2 A 2 S1Q45O4
public class Flow LayoutDemo extends Applet implements ItemListener { String msg
= ""; Checkbox W in98, w inNT, solaris, mac; public void init() { setLayout(new Flow
Layout(Flow Layout.LEFT));
W in98 = new Checkbox("W indow s 98/XP", null, true); w inNT = new Checkbox("W
indow s NT/2000"); solaris = new Checkbox("Solaris", null, true); mac = new
Checkbox("MacOS"); add(W in98); add(w inNT); add(solaris); add(mac); W
in98.addItemListener(this); w inNT.addItemListener(this);
solaris.addItemListener(this); mac.addItemListener(this); } public void
itemStateChanged(ItemEvent ie) { repaint(); } public void paint(Graphics g) { msg
= "Current state: "; g.draw String(msg, 6, 80); msg = " W indow s 98/XP: " + W
in98.getState(); g.draw String(msg, 6, 100); msg = " W indow s NT/2000: " + w
inNT.getState(); g.draw String(msg, 6, 120); msg = " Solaris: " + solaris.getState();
g.draw String(msg, 6, 140); msg = " Mac: " + mac.getState(); g.draw String(msg, 6,
160); } }
414 Identify layout used in the output given below . Figure:- 1 Y1 U 2 GridLayout
415 Identify proper syntax from follow ing options of TextArea constructor 1 N U 2 TextArea(int numlines, int numChars)
416 Identify the code for the output given below . Figure:- 1 Y1 A 2 import java.aw t.*;import javax.sw ing.*
JCheckBox cb1,cb2; public void init() { C
c.setLayout(new Flow Layout()); cb1=ne
cb2=new JCheckBox("Blue",
JButton("Submit");b2=new
JButton("Reset");c.add(cb1);
417 Identify the components required to design this applet w indow show n in image? 1 Y1 A 2 Label, Button, TextField, Checkbox, Chec
Figure:-
418 Identify the correct code for follow ing output. Figure:- 1 Y1 A 2 import java.aw t.*; public class MenuDem
new MenuBar(); setMenuBar(mbr); Menu
Menu("Edit"); Menu v =new
MenuItem("New "); Checkbox
CheckboxMenuItem("Open",t
mbr.add(e); mbr.add(v); } public static
MenuDemo(); m.setVisible(true); m.setS
420 If a progam consist of three classes,then after compilation how many class file (s) is ar 1 N U 2 Three
421 If user does not set size of frame then in output size of frame is _____ 1 N U 2 0,0
w idth ______ height
422 import java.aw t.*; class Demo extends Frame { public static void main(String args[]){1 N A 2 using setVisible(false);
423 import java.aw t.*; import java.applet.* /*<applet code="my.class" w idth=300 height1 N A 2 Compilation Error
424 import java.aw t.*; import java.applet.*; /*<applet code="Choice_Demo.class" w idth=1 N A 2 Applet
425 import java.aw t.*; import javax.sw ing.*; public class Test { public static void main(Str1 N A 2 Only button Cancel is displayed.
426 import java.aw t.*; import javax.sw ing.*; /*<applet code="L.class" w idth=200 height1 N A 2 Button is created w ith given image
427 import java.aw t.*; import javax.sw ing.*; public class Sw ing_Demo extends JApplet 1 Y1 A 2 Container c=getContentPane();
{ public void init() { ImageIcon ii=new ImageIcon("Sunset.jpg"); JLabel l1=new
JLabel("Sunset Image",ii,JLabel.CENTER); c.add(l1); } }
Figure:-
428 In CardLayout w e are going to add components for every card to 1 N U 2 Panel
429 In given constructor w hat 3rd parameter indictaes Scrollbar s=new 1 N A 2 Size of thumb
Scrollbar(0,10,20,0,1000)
430 In the applet w indow a user w ants to arrange all component one after another W hich 1 N U 2 setLayout(new Flow Layout());
431 In the below program, w hy is java.aw t package imported? import javax.sw ing.*; 1 N U 2 Because Container belongs to the packag
import java.aw t.*; public class New Main extends JFrame { public static void
main(String[] args) { JFrame jf=new JFrame(""My Frame""); Container
cpane=jf.getContentPane(); JLabel l1=new JLabel(""Name""); JButton b1=new
JButton(""OK""); JButton b2=new JButton(""CANCEL""); JTextField t1= new
JTextField(); jf.setLayout(new GridLayout(2,2)); cpane.add(l1); cpane.add(t1);
cpane.add(b1); cpane.add(b2); jf.setSize(100,100); jf.setVisible(true);
jf.setDefaultCloseOperation(EXIT_ON_CLOSE); } }
432 Insert the correct code in the follow ing program segment in order to display follow 1 Y1 A 2 JRadioButton b1,b2,b3; b1= new JRadio
ing output. JRadioButton("American"); b
Figure:-
433 Is it possible to change display character of TextField?How ? 1 N U 2 Yes,by using setEchoChar() method.
434 java Applets are used to create ……………………Applications 1 N A 2 both (a) and (b)
437 Multiple layouts in the single conainer can be created w ith the help of 1 N U 2 Panel
_______________
439 Observe the follow ing code import java.aw t.*; import javax.sw ing.*; /* 1 N A 2 The output is obtained in table w ith tw o
<applet code="JTableDemo.class" w idth=400 height=500> </applet> scrollbar
*/ public class JTableDemo extends JApplet { public void init() { Container
contentPane = getContentPane(); contentPane.setLayout(new Flow Layout()); final
String[] colHeads = { "Name", "Phone", "Fax"}; final Object[][] data = { {"Prashant",
"12345","6789"}, {"Rupesh", "12345", "23456"} }; JTable table = new JTable(data,
colHeads); int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALW AYS; int h =
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALW AYS; JScrollPane jsp = new
JScrollPane(table, v, h); contentPane.add(jsp, BorderLayout.CENTER); } }
440 Observe the follow ing code import java.aw t.*; import java.applet.*; import 1 N A 2 The output is obtained in Applet w ith Bo
java.util.*; /* <applet code="BorderLayoutDemo" w idth=400 height=200> est,north,south and TextArea at center
</applet> */ public class BorderLayoutDemo extends Applet { public void init() {
setLayout(new BorderLayout()); add(new Button("This is across the top."),
BorderLayout.NORTH); add(new Label("The footer message might go here."),
BorderLayout.SOUTH); add(new Button("Right"), BorderLayout.EAST); add(new
Button("Left"), BorderLayout.W EST); String msg = "The reasonable man adapts " +
"himself to the w orld;\n" + "the unreasonable one persists in " +
"trying to adapt the w orld to himself.\n" + "Therefore all progress depends " + "on
the unreasonable man.\n\n" + " - George Bernard Shaw \n\n"; add(new
TextArea(msg), BorderLayout.CENTER); } } W hat w ill be the output of the above
program?
441 Observe the follow ing code importjava.aw t.*; importjava.applet.*; public class LayoutD1 N A 2 The output is obtained in Applet w ith tw
Observe the follow ing code import java.aw t.*; import java.applet.*; /*
442 <APPLET Code="TextFieldPassw ord" W idth=500 Height=200> 1 N A 2 The output is obtained in Applet w ith tw
</APPLET> */ public class TextFieldPassw ord extends Applet { public void init() {
Label lblName = new Label("enter name"); Label lblPassw d
= new Label("enter passw ord"); TextField txtName = new TextField("your name
here", 20); TextField txtPassw d = new TextField(20); add(lblName); add(txtName);
add(lblPassw d); txtPassw d.setEchoChar('*'); add(txtPassw d); } }
443 Observe the follow ing program and point out w hich statement contains error. 1 N A 2 Error in statement in w hich JScrollPane
importjava.aw t.*; importjavax.sw ing.*; /* <applet code="JTableDemo" w idth=400
height=200> </applet> */ public class JTableDemo extends JApplet { public void
init() { Container
contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); final
String[] colHeads = { "emp_Name", "emp_id", "emp_salary" }; final Object[][] data
= { { "Ramesh", "111", "50000"
}, { "Sagar", "222", "52000" }, { "Virag", "333", "40000" }, { "Amit", "444", "62000"
}, { "Anil", "555", "60000" }, }; JTable table = new JTable(data,colHeads ); int v =
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h =
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPanejsp = new
JScrollPane(table,,h,v); contentPane.add(jsp, BorderLayout.CENTER); } }
444 Observe the image show n below . S1Q42 W hich AW T component w ill the image as 1 Y1 A 2 CheckboxGroup
show n
Figure:-
446 Point out missing w ord in syntax in given code import java.aw t.*; import java.aw t.eve1 N U 2 new
447 Positions the components into five regions:east, w est, north, south, center 1 N U 2 BorderLayout
448 Say that a Frame contains three Panels. Could each Panel have a different layout manag1 N U 2 Yes---each one can use setLayout() w ith
449 select correct code for display given output 1 Y1 A 2 import java.aw t.*; imort java.applet.*;
Figure:- idth=200 height=300></applet>
void init() { // setLayout(new Flow Layo
Button("Button " + i)); } } }
450 Select correct statement to add component in south region. 1 N U 2 add(component obj,BorderLayout.SOUTH);
451 Select proper code for given image as shw on in below 1 Y1 A 2 import java.aw t.*; import java.applet.*;
Figure:- init() { Choice os=new Choice(); os.add(
os.add("w nn nt"); os.add(&q
} /*<applet code="choice11&quo
</applet>*/
456 Select the correct output of the follow ing program: import java.aw t.*; import java.app 1 Y2 A 2 .
457 Select the missing statement in given code import java.aw t.*; import java.applet.*; 1 N U 2 JTable it=new JTable(data,s);
import javax.sw ing.*; public class table extends JApplet
{ public void init() { String s[]={"srno","name","rollno"}; Object data[]
[]={{"1","abc","01"},{"2","xyz","0"}}; int
v=JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED; int
h=JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPane p=new
JScrollPane(it,v,h); Container co=getContentPane(); co.add(p,BorderLayout.CENTER);
} } /*<applet code=table w idth=300 height=300></applet>*/
458 select the missing statement in the follow ing code import java.aw t.Flow Layout; public1 N A 2 import javax.sw ing.*;
459 Select the missing statement in the follow ing program for follow ing output import 1 Y1 A 2 nw .add(nw 1);
java.aw t.*; public class MenuTest extends Frame { MenuTest(String title) {
super(title); MenuBar mb=new MenuBar(); Menu file=new Menu("File"); Menu
edit=new Menu("Edit"); Menu view =new Menu("View "); MenuItem nw =new
MenuItem("New "); MenuItem open=new MenuItem("Open"); MenuItem nw 1=new
MenuItem("Blank document"); file.add(nw ); file.add(open); mb.add(file);
mb.add(edit); mb.add(view ); setMenuBar(mb); } public static void main(String
arg[]) { MenuTest obj=new MenuTest("My Frame"); obj.setSize(200,400);
obj.setVisible(true); }}
Figure:-
460 Select the missing statement in the program for follow ing output import java.aw t.*; pu1 N A 2 mbr.add(view menu);
461 Select the missing statement in the program to get the follow ing output import 1 N U 2 city = new Choice();
java.aw t.*; import java.aw t.event.*; import java.applet.*; /* <applet
code="ChoiceDemo" w idth=300 height=180>
</applet> */ public class ChoiceDemo extends Applet implements ItemListener {
Choice city; public void init() { city.add("Nagpur"); city.add("Mumbai");
city.add("Pune"); city.add("Nashik"); add(city); city.addItemListener(this); } public
void itemStateChanged(ItemEvent ie) { repaint(); } public void paint(Graphics g) {
String msg = "Select city: "; msg += city.getSelectedItem(); g.draw String(msg, 6,
120); } }
462 Select the missing statements in the program to get follow ing output: import 1 Y1 A 2 CheckboxMenuItem bold = new Checkbo
java.aw t.*; class Sample extends Frame { Sample(String title) { super(title); CheckboxMenuItem italic = new Checkbo
MenuBar mbar = new MenuBar(); setMenuBar(mbar); CheckboxMenuItem under = new Checkb
Menu font = new Menu("Font"); font.add(bold);font.add(italic);font.add(under); CheckboxMenuItem strike = new Checkb
font.add(strike); mbar.add(font); Menu para = new Menu("Paragraph");
mbar.add(para); Menu styles = new Menu("Styles"); mbar.add(styles);
setSize(400,400); setVisible(true); } public static void main(String args[]) { new
Sample("Menu Example"); } }
Figure:-
463 Select the proper code for follow ing output? Figure:- 1 Y1 A 2 import java.aw t.*; import java.applet.*;
idth=200 height=80> </applet>
{ Label jlb1=new Label(" Enter Num
Choice ch=new Choice();
464 Select the proper command to run the follow ing code import java.aw t.*; import java.a 1 N A 2 appletview er textdemo25 .java
465 Select the proper command to run the follow ing code import java.aw t.*; import 1 N A 2 appletview er combodemo.java
java.aw t.event.*; import javax.sw ing.*; import java.applet.*; /* <applet
code="combodemo" w idth=300 height=100>
</applet> */ public class combodemo extends JApplet { public void init() { Container
co = getContentPane(); co.setLayout(new Flow Layout()); JComboBoxjc=new
JComboBox(); jc.addItem("pen"); jc.addItem("pencil"); jc.addItem("eraser");
jc.addItem("sharpner"); co.add(jc); } }
466 Select the proper command to run the follow ing code import java.aw t.*; import 1 N A 2 Javac combodemo11.java & appletv
java.aw t.event.*; import javax.sw ing.*; import java.applet.*; /* <applet
code="combodemo11" w idth=300 height=100> </applet> */ public class
combodemo11 extends JApplet
{ public void init() { Container co = getContentPane(); co.setLayout(new Flow
Layout()); JComboBoxjc=new JComboBox(); jc.addItem("cricket");
jc.addItem("football"); jc.addItem("hockey"); jc.addItem("tennis"); co.add(jc); } }
467 Select the proper command to run the follow ing code import java.aw t.*; import 1 N A 2 appletview er combodemo11.java
java.aw t.event.*; import javax.sw ing.*; import java.applet.*; 90 /* <applet
code="combodemo11" w idth=300 height=100> </applet> */ public class
combodemo11 extends JApplet
{ public void init() { Container co = getContentPane(); co.setLayout(new Flow
Layout()); JComboBoxjc=new JComboBox(); jc.addItem("cricket");
jc.addItem("football"); jc.addItem("hockey"); jc.addItem("tennis"); co.add(jc); }
Select the proper command to run the follow ing code import java.aw t.*; import java.a
468 public mymenu(String title) { super(title); file.add(fnew ); file.add(fopen); file.add(fsa1 N A 2 java mymenu
469 Select the proper command to run the follow ing code import java.aw t.*; import 1 N A 2 appletview er tabbeddemo.java
javax.sw ing.*; public class tabbeddemo extends JApplet { public void init() {
Container ContentPane=getContentPane(); JTabbedPane jt=new JTabbedPane();
jt.addTab("City",new CityPanel()); jt.addTab("Color",new ColorPanel());
jt.addTab("Flavours",new FlavoursPanel()); getContentPane().add(jt); } } class
CityPanel extends JPanel { public CityPanel() { JButton b1=new JButton("Kolhapur");
add(b1); JButton b2=new JButton("Pune"); add(b2); JButton b3=new
JButton("Mumbai"); add(b3); JButton b4=new JButton("Sangali"); add(b4); } } class
ColorPanel extends JPanel { public ColorPanel() { JRadioButton rb1=new
JRadioButton("Red"); add(rb1); JRadioButton rb2=new JRadioButton("Green");
add(rb2); JRadioButton rb3=new JRadioButton("Blue"); add(rb3); JRadioButton
rb4=new
JRadioButton("Pink"); add(rb4); } } class FlavoursPanel extends JPanel
{ public FlavoursPanel() { JComboBox jc=new JComboBox(); jc.addItem("Vanilla");
jc.addItem("Chocalate"); jc.addItem("Straberry"); add(jc); } } /*<applet
code="tabbeddemo.class" w idth=500 height=500> </applet>*/
470 Select the proper command to run the follow ing code import javax.aw t.* import 1 N A 2 appletview er JListDemo.java
javax.sw ing.*; public class JListDemo extends JApplet { JTextField t1; JList jl; String
data[ ]={“Red”, “Green”, “Blue”, “Yellow ”, “Pink”}; Public void init() { Container
cp=getContentPane(); cp.setLayout(new Flow Layout()); T1=new JList(data);
cp.add(jl); cp.add(t1); } } /*<applet code=”JListDemo” w idth=300 height=300>
</applet>*/
471 Select the proper command to run the follow ing code import java.aw t.*; import 1 N A 2 appletview er TextFieldDemo.java
java.applet.*; /* <applet code="TextFieldDemo" w idth=380 height=150> </applet>
*/ public class TextFieldDemo extends Applet { TextField name, pass; public void
init() { Label namep
= new Label("Name: ", Label.RIGHT); Label passp = new Label("Passw ord: ",
Label.RIGHT); name = new TextField(12); pass = new TextField(8);
pass.setEchoChar('?'); add(namep); add(name); add(passp); add(pass); } public void
paint(Graphics g) { } }
Select the proper command to run the follow ing code /*<applet code=frameinapp w idt
472 java.aw t.*; import java.aw t.event.*; import java.applet.*; class framein extends Fram1 N A 2 Appletview er frameinapp.java
473 Select the proper output for follow ing code import java.aw t.*; import java.applet.*; 1 Y2 A 2 S1Q42O2
public class DemoBorderLayout extends Applet { Button b1,b2,b3,b4,b5; public void
init() { BorderLayout b=new BorderLayout(20,30); setLayout(b); b1=new
Button("Top"); b2=new Button("Right"); b3=new Button("Bottom"); b4=new
Button("Left"); b5=new Button("Center"); add(b1,BorderLayout.NORTH);
add(b2,BorderLayout.EAST); add(b3,BorderLayout.SOUTH); add(b4,BorderLayout.W
EST); add(b5,BorderLayout.CENTER); } } /*
<applet code="DemoBorderLayout.class" w idth=350 height=300>
</applet>*/
474 Select the suitable statement for given output 1 Y1 U 2 Buttons,Flow Laout.RIGHT
Figure:-
476 Show a single line of code that w ill convert char ch into String s 1 N A 2 String s=””+ch;
477 Show the output of follow ing code. import javax.sw ing.*; public class Test { public sta 1 N A 2 true,false
State the method that w ill be used so as to display the passw ord as '?' in the output
show n in S1Q43
Figure:-
478 1 Y1 A 2 setEchoChar('?')
479 state the output and assume suitable data import java.aw t.*; import java.applet.*; clas1 N U 2 label of c2 w ill print
480 State true of false. i) AW T is an extended version of sw ing ii) Paint( ) of 1 N U 2 i-false, ii-false
Applet class cannot be overridden
481 Steps for Adding TabbedPane Control 1 N U 2 1. Create a JTabbedPane object 2. Call a
Step 2 for each Tab 4. Add the Tabbed P
482 Suppose a Panel is added to a Frame and a Button is added to the Panel. If the Frame's 1 N U 2 10-point TimesRoman
483 Sw ing components are light w eight because: 1 N A 2 Sw ing components are platform independent.
484 Sw ing provides a combo box (a combination of a text field and a drop- dow n list) 1 N U 2 Jcomponent
through the JComboBox class, w hich extends
__________________.
485 Tabbedpane Layout can be changed using: 1 N U 2 Mentioning layout in constructor only.
486 The code Code w ill produce how many buttons: public class JScrollPaneDemo extends 1 N A 2 400 Buttons
JApplet { public void init() { // Get content pane Container contentPane =
getContentPane(); contentPane.setLayout(new BorderLayout()); JPanel jp = new
JPanel(); jp.setLayout(new GridLayout(20, 20)); int b = 0; for(int i = 0; i
< 20; i++) { for(int j = 0; j < 20; j++) { jp.add(new JButton("Button " + b)); ++b;
} } // Add panel to a scroll pane int v =
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h =
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPane jsp = new
JScrollPane(jp, v, h); // Add scroll pane to the content pane contentPane.add(jsp,
BorderLayout.CENTER); } }
487 The constructor JCheckBox(true, “YES”) suggests that – 1 N U 2 Checkbox is selected and displays the string “YES” on it.
488 The default horizontal and vertical gap in Flow Layout is….. 1 N U 2 5 Pixel
The follow ing constructors are required in the program to get output
Figure:-
493 The layout manger that show s how w ords flow in a text editor?Use 1 N U 2 Flow
494 The main difference betw een model and models dialog box is 1 N U 2 W hen box is active input focus can not be directed to anoth
495 The method _______ assigns the name Result to the Text of variable jlbl. 1 N A 2 jlbl.setText("Result")
496 The method __________ separates menu items in a menu mu. 1 N A 2 mu.addSeparator()
497 To construct a text area that is 80 character-w idths w ide and 10 1 N U 2 new TextArea(10, 80)
502 To implement a single –line text area entry area, Use? 1 N A 2 TextField
503 To place any component in AW T/Sw ing w hich method w ill be used 1 N U 2 setBounds(int x,int y,int height,int w idth)
506 To set new font object w ith size 48 , name: Serif , Style PLAIN, w hat w ill be the 1 Y1 U 2 new Font("Serif", Font.PLAIN
statement from the follow ing
Figure:-
507 To set passw ord as '******' w hich command should be added in the follow ing code im1 N A 2 psw .setEchoChar('*');
508 W hat AW T classes (components) w ill be needed to get follow ing output? 1 Y1 U 2 Label,Checkbox,checkboxGroup,Flow Lay
Figure:-
W hat code should be added so that w e can get follow ing Code? import java.aw t.*;
import java.applet.*; import java.aw t.event.*; /*<applet code=SignIn.class w
idth=400 height=400></applet>*/ public class SignIn extends Applet implements
ActionListener { TextField t1,t2; Button b1; Label l; public void init() { t1=new
TextField(20); t2=new TextField(20); b1=new Button("Sign In"); l=new Label("");
"); add(t1); add(t2); --------------------- add(b1); ---------------------- add(l); }
public void actionPerformed(ActionEvent ae) { if(ae.getSource()==b1) {
String msg=t1.getText(); String msg1=t2.getText();
510 W hat code should be added so that w e can get follow ing Code? import java.aw t.*; 1 Y1 A 2 setLayout(new Flow Layout());
import java.aw t.event.*; class W indow CloseDemo extends Frame { Button exit; W
indow CloseDemo() { exit=new Button("Exit"); add(exit); W indow Close w =new W
indow Close(); addW indow Listener(w ); setTitle("W indow "); setSize(400,300);
setVisible(true); } public static void main(String []cd) { W indow CloseDemo w
cd=new W indow CloseDemo(); } } class W indow Close extends W indow Adapter {
public void w indow Closing(W indow Event w e) { System.exit(1); } }
Figure:-
511 W hat code w ould you use to construct a 24-point bold Calibri font? 1 N U 2 new Font("Calibri", Font.BOLD,24);
512 W hat Component w ill be displayed in output of Follow ing Code import java.aw t.*; im 1 N A 2 TextBox and Button
513 W hat component w ill be needed to get follow ing output? Figure:- 1 Y1 U 2 D) JPanel, JTextField, JScrollPane and C
514 W hat components w ill be needed to get follow ing output? Figure:- 1 Y1 U 2 Applet, TabbedPane, ComboBox
515 W hat components w ill be needed to get follow ing output? Figure:- 1 Y1 U 2 Button,Checkbox,RadioButton
W hat components w ill be needed to get follow ing output? Figure:-
517 W hat components w ill be needed to get follow ing output? Figure:- 1 Y1 A 2 Icon, Button, Panel, Frame
518 W hat components w ill be needed to get follow ing output? Figure:- 1 Y1 U 2 JApplet, JCheckBox, JComboBox, Jbutton
519 W hat components w ill be needed to get follow ing output? Figure:- 1 Y1 U 2 JPassw ordField,JComboBox,ToolTipText,
520 W hat components w ill be needed to get follow ing output? Figure:- 1 Y1 U 2 Jtable, JScrollPane
521 W hat components w ill be needed to get follow ing output? Figure:- 1 Y1 U 2 Label , Button, ComboBox
522 W hat components w ill be needed to get follow ing output? Figure:- 1 Y1 U 2 Label, Choice
523 W hat components w ill be needed to get follow ing output? Figure:- 1 Y1 U 2 Label,textfield,Button
524 W hat components w ill be needed to get follow ing output? Figure:- 1 Y1 U 2 TextField , Label , Button
525 W hat correction is required in the follow ing program to get output? import java.aw t.*;1 N A 2 JComboBox jc=new JComboBox() ;
W hat Correction should be done in the follow ing program to get the proper output? /*
526 ColorsPanel()); getContentPane().add(jtp); } } class CitiesPanel extends JPanel { public1 N A 2 Missing package sentences
527 W hat is output of follw ing programmissing statement? import java.aw t.*; import 1 Y1 A 2 Buttons are displayed in 3 row s and 3 co
javax.sw ing.*; public class MyGridLayout{ JFrame f; MyGridLayout(){ f=new
JFrame(); JButton b1=new JButton("1"); JButton b2=new JButton("2"); JButton
b3=new JButton("3"); JButton b4=new JButton("4"); JButton b5=new JButton("5");
JButton b6=new JButton("6"); JButton b7=new JButton("7"); JButton b8=new
JButton("8"); JButton b9=new JButton("9");
f.add(b1);f.add(b2);f.add(b3);f.add(b4);f.add(b5);
f.add(b6);f.add(b7);f.add(b8);f.add(b9); f.setLayout(new GridLayout(3,3));
f.setSize(300,300); f.setVisible(true); } public static void main(String[] args) { new
MyGridLayout(); } }
Figure:-
528 W hat is an event in delegation event model used by Java programming language? 1 N U 2 An event is an object that describes a sta
529 W hat is mising statement in follow ing code? import 1 N U 2 Both a & b
java.aw t.Container; import java.aw t.Font; import java.aw t.GridLayout; import
javax.sw ing.JButton; import javax.sw ing.JFrame; public class GridSizeTest extends
JFrame { public static void main(String[] args) { GridSizeTest gst = new
GridSizeTest(); gst.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); gst.pack(); }
public GridSizeTest() { Container pane = getContentPane(); pane.setLayout(new
GridLayout(2, 2)); JButton button = new JButton("First"); pane.add(button); button =
new JButton("Hi"); button.setFont(new Font("Courier", Font.PLAIN, 36));
pane.add(button); button = new JButton("There"); } }
530 W hat is output of follow ing program? import javax.sw ing.*; import java.aw t.event.*; 1 Y2 A 2
531 W hat is Purpose of Jtree ? 1 N U 2 A tree is a component that presents a hierarchical view of data
532 W hat is purpose of default constructor of Scrollbar( ) class? 1 N U 2 To create vertical Scrollbar
539 W hat is the length of the application box made by this program? import java.aw t.*; 1 N A 2 Compilation Error
import java.applet.*; public class myapplet extends Applet
{ Graphic g; g.draw String("A Simple Applet", 20, 20); }
540 W hat is the output of follow ing program: import java.aw t.*; import java.aw 1 N A 2 doesn't show frame
t.event.*; import java.applet.*; public class app3 extends Frame { public static void
main(String m[]) { Frame f=new Frame("BUTTON FRAME"); Button b=new
Button("save"); f.add(b); f.setSize(100,200); f.setLayout(new Flow Layout());
f.setVisible(false);
}}
541 W hat is the output of the follow ing code: import java.aw t.*; import java.applet.*; 1 Y2 A 2 A
/* <applet code="GridLayoutDemo" w idth=300 height=200> </applet> */ public
class GridLayoutDemo extends Applet
{ int n = 4; public void init() { setLayout(new GridLayout(n,n,10,10)); for(int i = 0; i
<n; i++) { for(int j = 0; j <n; j++) { add(new Button("k")); } } } }
544 W hat is the output of this program? Figure:- 1 Y1 A 2 w ill not display any output
545 W hat is the purpose of follow ing code? JTextField jtf=new 1 N U 2 Defining Textfield
JTextField(15)
546 W hat is the purpose of JTabbedPane? 1 N U 2 JTabbedPane manages a set of components of linking them
547 W hat is the purpose of ScrollPane 1 N U 2 ScrollPane Displays component in a rectangular area
W hat is the result of executing the follow ing Java class: import java
.aw t.*; public class FrameTest extends Frame { public Frame Test() {
550 add (new Button("First")); add ( new Button( "Second")); add (new 1 N A 2 Only the third button is diplayed .
Button ("Third")); pack() ; setVisible(true); } public static void main ( String args [] { n
W hat is the use of panel in the program given below import java.aw t.*; import java.ap
c.addItemListener(new ItemListener(){
563 W hat w ill be the order of four items added Choice c1 = new Choice(); c1.add("First"); 1 N U 2 First,Second,Lastadded,Third
564 W hen the size of componant is change___________event is generated. 1 N A 2 ComponantEvent
565 W hen there is a sw itching condition like on or off, w hich control is used of follow ing? 1 N U 2 toggle button
566 W hen w e create a Dialog box using the Constructor Dialog (Frame f,true) the dialog bo1 N U 2 Modal
567 W hen w e invoke repaint() for a java.aw t.Component object, the AW T 1 N U 2 update()
invokes the method:
568 W here g is a graphics instance w hat w ill the follow ing code draw on the screengfillArc1 N A 2 An arc bounded by a box of height 50, w
569 W here the panel add on frame? import java.aw t.*; public class CompLay extends Fram1 N A 2 A.On left side of Frame
570 W hether the code is correct to generate the given output? /*<applet 1 Y1 A 2 Yes
code="MyJRadioButton" w idth=900 height=900> </applet>*/ import java.aw t.*;
import javax.sw ing.*; public class MyJRadioButton extends JApplet { public void
init() { Container c=getContentPane(); c.setLayout(new Flow Layout()); JRadioButton
r1=new JRadioButton("A"); c.add(r1); JRadioButton r2=new JRadioButton("B");
c.add(r2); JRadioButton r3=new JRadioButton("C"); c.add(r3); add(r1); add(r2);
add(r3); } }
Figure:-
571 w hich abstract class is the super class of all menu related classes? 1 N U 2 MenuComponent
572 W hich among the below is not the method applicable for Button in sw ing 1 N U 2 setDisableIcon()
573 W hich among the follow ing is not correct regarding dialog? 1 N U 2 Use of Dialog effects the w orking of Application
574 W hich among the follow ing is the feature of Jtable 1 N U 2 all of these
575 W hich are the valid w ays to create DataInputStream streams? 1 N A 2 new DataInputStream(new FileInputStream("in.dat&q
576 W hich are true about the Container class? 1 N U 2 All of the above
577 w hich AW T complonents are used to produce given output? 1 N U 2 Button, Label, TextField, TextArea
578 W hich AW T control is uesd to produce given output 1 Y1 U 2 GridLayout, Label, TextField, Button
Figure:-
579 W hich checkbox w ill be selected in the follow ing code ( Assume w ith main and added 1 N U 2 cb3
580 W hich class can be used to represent a checkbox w ith a textual label that can appear i 1 N U 2 Checkbox MenuItem
581 w hich class provides method for accessing a font's properties? 1 N U 2 FontMerices
582 W hich classes are used to generate follow ing output as show n in figure. 1 Y1 U 2 Both options i and iii correct.
Figure:-
583 W hich code is correct to generate the follow ing output? Figure:- 1 Y1 A 2 a) Scrollbar vert = new Scrollbar(Scrollb
Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0,
584 W hich code w ill produce the out show n in figure 1 Y1 U 2 f=new Font("Times New Roman&qu
Figure:- new font setForeground(Color.red);
585 W hich componenet is needed to get the follow ing output? Figure:- 1 Y1 U 2 JScrollPane,Icon
586 W hich Componenets and layout manager are used in follow ing output 1 Y1 U 2 Buttons,Borderlayout
Figure:-
587 W hich Component are present in follow ing image 1 Y1 U 2 JButton, JLabel, JTable, JProgressBar
Figure:-
588 W hich component is display area for a short string of text, image or both? 1 N U 2 Jlabel
590 1 Y1 U 2 Label,TextArea,Button
591 W hich Component subclass is used for draw ing and painting? 1 N U 2 Canvas
592 W hich components are needed to get above show n output 1 Y1 U 2 List, Button
Figure:-
593 W hich components are needed to get below show n output? Figure:- 1 Y1 U 2 JComboBox, Button
596 W hich components are needed to get below show n output? Figure:- 1 Y1 A 2 Label,Choice
599 W hich components are reuired to get follow ing output (S1Q28) Figure:- 1 Y1 U 2 List and Button
600 1 Y1 U 2 JRadioButton,JTextField
601 W hich components are used in follow ing output 1 Y1 U 2 Label,TextArea,Button
Figure:-
602 W hich Components are used in Follow ing output? Figure:- 1 Y1 U 2 JRadioButton ,JTextField
603 1 Y1 U 2 Applet,Label,TextField,Button
604 W hich components are used in the follow ing output? Figure:- 1 Y1 U 2 Checkbox,Label
605 W hich components are used in the follow ing output? Figure:- 1 Y1 U 2 JButton,JTextField
607 W hich components are used in the follow ing output? Figure:- 1 Y1 U 2 Label, TextField, Button
608 W hich components are used in the follow ing output? Figure:- 1 Y1 U 2 Label, TextField, Button
609 W hich components are used in the follow ing output? Figure:- 1 Y1 U 2 Label,TextField,Button
610 W hich components are used in the follow ing output? Figure:- 1 Y1 U 2 Label,TextField,Button
611 W hich components are used in the follow ing output? Figure:- 1 Y1 U 2 Scrollbar, Label, Choice
W hich components are used in this code? import javax.sw ing.*; import java.aw t.*; 1 N U 2 Button and ImageIcon
public class Iconbutton{ public static void main(String[] args){ JFrame frame = new
JFrame("Icon on button"); JButton button
= new JButton("JAVA"); Icon imgicon = new ImageIcon("java.gif");
613 W hich components are used to devlope follow in w indow 1 Y1 U 2 Label, TextField, Button
Figure:-
614 W hich Components need to be used to produce this output 1 Y1 A 2 JtabbedPane,JLabel and ImageIcon
Figure:-
615 W hich components provide support for tw o-state buttons? 1 N U 2 JCheckBox, JRadioButton
616 W hich constructor creates a TextArea w ith 10 row s and 20 columns? 1 N U 2 new TextArea(10, 20);
617 W hich constructor w as correct to get output 1 Y1 U 2 Jtable(2,3)
Figure:-
618 W hich control is a combination of text field and dropdow n list? 1 N U 2 combo boxes
619 W hich Gridlayout class constructor creates single column grid Layout? 1 N U 2 GridLayout()
622 W hich is the layout manger that occupies the same size on the w indow ? 1 N A 2 Grid
623 W hich is the correct code for the follow ing output 1 Y1 A 2 import java.aw t.*; import java.applet.*;
Figure:- void init() { Button b1=new Butto
b2=new Button("Cancel");
Flow Layout(Flow Layout.RIGHT); se
627 W hich layout is used in the follow ing output? Figure:- 1 Y1 U 2 BorderLayout
628 W hich Layout is used to obtain the follow ing output 1 Y1 U 2 GridLayout
Figure:-
629 W hich layout manager can be used to get the follow ing output? Figure:- 1 Y1 U 2 BorderLayout
630 W hich layout manager can be used to get the follow ing output? Figure:- 1 Y1 U 2 GridLayout
632 W hich Layout Manager places compenent inone of the five region 1 N A 2 BorderLayout
NORTH,SOUTH,W EST,EAST,CENTER.
635 W hich method is used to display title on titlebar of Frame? 1 N U 2 setTitle(String title)
638 W hich method of Graphics class is to display "HelloW orld" on the 1 Y1 U 2 draw String("HelloW orld",30
Applet show n in figure. Figure:-
639 W hich method of the component class is used to set the position and the size of a comp1 N U 2 setBounds()
640 W hich method show s the complete process in percent on the progress bar? 1 N U 2 setStringPainted(boolean)
641 W hich method specifies that the text and icon are horizontally aligned to the right in th 1 N U 2 jbt.setHorizontalTextPosition(JButton.RIG
642 W hich methods are used to draw the follow ing output? Figure:- 1 Y1 U 2 a)draw Polygon(),fillPolygon()
643 W hich of follow ing is true? 1 N U 2 All the methods in the JButton class are
644 W hich of the follow ing applet tags is legal to embed an applet class named Test into a 1 N A 2 B.<applet code = Test. Class w idth =
646 W hich of the follow ing commands w ill set a layout manager that divides the container 1 N U 2 setLayout( new GridLayout(4, 3) )
647 W hich of the follow ing constructor creates a Checkbox? 1 N U 2 Checkbox(String str, boolean s, null)
648 W hich of the follow ing create a list w ith five visible items and multiple selection enabl 1 N U 2 new List(5,true)
649 W hich of the follow ing creates a List w ith 3 visible items and multiple mode selection 1 N U 2 new List(3,false)
653 W hich of the follow ing layout mangers honours the preferred size of component( Multip1 N U 2 Flow Layout
654 W hich of the follow ing method adds item "I" to the List w ith deprecation w arnings at 1 N U 2 addItem(“I”)
655 W hich of the follow ing method use to check w hether the JCheckBox jchk is selected? 1 N U 2 jchk.isSelected()
656 W hich of the follow ing method use to get the text or caption of the button jbt? 1 N U 2 jbt.getText()
657 W hich of the follow ing methods can be used to change the size of a java.aw t.Compone1 N A 2 (B) & (E)
658 W hich of the follow ing methods can be used to change the size of a java.aw t.Compone1 N U 2 setSize()
660 W hich of the follow ing options is correct about Layout Manager 1 N U 2 Both B and C
661 W hich of the follow ing statement is for placing the frames upper left corner to (200,10 1 N A 2 frame.setLocation(200,100)
W hich of the follow ing statement is used to create GridLayout in the output show n
below ?
Figure:-
663 W hich of the follow ing statements are true i) Scrollbar is a component but not a Conta1 N U 2 i and ii both are true
665 W hich of the follw ing is true about Flow Layout 1 N U 2 both A and B
666 W hich of these classes can be added to any Container class, using the add method defin1 N U 2 Button
667 W hich of these events w ill be notified if scroll bar is manipulated? 1 N U 2 AdjustmentEvent
668 W hich of these is not a constructor of the FileDialog? 1 N U 2 FileDialog(Frame parent,int how )
669 W hich of these methods are used to register a keyboard event listener? 1 N U 2 addKeyListener()
670 W hich of these methods can be used to determine the type of event? 1 N U 2 getID()
671 W hich of these methods can be used to know w hich key is pressed 1 N U 2 getModifier()
672 W hich of these methods returns the class of the object? 1 N U 2 getClass()
675 W hich option is correct to adding Jtree in an Applet? 1 N U 2 Create a Jtree Object, Create a JScrollPa
Add the scroll pane to the content pane o
677 W hich package is used to add progress bar in an application? 1 N U 2 javax.sw ing.JProgrssBar
678 W hich part of program Below w ill show an error: import java.aw t.*; import java.aaple 1 N A 2 super();
w hich statement is required for follow ing output? import java.aw t.*; import
java.applet.*; public class TextArea_Demo extends Applet { TextArea ta1; public
void init() { ta1=new TextArea("My name Is troy",25,25); ta1.append(" name is
khan "); } }
Figure:-
679 1 Y1 A 2 add(ta1)
680 W hich Statement is required to obtain given output by using follow ing code public 1 Y1 A 2 setLayout(new Flow Layout());
class fldemo extends Frame{ fldemo() { Button b1=new Button("Save"); Label
l1=new Label("Name"); TextField t1=new TextField(10); add(l1); add(t1); add(b1);
//Statement required here setSize(new Dimension(500,500)); setTitle("Flow
Layout"); setVisible(true); } public static void main(String arg[]) { fldemo f=new
fldemo(); } }
Figure:-
681 W hich statement should be added to display button. import java.aw t.*; import javax.s 1 N A 2 contentPane.add(jb);
W hich statements are missing in follow ing program to get the output
as show n in fig /*<applet code=GridBagDemo w idth=300 height=300>
</applet>*/ import java.aw t.*; import java.applet.*; public class GridBagDemo
extends Applet { GridBagLayout gdb=new GridBagLayout(); GridBagConstraints c
______________________________: Button b1=new Button("One"); Button b2=new
Button("Tw o"); Button b3=new Button("Three"); Button b4=new Button("Four");
Button b5=new Button("Five"); public void init() { __________________
c.gridx=0;c.gridy=0;c.w eightx=0.5; c.w eighty=0.5; gdb.setConstraints(b1,c);
c.gridx=1;c.gridy=0; gdb.setConstraints(b2,c); c.gridx=2;c.gridy=0;
gdb.setConstraints(b3,c); c.gridx=0;c.gridy=1; c.gridw idth=3; c.ipady=20;
c.fill=GridBagConstraints.BOTH; gdb.setConstraints(b4,c);
683 W hich statements are missing in the given code below . import java.aw t.*: Import 1 N A 2 t= new TextArea ( 5,20);
java.aw t.event.*; Importjava. Applet.*; public class Pral extends Applet implements
ActionListener { String s; Label a ; Button b; TextArea t; public void init () { a = nw
Label ( Enter Address: ",LabelLEFT); b = new Button ("OK"); add (a); add(t ); add
(b); b.addActionListener(this); } public void actionPerformed (ActionEventae) { if
(ae.getSource()==b) { repaint(); } } public void paint ( Graphics gr ) {
s=t.getText(0); gr.draw String ("User Address is : " +s,150,150); } } /*<applet code
= Pral w idth = 400 height = 300 >
</applet>*/
684 W hich statements is missing in the given code below . import java.aw t.*; import 1 N A 2 ButtonGroup bg= new ButtonGroup()
java.aw t. Event.*; import javax.sw ing.*; /*<applet code = Colur w idth = 500
height = 500 ></applet>*/ public class Colur extends J Applet implements
ActionListener { Container cp = getContentPane (); public void init () { cp.setLayout
(new Flow Layout()); JRadioButton b1= new JRadioButton("Red");
b1.addActionListener(this); cp.add(b1); JRadioButton b2 = new
JRadioButton("Green"); b2.addActionListener(this); cp.add(b2);
JRadioButton("Green"); b3.addActionListener(this); cp.add(b3); }
public void action Performed(ActionEvent ae ) { String S; s= ae.getActionCommand();
if (s=="Red") cp.setBackground(Color.red); else if (if s=="Green")
cp.setBackground(Color.green); else if (s=="Blue") cp.setBackground (Color.blue.); }
}
685 W hich statements is missing in the given code below . import javax.sw ing.*; public 1 N A 2 f.SetVisible(true);
class FirstSw ingExample { public static void main ( String [] args) { Jframe f =new
Jframe();//creating instance of Jframe Jbutton b = new Jbutton ("click") ;// creating
instance of Jbutton b. setBounds( 130,100,100,40);//x axis ,y axis , w idth,height f.
add(b);//adding button in JFrame f.seSize(400,500);//400 w idth and
500 height f.setLayout (null);//using no layout manager }}
687 W hich statemnet is missing in follow ing code w hich w ill generate given output:: 1 Y1 A 2 MenuBar mbar=new MenuBar();
public class MenuDemo extends Frame { public static void main(String args[]) {
MenuDemo m=new MenuDemo(); m.setTitle("Menu Demo"); m.setVisible(true);
m.setSize(300,200);
********** //Setting the menu bar m.setMenuBar(mbar); //Creating menus Menu
format=new Menu("Format"); Menu Tool =new Menu("Tool"); Menu Help=new
Menu("Help"); //Creating menu items MenuItem
item1,item2,item3,item4,item5,item6; format.add(item1=new MenuItem("Font"));
format.add(item2=new MenuItem("Bullets")); format.add(item3=new
MenuItem("Paragraph")); Tool.add(item4=new MenuItem("Spelling and Grammar"));
Tool.add(item5=new MenuItem("W ord Count")); Help.add(item6=new
MenuItem("Help Topics")); //Adding menus to the menu bar mbar.add(format);
mbar.add(Tool); mbar.add(Help); } }
Figure:-
690 W hich w ill be correct line of code at line no 16 1. Application level 2. Import java.aw 1 N A 2 Container contentPane=getContentPane(
t.*; 3. Import javax.sw ing.*; 4. /* 5. <applet code=”JTextField1” w idth=300
height=50> 6. </applet> 7. */ 8. Public class JTextField 1 extends JApplet 9. { 10.
JTextField jtf; 11. Public void init() 12. { 13. JTextField jtf; 14. Public void init() 15. {
16. …………………
17. contentPane.setLayout(new Flow Layout()); 18. jtf=new
JTextField(15); 19. contentPane.add(jtf); 20. } 21. }
691 W hy w e need to w rite static keyw ord to main method ? 1 N U 2 To create single copy
692 W rite a java program for follow ing Output? Figure:- 1 Y1 A 2 import java.aw t.*; public class Butt exte
{ Butt MyBut=new Butt(); } Butt() { se
Layout(Flow Layout.CENTER)); Button He
ByeBut=new Button("Bye");
setSize(300,300); setVisible(true); } }
693 w rite the command to compile the follow ing code import java.aw t.*; import java.apple1 N A 2 javac Paneldemo.java
694 W rite the missing code? import javax.sw ing.*; public class Radio { JFrame f; 1 N A 2 f.add(r1); f.add(r2);
Radio(){ f=new JFrame(); JRadioButton r1=new JRadioButton("A) Male");
JRadioButton r2=new JRadioButton("B) FeMale"); r1.setBounds(50,100,70,30);
r2.setBounds(50,150,70,30); ButtonGroup bg=new ButtonGroup();
bg.add(r1);bg.add(r2); ------------
---------------------- ----------------------------- f.setSize(300,300); f.setLayout(null);
f.setVisible(true); } public static void main(String[] args) { new Radio(); } }
695 W rite the sequence of component to be added on applet ? import java.aw t.*; import ja1 N U 2 Label, TextField, TextField, Label, Button
697 you can use methods___________________on any instance of java.aw t.Component 1 N U 2 setBackground
701 __________ is a Sw ing layout manager that arranges components in a row & a column1 N U 2 BoxLayout
702 __________ is a w idget that displays progress of a lengthy task, for instance file dow n1 N U 2 Progressbar
703 ___________ is a Sw ing layout manager that arranges components on top of each oth1 N A 2 CardLayout
704 ______________ displays a message that alerts the user and w aits for the user to click1 N A 2 Message dialog box
e-Exam Manage Questions for Advanced Java Programming (17625) for topic 2 Go Back to Subjects
2 1. W hich of these packages contains all the classes and methods required for even handling in 2 N R 1 java.aw t.event
Java?
3 2. W hich of these events is generated w hen the a w indow is closed? 2 N R 1 W indow Event
5 3. W hich of these methods can be used to know the degree of adjustment made by the user? 2 N R 1 getValue()
7 A source generates an event and sends it to ___________ listeners that can handle the event 2 N R 1 One or more
13 An event is generated w hen the internal state of the event source is ___________. 2 N R 1 Changed
15 At the root of the Java event class hierarchy is ___________w hich is the superclass for all events. 2 N R 1 EventObject
24 Focus events are fired w henever a component _____________________the focus 2 N R 1 gains or loses
26 Generated w hen a w indow is activated, de-activated, closed, de-activated,de-iconified, iconified, opened or qu 2 N R 1 W indow Event
31 How to obtain the command name for invoking ActionEvent? 2 N R 1 Using getActionCommand( ) metho
32 How to remove the event listener? 2 N R 1 Using removeTypeListener( ) meth
33 If a class extends the ActionListener interface, it must contain a method called. __________. 2 N R 1 actionPerformed()
38 In java an event is an _________ w hich specifies the change of state in the source. 2 N R 1 Object
39 In Java, events are all the activities that occur betw een 2 N R 1 A and B
41 In w hich package the methods for receiving and processing events are defined 2 N R 1 java.aw t.event
42 In w hich places can put the event handling code 2 N R 1 All mentioned above
49 Name the event that gets generated w hen a button is clicked. 2 N R 1 ActionEvent
50 Name the method defined in EventObject class that returns the Object generated from the event.select the one 2 N R 1 getSource()
57 Text changed ( ) method is used for______. 2 N R 1 w hen there is changes in text occu
60 The constructor w hich the Text Event class defines. 2 N R 1 TextEvent(Object source, int event
66 The follow ing method is an abstract method of TextListener interface. 2 N R 1 textChanged(TextEvent obj)
67 The follow ing method must be overriden in order to handle KeyEvent. 2 N R 1 All of the mentioned
68 The method in the ActionEvent ________ returns the action command of the button 2 N R 1 getActionCommand()
69 The method that is used for registering keyboard event is know s as ____________________. 2 N R 1 addKeyListener ()
70 The MouseEvent class does not defines the _____________integer constant. 2 N R 1 MOUSE_W HEELMOVE
72 The MouseListener's _______________ method is called after mouse button is released 2 N R 1 public void mouseClicked(MouseEv
74 The signature for the registration method for an ActionEvent should be 2 N R 1 public void addActionListener(Actio
79 Till now tw o models have been introduced in java for: 2 N R 1 Receiving and processing events
82 W hat is a listener in the context to event handling? 2 N R 1 A listener is an object that notified
86 W hat kind of event is fired w hen the user selects an item from a menu? 2 N R 1 an ActionEvent
87 W hen a component obtains keyboard focus, w hich method is invoked? 2 N R 1 void focusGained(FocusEvent fe)
92 W hen tw o or more objects are added as listeners for the same event, w hich listener is first invoked to handle 2 N R 1 There is no w ay to
93 w hen w e need to use check boxes or item from the list or use a checkable menu,an 2 N R 1 ItemEvent
_________________is generated.
96 W hich among the follow ing is true for Adaptor Classes? 2 N R 1 Adaptor classes reduce Complexit
97 W hich are various methods of W indow Listener interface from follow ing? 2 N R 1 All above
98 W hich are W indow Event class defines integer constants ? 2 N R 1 All The Above
100 W hich class is used for this Processing Method processActionEvent( )? 2 N R 1 Button,List,MenuItem
107 W hich method does display the message w henever there is an item selection or deselection of the CheckboxMe2 N R 1 itemStateChanged
111 W hich method used for return for mouse co-ordinate ? 2 N R 1 getX () ,getY()
113 W hich of the follow ing are correct event handling methods 2 N R 1 mousePressed(MouseEvent e){}
116 W hich of the follow ing component can generate ItemEvent? 2 N R 1 CheckBoxMenuItem
117 W hich of the follow ing is not event class is Java? 2 N R 1 ClickEvent
118 W hich of the follow ing is the highest class in the event delegation class hierarchy? 2 N R 1 java.util.EventObject
119 W hich of the follow ing is the legal adapter classes in java. 2 N R 1 MouseAdapter
120 W hich of the follow ing Listeners have their Adapter class 2 N R 1 W indow Listener
121 W hich of the follow ing method is used to register a listener to a button ? 2 N R 1 addActionListener(ActionListener o
123 W hich of these methods can be used to obtain the command name for invoking ActionEvent object? 2 N R 1 getActionCommand
126 W hich of these are constants defined in W indow Event class 2 N R 1 All the Above
127 W hich of these constant value w ill change w hen the button at the end of scroll bar w as clicked to increase its2 N R 1 UNIT_INCREMENT
128 W hich of these event is generated w hen computer gains or loses input focus? 2 N R 1 FocusEvent
130 W hich of these events is generated w hen a w indow is minimized? 2 N R 1 Both a and b
131 W hich of these events is generated w hen the component is added or removed? 2 N R 1 ContainerEvent
132 W hich of these events w ill be generated if w e close an Frame's w indow ? 2 N R 1 W indow Event
136 W hich of these methods are used to determine the type of adjustment event? 2 N R 1 getAdjustmentType()
137 W hich of these methods are used to register a mouse motion listener? 2 N R 1 addMouseMotionListener().
138 W hich of these methods can be used to know the degree of adjustment made by the user? 2 N R 1 getValue()
140 W hich of these methods is used to get x coordinate of the mouse 2 N R 1 getX()
141 W hich of these methods is used to get Y coordinate of the mouse? 2 N R 1 getY()
142 W hich of these methods is used to know the full URL of an URL object? 2 N R 1 getHOst()
143 W hich of these methods is used to obtain the object that generated a ComponentEvent. 2 N R 1 getContainer()
144 W hich of these methods is used to obtain the object that generated a W indow Event? 2 N R 1 getW indow ()
146 W hich of these methods w ill respond w hen you click any button by mouse? 2 N R 1 All of the mentioned
147 W hich of these methods w ill respond w hen you click any button by mouse? 2 N R 1 All of these
149 W hich tw o parameters are required for JTable constructor to create a table? 2 N R 1 Data array and Column Headings
152 __________is generated w hen checkbox is clicked, list item is clicked, choice selection is made or checkable m2 N R 1 ItemEvent
153 ___________class provides an empty implementation of all methods in an Event Listener interface? 2 N R 1 Adapter
154 _________________generates an event and sends it to one or more listeners. 2 N R 1 Event Source
155 ActionEvent: It indicates the component-defined events occurred b)MouseEvent: Events generated during the m2 Y2 U 2 All a,b,c and d are
156 For the follow ing code select the method that can be used to handle event. importjava.aw t.event.*; import 2 N A 2 itemStateChanged(
java.aw t.*; 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
__________________(ItemEvent ie) { if(ie.getSource()==m1) setBackground(Color.red);
if(ie.getSource()==m2) setBackground(Color.green); } } /*<applet code=checkbackg.class height=150 w
idth=150> </applet>*/
157 1)For Key events, KeyEvent class is used 2)For Mouse motion events, MouseEvent class is used 2 N A 2 1,2,3 are true
3)For For Component events, CoumponentEvent class is used 4)For W indow events, W indow E
class is used
1. W hat w ill be the output of the follow ing code? import java.aw t.*; import java.applet.*; import
158 java.aw t.event.*; public class adm extends Applet { public void init() { addMouseMotionListener(new 2 Y2 U 2 S1-chapter2(Q1.C).
mma1(this)); } } class mma1 extends MouseAdapter { adm a; public mma1(adm a) { this.a=a; } public void
mouseDragged(MouseEvent me) { a.show Status("mouse dragged"); } } /*<applet code="adm" w idth=500
height=500>
</applet>*/
159 1.W hich line of code is missing in follow ing code and error statement code line import java.aw t.*; 2 N A 2 KeyListener and pu
import java.aw t.event.*; import java.applet.*; /*<applet code="KeyEventDemo.class" w idth=400 show Status("
height=400> </applet>*/ public class KeyEventDemo extends Applet implements
_____________ { String msg=""; public void init() { addKeyListener(this); } public void
keyPressed(KeyEvent e) { show Status("Key Dow n"); int key=e.getKeyCode(); repaint(); } public void
keyTyped(KeyEvent e) { msg+=e.getKeyChar(); repaint(); } public void paint(Graphics g) { g.draw
String(msg,10,20); } }
160 4. W hat w ill happen w hen you attempt to compile and run the follow ing code? import java.aw t.*; import jav 2 N A 2 Error not override M
161 5. W hich statement is incorrect or missing in the follow ing code import java.aw t.*; import java.aw t.event*; i 2 N A 2 Container c=getCon
162 A Frame's background color is set to Color.Yellow , and a Button's background color is to Color.Blue. Suppose th 2 N A 2 Color.Yellow .
167 Add the missing statement.. import java.aw t.*; import java.aw t.event.*; import java.applet.*; /* 2 N A 2 no=new Button(&q
<applet code="ButtonDemo" w idth=250 height=150> </applet> */ public class ButtonDemo extends Applet
implements ActionListener { String msg = ""; Button yes, no, maybe; public void init() { yes = new
Button("Yes"); maybe = new Button("Undecided"); add(yes); add(no); add(maybe);
yes.addActionListener(this); no.addActionListener(this); maybe.addActionListener(this); } public void
actionPerformed(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.draw String(msg, 6, 100); } }
168 After inserting w hich statement in follow ing program, output w indow w ill be closed w hen close button is 2 N A 2 addW indow Listene
clicked import java.aw t.event.*; import java.aw t.*; class Demo extends Frame { Demo() {
setSize(500,500); setVisible(true); setTitle("My W indow "); } public static void main(String args[]) { new
Demo(); } } class AdapterDemo extends W indow Adapter { Demo d1;
AdapterDemo(Demo d) { d1=d; } public void w indow Closing(W indow Event w e) { d1.dispose(); }
}
170 An event is generated w hen internal stae of event source is________ 2 N A 2 changed
Analyse the follow ing code and Find out errors. import java.aw t.*; import java.applet.*; import java.aw t.even
171 Select Color:"); Choice ch=new Choice(); ch.addItem("Red"); ch.addItem("Green"); ch.addItem("Blue"); TextFi 2 N A 2 Error is in the statement String s=
172 Analyse the follow ing code and find out missing statement. import javax.sw ing.*; import javax.sw 2 N A 2 missing package st
ing.tree.*; public class TreeDemo extends JFrame { public static void main(String args[])
{ TreeDemo frame = new TreeDemo(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root"); DefaultMutableTreeNode mercury =
new DefaultMutableTreeNode("Mercury"); root.add(mercury); DefaultMutableTreeNode venus = new
DefaultMutableTreeNode("Venus"); root.add(venus); DefaultMutableTreeNode mars = new
DefaultMutableTreeNode("Mars"); root.add(mars); JTree tree = new JTree(root); JScrollPane scrollPane = new
JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150);
frame.setVisible(true); } }
173 Analyse the follow ing code and select missing statement. import java.aw t.*; import java.applet.*; /*<applet c2 N A 2 All of the above
174 Analyze the follow ing code import javax.sw ing.*; import javax.sw ing.border.*; import java.aw t.*; public clas2 N A 2 Tw o buttons displa
175 Analyze the follow ing code: import javax.sw ing.*; import java.aw t.*; public class Test extends JFrame { publ 2 N U 2 Four buttons are di
177 Choose correct fig. as ouput for given code import java.aw t.*; import java.applet.*; import java.aw 2 Y2 A 2
t.event.*; public class addition2 extends Applet implements ActionListener { TextField t1; TextField t2;
TextField t3; Button b; {Label num1=new Label ("Addition of tw o numbers"); Label num2=new Label("Enter
First no in text field"); Label num3=new Label("Enter Second no in text field"); t1=new TextField(); t2=new
TextField(); t3=new TextField(); b=new Button("add"); setLayout(new GridLayout(4,2)); add(num1);
add(t1); add(num2); add(t2); add(num3); add(t3); add(b); b.addActionListener(this); } public void
actionPerformed(ActionEvent ae)
{if(ae.getSource()==b) { int n1=Integer.parseInt(t2.getText()); int n2=Integer.parseInt(t3.getText()); int
sum=n1+n2; t1.setText(Integer.toString(sum)); } } } /*
<applet code="addition1" height=200 w idth=300> </applet>*/
178 Choose the correct missing statement from the given code import java.aw t.*; import java.applet.*; import java2 N A 2 b1.addActionListene
Choose the correct option for the given code import java.aw t.*; import java.aw t.event.*; import java.applet.*; The program w ill d
Complete remaining code for getting output as show n in figure. import java.aw t.*; import
java.aw t.event.*; import javax.sw ing.*; /*<applet code="jcombodemo" w idth=300 height=100>
</applet>*/ public class jcombodemo extends JApplet implements ItemListener { JLabel jl;
ImageIcon green, red, black, yellow ; public void init() { Container cp = getContentPane();
JComboBox jc = new JComboBox(); jc.addItem("Creek"); jc.addItem("Dock");
jc.addItem("Forest"); jc.addItemListener(this); cp.add(jc); jl = new JLabel(new
ImageIcon("Creek.jpg")); cp.add(jl); } Figure:-
190 Component listener can not be applicable to 2 N U 2 Frame, Label
191 Consider follow ing code and state how many keyevent generated by this program import java.aw t.event.*; 2 N A 2 3
import javax.sw ing.*; /* <applet code="KeyDemo.class " w idth=300 height=300> </applet> */ public
class KeyDemo extends JApplet implements KeyListener { String msg=""; int x=10,y=20; public void init() {
addKeyListener(this); requestFocus(); } public void keyPressed(KeyEvent ke) { show Status("Key Dow n"); }
public void keyTyped(KeyEvent ke)
{ msg+=ke.getKeyChar(); repaint(); } public void keyReleased(KeyEvent ke) { show Status("Key up"); }
public void paint(Graphics g) { g.draw String(msg,x,y); } }
192 Consider follow ing output. Find missing statement from follow ing code. import java.aw t.*; import 2 Y1 A 2 D. Missing{}
java.applet.*; import java.aw t.event.*; public class keyEp extends Applet implements KeyListener { String
msg=" "; int x=10, y=20; public void init() { addKeyListener(this); } public void keyPressed(KeyEvent k) {
show Status("key pressed"); int kl=k.getKeyCode(); sw itch(kl) { case KeyEvent.VK_LEFT: msg+="<left
arrow >"; break; case KeyEvent.VK_RIGHT: msg+="<right arrow >"; break; } repaint(); } public void
keyReleased(KeyEvent k) { show Status("key up"); } public void keyTyped(KeyEvent l) public void
paint(Graphics g) { g.draw String(msg,x,y); } }
Figure:-
193 Consider the follow ing code and identify the error. import java.aw t.*; import javax.sw ing.*; 2 N A 2 Error in statement
import javax.sw ing.JScrollPane; /*<applet code=”JScrollPane1” w idth=150 height=150>
</applet> */ public class JSCrollPane1 extends JApplet { public void init() { Container cp=getContentPane();
contentPane.setLayout(new BorderLayout()); JPanel jp=new JPanel(); jp.setLayout(new GridLayout(10,10));
Char b=’A’; for(int i=0;i<5;i++) { for(int j=0;j<5;j++) { jp.add(new JButton(“Button”+b)); ++b; } } int
v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h=
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPane jsp=new JScrollPane(v,h);
cp.add(jsp,BorderLayout.CENTER); } }
194 Consider the follow ing code. Event handling doesn't w ork on the button because of the follow ing reason: impo2 N A 2 The action listener
197 Consider the follow ing code.w hat w ill be output of code? import java.applet.*; import java.aw t.*; import java2 Y2 A 2 All of these
198 Consider the follow ing output,Find the missing Statement in program import java.aw t.*; import 2 Y1 A 2 public void mouseR
java.applet.*; import java.aw t.event.*; public class MouseEvent1 extends Applet implements
MouseListener,MouseMotionListener { String msg=" "; int mx=0,my=0; public void init() {
addMouseListener(this); addMouseMotionListener(this); } public void mouseClicked(MouseEvent me) {
mx=0; my=10; msg="mouse clicked"; repaint(); } void mouseEntered(MouseEvent me) { mx=0; my=10;
msg="mouse entered"; repaint(); } public void mousePressed(MouseEvent me) { mx=me.getX();
my=me.getY(); msg="mouse pressed"; repaint(); } { mx=me.getX(); my=me.getY(); msg="mouse
Released"; repaint(); } public void mouseExited(MouseEvent me) { mx=0; my=10; msg="mouse Exited";
repaint(); } public void mouseDragged(MouseEvent me) { mx=me.getX(); my=me.getY(); msg="*"; show
Status("Dragging mouse at"+mx+","+my); repaint(); } public void mouseMoved(MouseEvent me) {
mx=me.getX(); my=me.getY(); show Status("moving mouse at"+mx+","+my); repaint(); } public void
paint(Graphics g) { g.draw String(msg,mx,my); } } /* <applet code=MouseEvent1.class height=400 w
idth=300>
</applet>*/ S1Q47.jpg
Figure:-
199 Consider the follow ing output. Find the missing statement in the program show n by 2 N A 2 public void keyPres
____________. import java.aw t.*; import java.aw t.event.*; import java.applet.*; import javax.sw ing.*; /*
<applet code="SimpleKey1" w idth=300 height=100> </applet> */ public class SimpleKey1 extends JApplet
implements KeyListener { String msg = ""; int X = 10, Y = 20; public void init() { addKeyListener(this);
requestFocus(); } ___________________ { show Status("Key Dow n"); } public void keyReleased(KeyEvent
ke) { show Status("Key Up"); public void keyTyped(KeyEvent ke) { msg += ke.getKeyChar(); repaint(); }
public void paint(Graphics g) { g.draw String(msg, X, Y); } }
200 Consider the follow ing output. Find the missing statement in the program. import java.aw t.*; import java.aw t2 N A 2 {
201 Consider the follow ing output. Find the missing statement in the program. import java.aw t.*; import java.aw 2 Y1 A 2 repaint();
t.event.*; import java.applet.*; import javax.sw ing.*; /* <applet code="SimpleKey1" w idth=300
height=100> </applet> */ public class SimpleKey1 extends JApplet implements KeyListener { String msg =
""; int X = 10, Y = 20; public void init() { addKeyListener(this); requestFocus(); } public void
keyPressed(KeyEvent ke) { show Status("Key Dow n"); } public void keyReleased(KeyEvent ke) { show
Status("Key Up"); } public void keyTyped(KeyEvent ke) { msg += ke.getKeyChar(); } public void
paint(Graphics g) { g.draw String(msg, X, Y); } }
Figure:-
202 Consider the follow ing output. Find the missing statement in the program. import java.aw t.*; import java.aw 2 Y1 A 2 }
t.event.*; import java.applet.*; import javax.sw ing.*; /* <applet code="SimpleKey1" w idth=300
height=100> </applet> */ public class SimpleKey1 extends JApplet implements KeyListener { String msg =
""; int X = 10, Y = 20; public void init() { addKeyListener(this); requestFocus(); } public void
keyPressed(KeyEvent ke) { show Status("Key Dow n"); } public void keyReleased(KeyEvent ke) { show
Status("Key Up"); public void keyTyped(KeyEvent ke) { msg += ke.getKeyChar(); repaint(); } public void
paint(Graphics g) { g.draw String(msg, X, Y); } }
Figure:-
Consider the follow ing output. Find the missing statement in the program. import java.aw t.*;
203 import java.aw t.event.*; import java.applet.*; import javax.sw ing.*; /* <applet code="SimpleKey1" w 2 Y1 A 2 All of the Above
idth=300 height=100> </applet> */ public class SimpleKey1 extends JApplet implements KeyListener {
String msg = ""; int X = 10, Y = 20; public void init() { addKeyListener(this); requestFocus(); } public void
paint(Graphics g) { g.draw String(msg, X, Y);
} } Figure:-
204 Consider the follow ing output. Find the missing statement in the program. import javax.sw ing.*; 2 N A 2 getContentPane().a
/* <applet code="JTabbedPaneDemo" w idth=400 height=100> </applet> */ public class JTabbedPaneDemo
extends JApplet { public void init() { JTabbedPane jtp = new JTabbedPane(); jtp.addTab("Cities", new
CitiesPanel()); jtp.addTab("Colors", new ColorsPanel()); jtp.addTab("Flavors", new FlavorsPanel()); } } class
CitiesPanel extends JPanel { public CitiesPanel() { JButton b1 = new JButton("New York"); add(b1); JButton
b2 = new JButton("London"); add(b2); JButton b3 = new JButton("Hong Kong"); add(b3); JButton b4 = new
JButton("Tokyo"); add(b4); } } class ColorsPanel extends JPanel { public ColorsPanel()
{JCheckBox cb1 = new JCheckBox("Red"); add(cb1); JCheckBox cb2 = new JCheckBox("Green");
add(cb2); JCheckBox cb3 = new JCheckBox("Blue"); add(cb3); } }
205 Consider the follow ing output. Find the missing statement in the program. import java.aw t.*; import java.aw 2 Y1 A 2 addKeyListener(this
t.event.*; import java.applet.*; /* <applet code="SimpleKey" w idth=300 height=100> </applet> */ public
class SimpleKey extends Applet implements KeyListener { String msg = ""; int X = 10, Y = 20; // output
coordinates public void init() { } public void keyPressed(KeyEvent ke) { show Status("Key Dow n"); } public
void keyReleased(KeyEvent ke) { show Status("Key Up"); } public void keyTyped(KeyEvent ke) { msg +=
ke.getKeyChar(); repaint(); } // Display keystrokes. public void paint(Graphics g) { g.draw String(msg, X, Y);
}}
Figure:-
Consider the follow ing output. Find the missing statement in the program. import java.aw t.Frame; import java
206 e.getX(); y = getY(); repaint(); } public void paint(Graphics g){ g.draw String(strEvent + " at " + x 2 Y1 A 2 all of the Above
+ "," + y, 50,50); } public static void main(String[] args) { HandleMouseListenerInW indow Example myW
indow = new HandleMouseListenerInW indow Example("W indow W ith Mouse Events Example"); } } class
MyW indow Adapter extends W indow Adapter{ HandleMouseListenerInW indow Example myW indow = null;
MyW indow Adapter(HandleMouseListenerInW indow Example myW indow ){ this.myW indow = myW indow ;
} public void w indow Closing(W indow Event w e){ myW indow .setVisible(false); }
Figure:-
207 Consider the follow ing program W hat correction should be done in the program to get correct output? import 2 N A 2 Missing }
java.applet.*; import java.aw t.event.*; /* <APPLET Code="SimpleKey" W idth=200 Height=250>
</APPLET> */ public class SimpleKey extends Applet implements KeyListener { String msg=""; int
X=10,Y=20; public void init() { addKeyListener(this); requestFocus(); } public void keyPressed(KeyEvent ke)
{ show Status("Key Dow n"); } public void keyReleased(KeyEvent ke) { show Status("Key Up"); } public void
keyTyped(KeyEvent ke) { msg
+=ke.getKeyChar(); repaint(); } public void paint (Graphics g) { }
208 Consider the follow ing program Find the error in program to get correct output. import java.applet.*; import jav2 N A 2 Error in mymouseli
209 Consider the follow ing program and find out the method w hich is w rong and correct it /*<applet 2 N A 2 The method public
code=TextAreaDemo w idth=300 height=300> </applet>*/ import java.aw t.*; import java.aw t.event.*; public void textCha
import java.applet.*; public class TextAreaDemo extends Applet implements FocusListener,TextListener {
TextArea text=new TextArea("AW T stands for Abstract W indow ToolKit"); TextField tf=new TextField();
public void init() { add(text); add(tf); text.addFocusListener(this); text.addTextListener(this); } public void
focusGained(FocusEvent e)
{ show Status("TextArea got focus"); } public void focusLost(FocusEvent e) { show Status("TextArea lost
focus"); } public void valueChanged(TextEvent e) { show Status("change in value of textarea"); } }
210 Consider the follow ing program and identify the missing statement. import java.applet.Applet; import java.aw t2 N A 2 None of the above.
show Status("Dragging mouse at " + mouseX + ", " + mouseY); repaint(); } public void mouseMoved(MouseEve
211 Consider the follow ing program. W hat should be the correction done in the program to get correct output? /* <2 N A 2 missing import stat
212 Consider the follow ing program. Choose the missing statements to get correct output. import java.aw t.*; impo2 N A 2 public class Sample
year.addItemListen
itemStateChanged(
213 Consider the follow ing program. Find w hich statement contains error. import java.aw t.*; import java.aw 2 N A 2 Applet Tag not decl
t.event.*; import java.applet.*; public class choicedemo1 extends Applet implements ItemListener { Choice
os,brow ser; String msg=""; public void init() { os=new Choice(); brow ser
=new Choice(); os.add("w indow s7"); os.add("w indow sXP"); os.add("w indow s8"); os.add("w indow s98");
brow ser.add("netscape 3.x"); brow ser.add("netscape 4.x"); brow ser.add("netscape 5.x"); brow
ser.add("netscape 6.x"); brow ser.add("Internet Explorer
4.0"); brow ser.add("Internet Explorer 5.0"); brow ser.add("Internet Explorer 6.0"); brow ser.add("Lynx
2.4"); brow ser.select("Netscape 4.x"); add(os); add(brow ser); os.addItemListener(this); brow
ser.addItemListener(this); } public void itemStateChanged(ItemEvent ie) { repaint(); } public void
paint(Graphics g) { msg="Current os"; msg+=os.getSelectedItem(); g.draw String(msg,6,120);
msg="Current brow ser"; msg+=brow ser.getSelectedItem(); g.draw String(msg,6,140); } }
214 Consider the follow ing program. Find w hich statement contains error. import java.applet.*; import java.aw t.* 2 N A 2 error in the stateme
called
215 Consider the follow ing program. Identify the missing statement from the output. import java.applet.*; /* 2 N A 2 }
<applet code="ChoiceDemo" w idth=300 height=180> </applet> */ public class ChoiceDemo extends Applet
implements ItemListener { Choice os, brow ser; String msg = ""; public void init() { os = new Choice(); brow
ser = new Choice(); // add items to os list os.add("W indow s XP"); os.add("W indow s Vista");
os.add("Solaris"); os.add("Mac OS"); // add items to brow ser list brow ser.add("Internet Explorer"); brow
ser.add("Firefox"); brow ser.add("Opera"); // add choice lists to w indow add(os); add(brow ser); // register
to receive item events os.addItemListener(this); brow ser.addItemListener(this); } public void
itemStateChanged(ItemEvent ie) { repaint(); } // Display current selections. public void paint(Graphics g) {
msg = "Current OS: "; msg += os.getSelectedItem(); g.draw String(msg, 6,
120); msg = "Current Brow ser: "; msg += brow ser.getSelectedItem(); g.draw String(msg, 6,
140); }
consider the follow ing program. Identify w hich are the event need to get the correct output import java.aw
t.*; import java.aw t.event.*; class AEvent extends Frame implements
____________ { TextField tf; AEvent(){ tf=new TextField(); tf.setBounds(60,50,170,20); Button b=new
Button("click me"); b.setBounds(100,120,80,30); b._______________(this); add(b);add(tf);
setSize(300,300); setLayout(null); setVisible(true); } public void
_________________(__________ e) { tf.setText("W elcome"); } public static void main(String args[]){ new
AEvent(); } }
Figure:-
216 2 Y1 A 2 ActionListener, add
217 Consider the follow ing program. W hat should be the correction done in the program to get colored button 2 N A 2 b1.setBackground(C
output?. import java.aw t.*; import java.applet.*; public class colordemo extends Applet { Button b1; Color c;
public void init() { c=new Color(255,0,0); setBackground(c); Button b1=new Button("Click");
b.setBackground(Color.yellow ); setForeground(Color.green); add(b1); }
} /*<applet code="colordemo" height=150 w idth=150> </applet>*/
218 Consider the follow ing program. W hat should be the correction done in the program to see output?. import 2 N A 2 add(txtpsw d);
java.aw t.*; import java.applet.*; import java.aw t.event.*; public class authenticateuser extends Applet
implements ActionListener { Label lblname,lblpsw d,lblmsg; TextField txtname,txtpsw d; Button b1; String
msg=""; public void init() { lblname= new Label("Enter username:"); lblpsw d= new Label("Enter psw d:");
lblmsg= new Label(""); txtname= new TextField(8); txtpsw d= new TextField(8); b1=new Button("Submit");
setLayout(new GridLayout(3,2)); add(lblname); add(txtname); add(lblpsw d); add(b1); add(lblmsg);
b1.addActionListener(this); } public void actionPerformed(ActionEvent e) { if (txtpsw
d.getText().equals("1234")) lblmsg.setText("Hello "+txtname.getText() ); else lblmsg.setText("Invalid user");
} } /*<applet code = authenticateuser height=200 w idth=200>
</applet>*/
219 Consider the follow ing program. W hat should be the correction done to get correct output? import java.aw 2 N A 2 import java.aw t.*;
t.*; import java.aw t.event.*; import java.applet.*; public class Sample extends Applet implements class Sample exten
ItemListener { Button red, green, blue; public void init() { red=new Button("Red"); green=new green, blue; public
Button("Green"); blue=new Button("Blue"); add(red); add(green); add(blue); red.addItemListener(this); green=new Button(
green.addItemListener(this); blue.addItemListener(this); Button("Blue&
} public void itemStateChanged(ItemEvent ie) { if(ie.getSource()==red) { setBackground(Color.red); }
if(ie.getSource()==green) { setBackground(Color.green); } if(ie.getSource()==blue) {
setBackground(Color.blue); } } }
220 Consider the follow ing program. W hat w ill be displayed in the output? import java.aw t.*; import java.aw 2 N A 2 compile error
t.event.*; import java.applet.*; /* <applet code="MouseEvents" w idth=300 height=100> </applet> */
public class MouseEvents extends Applet implements MouseListener, MouseMotionListener { String msg = "";
int mouseX = 0, mouseY = 0; // coordinates of mouse public void init() { addMouseListener(this);
addMouseMotionListener(this); } public void mouseClicked(MouseEvent me){ mouseX = 0; mouseY = 10;
msg = "Mouse clicked."; repaint(); }
public void mouseMoved(MouseEvent me) { show Status("Moving mouse at " + me.getX() + ", " +
me.getY()); } public void paint(Graphics g) { g.draw String(msg, mouseX, mouseY); } }
221 Consider the follow ing program.Find the listener implemented by applet. import java.aw t.*; 2 N A 2 Both B and C
import java.aw t.event.*; import java.applet.*; /* <applet code="Loan" w idth=200 height=300>
</applet> */ public class Loan extends Applet implements
_________________________________ { double p,r,n,total,i; String param1; boolean month; Label
l1,l2,l3,l4; TextField t1,t2,t3,t4; Button b1,b2; CheckboxGroup cbg; Checkbox c1,c2; String str; public void
init() { l1=new Label("Balance Amount",Label.LEFT); l2=new Label("Number of Months",Label.LEFT); l3=new
Label("Interest Rate",Label.LEFT); l4=new Label("Total Payment",Label.LEFT); t1=new TextField(5); t2=new
TextField(5); t3=new TextField(15); t4=new TextField(20); b1=new Button("OK"); b2=new Button("Delete");
cbg=new CheckboxGroup(); c1=new Checkbox("Month Rate",cbg,true); c2=new Checkbox("Annual
Rate",cbg,true); t1.addActionListener(this); t2.addActionListener(this); t3.addActionListener(this);
t4.addActionListener(this); b1.addActionListener(this); b2.addActionListener(this); c1.addItemListener(this);
c2.addItemListener(this); add(l1); add(t1); add(l2); add(t2); add(l3); add(t3); add(l4); add(t4); add(c1);
add(c2); add(b1); add(b2); } public void
229 public MyChoice() { enableEvents(AW TEvent.ITEM_EVENT_MASK); } protected void 2 Y1 A 2 import java.aw t.ev
processItemEvent(ItemEvent ie) { //show Status("Choice selection: " + getSelectedItem());
super.processItemEvent(ie); }
Figure:-
230 Find Error in follow ing code nd select correct code : import java.io.*; import java.aw t.*; import java.aw 2 N A 2 import java.io.*; im
t.event.*; import java.applet.*; public class choiceeve extends Applet implements ItemListener {String m=" java.applet.*; publ
"; Choice os; public void init() {os=new Choice(); os.add("W indow s ItemListener {Strin
98"); os.add("W indow s XP"); os.add("W indow s Vista"); add(os); os.addItemListener(this); } public void {os=new Choice();
itemValueChanged(ItemEvent e) {repaint(); } public void paint(Graphics g) { m="Selected os.add("W ind
OS:"+os.getSelectedItems(); g.draw String(m,10,60); } } /*<applet code="choiceeve.class" w idth=400
height=300> </applet> */
231 Find error in follow ing program. import java.aw t.*; import java.applet.*; /*<applet code="choicedemo" w idth2 N A 2 both A and B
232 Find missing Lines in follow ing Program. import java.aw t.*; import java.io.*; import java.aw t.event.*; 2 Y1 U 2 public void keyType
import java.applet.*; public class ex7 extends Applet implements KeyListener
{ String msg =""; int X=10,Y=20; public void init() { addKeyListener(this); requestFocus(); } public void
keyPressed(KeyEvent k) { show Status("KeyDow n"); int key=k.getKeyCode(); sw itch(key) { case
KeyEvent.VK_UP: show Status("UP KEY PRESSED"); break; } repaint(); } public void keyReleased(KeyEvent
k) { show Status("Key Up"); } public void paint(Graphics g) { g.draw String(msg,X,Y); } } /* <applet code
=ex7 w idth =500 height =500> </applet> */
Figure:-
233 Find missing statement in given code: import java.io.*; import java.aw t.*; import java.aw t.event.*; import ja 2 N A 2 = missing
234 Find missing statements in order from top to end of the program import java,aw t*; import java.aw t.event.*; 2 N A 2 ActionListener
import java.applet.*; public class RadioDemo extends JApplet implements ,addActionListener,
______________ { public void init() { Container c=getContentPane(); JRadioButton b1=new
JRadioButton("Red"); JRadioButton b2=new JRadioButton("Blue"); b1.add_________________(this);
b2.add___________________(this); c.add(b1); c.add(b2); ButtonGroup bg=new ButtonGroup(); bg.add(b1);
bg.add(b2); } public void _____________ { }
}
235 find out missing statement in follow ing code import java.aw t.*; import javax.sw ing.*; import java.applet.*; 2 N U 2 All of these
public class ass1 extends JApplet implements ItemListener { JTextAreajtf; JComboBoxjb; public void init() {
Container ContentPane=getContentPane(); ContentPane.setLayout(new Flow Layout()); String alpha[]=
{"A","B","C","D","E","F","G","H","I","J","K","L"}; JComboBox jb=new JComboBox(alpha);
ContentPane.add(jb); jtf=new JTextArea(20,10); } public void itemStateChanged(ItemEvent IE)
{ String str=(String)IE.getItem(); jtf.append(str); } } /*<applet code="ass1.class" w idth="400"
height="500" ></applet>*/
236 Find out the Error statement import java.applet.*; import java.aw t.event.*; /* <applet 2 N A 2 addMouseListener(n
code="InnerClassDemo" w idth=200 height=100> </applet> */ public class InnerClassDemo extends Applet
{ public void init() { addMouseListener(new MyMouseAdapter()); } class MyMouseAdapter { public void
mousePressed(MouseEvent me) { show Status("Mouse Pressed");
}}}
237 find out the errors in the follow ing code if any and correct them: import java.aw t.event.*; /* 2 N A 2 public void mouseP
<applet code =" AdapterDemo" height = 250 w idth =350 ></applet>*/ public class Adapter Demo extends
Applet { public void init () { addMouseListener ( new Mouse Adapter() { int topX, bottom Y; public void
Mousepressed ( Mouseevent me) { topX = me.getX(); bottom Y me.get Y ();
} public void mouse Released ( MouseEvent me ) Graphics g = AdapterDemo. this getGraphics (
0; g. draw Rect( topX, bottomY, me.GetX()-topX, me. get Y ()-bottomY); } } ); } }
238 Find out the missing statement show n by _______________in the follow ing code import java.aw t.event.*; im2 N A 2 addMouseListener(n
239 Find out the missing statements show n by _____________in the follow ing code. import java.aw t.*; import ja 2 N A 2 Frame, W indow Ad
240 Find out w hich listener is used in follow ing program:import java.aw t.*; import java.aw t.event.*; import java.2 N A 2 ActionListener
241 Find the error in the code public void itemStateChanged(ItemEvent ie) { 2 N A 2 No error
l.setText(c.getSelectedItem()); }
Find the error in the follow ing code import java.aw t.*; import java.applet.*; public class Demo extends Apple
242 Button(); add(b); b.addActionListener(); } public void actionEvent(Event ae) { 2 N A 2 2 and 4 is true
show Status(“Button clicked”); } } 1) Button constructor is w rong 2) Error is addActionListener method
3)ActionListener method should be public void actionPerformed(Event ar) 4)ActionListener method should be
public void actionPerformed(ActionEvent ae)
243 Find the missing at ******** in follow ing code. import java.aw t.*; import java.applet.*; import java.aw 2 N A 2 Key
t.event.*; public class key extends Applet implements *******Listener { String msg=" "; public void init() {
addKeyListener(this); } public void keyPressed(KeyEvent k) {
show Status("key pressed"); } public void keyReleased(KeyEvent k) { show Status("key released"); } public
void keyTyped(KeyEvent k) { show Status("key typing"); } public void paint(Grapics g) { g.draw
String(msg,80,100); } } /*<applet code="Key" w idth=600 height=600>
</applet> */
244 find the missing method follow ing given code import java.aw t.*; import java.aw t.event.*; public class 2 N A 2 w indow Closing()
ButtonTest3 { public static void main(String[] args) { Frame f = new ButtonTestFrame("Button Test");
f.setSize(150, 100); f.setVisible(true); } } class ButtonTestFrame extends Frame { public
ButtonTestFrame(String title) { super(title); setLayout(new Flow Layout()); Button b = new Button("Close w
indow "); add(b); b.addActionListener(new ButtonListener()); addW indow Listener(new W indow Closer()); }
} class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent evt) {
System.exit(0); } } class W indow Closer extends W indow Adapter { public void
____________(W indow Event evt) { } }
245 Find the missing statement for getting follow ing output import java.aw t.*; import javax.sw ing.*; import 2 Y1 A 2 b1=new JButton(i1
java.aw t.event.*; public class Sw ing_Demo1 extends JApplet implements ActionListener { JButton
b1,b2,b3,b4; JTextField t1; public void init() { Container c=getContentPane(); c.setLayout(new
GridLayout(3,3)); t1=new JTextField(20); c.add(t1); ImageIcon i1=new ImageIcon("Sunset.jpg"); ImageIcon
i2=new ImageIcon("Blue hills.jpg"); ImageIcon i3=new ImageIcon("W inter.jpg"); ImageIcon i4=new
ImageIcon("W ater lilies.jpg"); b2=new JButton(i2); b3=new JButton(i3); b4=new JButton(i4);
b1.setActionCommand("Sunset image"); b2.setActionCommand("Blue hills"); b3.setActionCommand("W
inter"); b4.setActionCommand("W ater lilies"); b1.addActionListener(this); b2.addActionListener(this);
b3.addActionListener(this); b4.addActionListener(this); c.add(b1); c.add(b2); c.add(b3); c.add(b4); } public
void actionPerformed(ActionEvent ae) { if(ae.getSource()==b1) t1.setText(b1.getActionCommand());
if(ae.getSource()==b2) t1.setText(b2.getActionCommand()); if(ae.getSource()==b3)
t1.setText(b3.getActionCommand()); if(ae.getSource()==b4) t1.setText(b4.getActionCommand()); } }
Figure:-
246 Find the missing statement in the program. /* <APPLET Code="InnerClassDemo" W idth=200 2 N A 2 Missing semicolon
Height=250> </APPLET> */ public class InnerClassDemo extends Applet { public void init() {
addMouseListener(new MyMouseAdapter()); } class MyMouseAdapter extends MouseAdapter { public void
mousePressed(MouseEvent me) { show Status("Mouse Pressed") } } } }
247 Find the missing statement in the program. import java.applet.Applet; import java.aw t.*; import java.aw t.eve 2 N A 2 implements ActionL
textarea1.insert(msg, 0); } } }
248 Find the statement in w hich there is error import java.aw t.*; import java.applet.*; import java.aw t.event.*; 2 N U 2 barr.addActionListe
/*<applet code="DemoButton.class" height=500 w idth=500></applet>*/ public class DemoButton extends
Applet implements ActionListener { String msg= " "; Button barr[]=new Button[3]; public void init() { Button
yes=new Button ("YES"); Button no=new Button ("No"); Button undecided=new Button ("UNDECIDED");
barr[0]=(Button)add(yes); barr[1]= (Button)add(no); barr[2]=(Button)add(undecided); for(int i=0;i<3;i++)
{ barr.addActionListener(this); } } public void actionPerformed(ActionEvent ae) { for(int i=0;i<3;i++) {
if(ae.getSource()==barr[i]) { msg=" You Pressed "+ barr[i].getLabel(); }//if end
}//for end repaint(); }//method end public void paint(Graphics g) { g.draw String(msg ,100,100);
}}
249 follow ing code select the method that can be used to handle event. import java.aw t.event.*; import java.aw 2 N A 2 itemStateChanged(
t.*; 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
__________________(ItemEvent ie) { if(ie.getSource()==m1) setBackground(Color.red);
if(ie.getSource()==m2) setBackground(Color.green); } } /*<applet code=checkbackg.class height=150 w
idth=150>
</applet>*
250 follow ing is an example of w hat? Frame f=new Frame(“MyFrame”); f.addW indow Listener(new 2 N U 2 Code show s the us
W indow Adapter() { public void w indow Closing(W indow Event w e) {System.exit(0);}});
251 Follow ing program is the example of import java.applet.*; import java.aw t.event.*; /* <applet 2 N A 2 Inner class
code="ClassDemo" w idth=200 height=100> </applet> */ public class ClassDemo extends Applet
{public void init() { addMouseListener(new MyMouseAdapter()); } class MyMouseAdapter extends
MouseAdapter { public void mousePressed(MouseEvent me) { show Status("Mouse Pressed"); } } }
252 For displaying coordinates of moving mouse pointer on status bar of applet, in follow ing programs w hich statem
2 N A 2 repaint() in public v
253 For the follow ing code select correct statements to complete the code. import java.aw t.*; import 2 N A 2 ActionListener , act
java.applet.*; import java.aw t.event.*; /*<applet code=demo w idth=100 height=100>
</applet> */ public class demo extends Applet implements ____________ { Label l1,l2; Button b1; String
msg=""; public void init() { l1=new Label("Label 1"); l2=new Label("Label 2"); b1=new Button("Enter");
add(l1); add(l2); add(b1); b1.addActionListener(this); } public void
____________________________ { msg="U Have Pressed Enter Button"; repaint(); } public void
paint(Graphics g) { g.draw String(msg,100,100); } }
254 For the follow ing code select the appropriate method. import java.aw t.*; import java.aw t.event.*; import java2 N A 2 getActionCommand
For the follow ing code select the listener implemented by class import java.aw t.*; import java.aw t.event.*;
import javax.sw ing.*; /* <applet code="JRadioEvent" w idth=300 height=100>
</applet> */ public class JRadioEvent extends JApplet implements ______________ { ButtonGroup grp;
JRadioButton red,pink,green; JTextArea ta; public void init() { setLayout(new
255 Flow Layout()); ta=new JTextArea(5,10); setupButtons(); addListeners(); add(red); add(pink); add(green); add2 N A 2 ActionListener
256 For the follow ing code select the method that can be used to handle event import java.aw t.*; import 2 N A 2 adjustmentValueCh
java.aw t.event.*; import java.applet.*; /* <applet code="ScrollBbar1" w idth=300 height=200> </applet>
*/ public class ScrollBbar1 extends Applet implements AdjustmentListener { String msg = ""; Scrollbar red,
blue,green; int r,g,b; Color c; public void init() { int max=255; c = new Color(0,0,0); setBackground(c); red
= new Scrollbar(Scrollbar.HORIZONTAL,0, 1, 0, max); green = new Scrollbar(Scrollbar.HORIZONTAL,0, 1,
0, max); blue = new Scrollbar(Scrollbar.HORIZONTAL,0, 1, 0, max); add(red); add(green); add(blue); //
register to receive adjustment events red.addAdjustmentListener(this); green.addAdjustmentListener(this);
blue.addAdjustmentListener(this); } public void
_____________________________ { r=red.getValue(); g=green.getValue();
b=blue.getValue(); c = new Color(r,g,b); setBackground(c); } }
257 For the follow ing code select the method that can be used to handle event import java.aw t.*; import 2 Y1 A 2 actionPerformed(Ac
java.aw t.event.*; class AEvent extends Frame implements ActionListener{ TextField tf; AEvent(){ tf=new
TextField(); tf.setBounds(60,50,170,20); Button b=new Button("click me"); b.setBounds(100,120,80,30);
b.addActionListener(this); add(b);add(tf); setSize(300,300); setLayout(null); setVisible(true); } public void
actionPerformed(ActionEvent e){ tf.setText("W elcome"); } public static void main(String args[]){ new
AEvent(); } }
Figure:-
258 For the follow ing code select the method that can be used to handle event import java.aw t.*; import java.appl2 N A 2 itemStateChanged(
259 For the follow ing code select the method that can be used to handle event so that w e get proper output. 2 N U 2 adjustmentValueCh
import java.aw t.*; import java.aw t.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" w idth=300
height=300></applet>*/
260 For the follow ing code select the method that can be used to handle event, and to get the output given in the 2 Y1 U 2 keyTyped(KeyEven
figure. import java.applet.*; import java.aw t.*; import java.aw t.event.*; public class DemoKeyEvent
extends Applet { char ch; public void init() { this.addKeyListener(new KeyAdapter() { public
void______________________________ { ch=ke.getKeyChar(); repaint(); } }); } public void paint(Graphics
g) { g.draw String("Character pressed is: "+ch,100,100); } } /*<applet code="DemoKeyEvent.class" w
idth=300 height=300></applet>*/
Figure:-
261 For the follow ing code select the method that can be used to handle event. import java.aw t.*; import 2 N A 2 adjustmentValueCh
java.aw t.event.*; import java.applet.*; /* <applet code="SBDemo" w idth=300 height=200> </applet> */
public class SBDemo extends Applet implements AdjustmentListener, MouseMotionListener { String msg = "";
Scrollbar vertSB, horzSB; public void init() { int w idth = Integer.parseInt(getParameter("w idth")); int height
= Integer.parseInt(getParameter("height")); vertSB = new Scrollbar(Scrollbar.VERTICAL,0, 1, 0,
height); horzSB = new Scrollbar(Scrollbar.HORIZONTAL,0, 1, 0, w idth); 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.draw String(msg, 6, 160); g.draw String("*", horzSB.getValue(), vertSB.getValue()); } }
262 For the follow ing code select the method that can be used to handle event. import java.aw t.event.*; import ja 2 N A 2 actionPerformed(Ac
263 For the follow ing code select the method that can be used to handle event. import java.applet.*; import 2 N U 2 textChanged(TextE
java.aw t.*; 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.draw String(msg,100,100); } } /*
<applet code=checkbackg.class height=150 w idth=150> </applet>*/
For the follow ing code select the method that can be used to handle event. import java.aw t.*; import
java.applet.*; import java.aw t.event.*; /* <APPLET Code="ActionListenerTest" W idth=300 Height=300>
</APPLET> */ public class ActionListenerTest extends Applet
implements ActionListener { Button b1,b2,b3,b4; public void init() { Font f=new Font("New Times
265 For the follow ing code select the method that can be used to handle event. import java.aw t.*; import 2 N A 2 itemStateChanged
java.applet.*; import java.aw t.event.*; /*<applet code=exp.java w idth=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)); } } }
266 For the follow ing code select the method that can be used to handle event. import java.aw t.*; import 2 N A 2 actionPerformed(Ac
java.aw t.event.*; import java.applet.*; /* <applet code="ButtonDemo" w idth=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.draw String(msg, 6,
100); } }
267 For the follow ing code select the method that can be used to handle event. import java.aw t.*; import 2 N A 2 keyReleased(KeyEv
java.aw t.event.*; import java.applet.*; import javax.sw ing.*; /*<applet code="simple" w idth=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)
{ show Status("key dow n"); } public void
_________________(KeyEvent ke) { show Status("Key Up"); } public void keyTyped(KeyEvent ke) {
msg+=ke.getKeyChar(); repaint(); } public void paint(Graphics g) { g.draw String(msg,x,y);
}}
268 For the follow ing code select the method that can be used to handle event. importjava.aw t.event.*; import 2 N A 2 C. itemStateChange
java.aw t.*; 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 w idth=150>
</applet>*/
269 For the follow ing code select the method that can be used to handle event. import java.aw t.*; import 2 N A 2 adjustmentValueCh
java.aw t.event.*; import java.applet.*; public class scrl extends Applet implements AdjustmentListener {
Scrollbar vsb,hsb; public void init() { int w idth=Integer.parseInt(getParameter("w idth")); int
height=Integer.parseInt(getParameter("height")); vsb=new Scrollbar(Scrollbar.VERTICAL,0,1,0,height);
hsb=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,w idth); add(vsb); add(hsb);
vsb.addAdjustmentListener(this); hsb.addAdjustmentListener(this); } public void -----------------(-
--------Event ae) { repaint(); } public void paint(Graphics g) { msg="Vertical: "+vsb.getValue();
msg+="Horizontal: "+hsb.getValue(); g.draw String(msg,6,160); g.draw String("*",
hsb.getValue(),vsb.getValue()); } }
270 For the follow ing code select the method that can be used to handle event. import java.aw t.*; import 2 Y1 A 2 actionPerformed(Ac
java.aw t.event.*; class AEvent extends Frame implements ActionListener{ TextField tf; AEvent(){ tf=new
TextField(); tf.setBounds(60,50,170,20); Button b=new Button("click me"); b.setBounds(100,120,80,30);
b.addActionListener(this); add(b); add(tf); setSize(300,300); setLayout(null); setVisible(true); } public void
__________________(ActionEvent e){ tf.setText("W elcome"); } public static void main(String args[]){ new
AEvent(); } }
Figure:-
271 For the follow ing code select the method that can be used to handle event. importjava.aw t.event.*; import 2 N A 2 itemStateChanged(
java.aw t.* ; 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=
272 For the follow ing code select the method that can be used to handle event. ? import java.aw t.*; import 2 N A 2 itemStateChanged(
java.applet.*; import java.aw t.event.*; /*<applet code=ListDemo.class w idth=400
height=400></applet>*/ public class ListDemo extends Applet implements ItemListener { List l; String
msg=""; public void init() { l=new List(2,true); l.add("Day"); for(int i=1;i<=31;i++) { l.add(i+""); } add(l);
l.addItemListener(this); } public void
_______________________________ { repaint(); } public void paint(Graphics g) { int idx[];
idx=l.getSelectedIndexes(); for(int i=0;i<idx.length;i++) { msg=l.getItem(idx[i]); g.draw
String(msg,20,i*10+20); } } }
273 For the follow ing code select the method that can be used to hanle event. import java.aw t.*; import java.apple2 N A 2 adjustmentValueCh
274 For the follow ing code select the method that should fill in the blanks. import java.applet.Applet; import 2 N A 2 e.getSource()
java.aw t.*; import java.aw t.event.*; public class New Applet extends Applet implements ActionListener {
Button b1,b2,b3; public void init() { b1=new Button("1"); b2=new Button("2"); b3=new Button("3");
add(b1); add(b2); add(b3); b1.addActionListener(this); b2.addActionListener(this);
b3.addActionListener(this); } public void
actionPerformed(ActionEvent e) { if(_____________==b1) setBackground(Color.RED); else if
(__________==b2) setBackground(Color.BLUE); else setBackground(Color.GREEN); }} /*
<applet code=New Applet.class height=150 w idth=150> </applet>*/
For the follow ing code select the methods that can be used to handle event and register the event. importjava.
275 String msg = ""; intmouseX = 0, mouseY = 0 public void init() { add-------------(this); } public void 2 N A 2 addMouseMotionLis
----------------(MouseEvent me) { mouseX = me.getX(); mouseY = me.getY(); msg = "*"; show Status("
Mouse at " + mouseX + ", " + mouseY); repaint(); } public void ---------------- (MouseEvent me) { show
Status("Mouse at " + me.getX() + ", " + me.getY()); } public void paint(Graphics g) { g.draw String(msg,
mouseX, mouseY); } }
276 For the follow ing code w hich interface is use. importjava.aw t.event.*; import java.aw t.*; 2 N A 2 ItemListener
importjava.applet.*; public class checkbackg extends Applet implements __________________
{ Checkbox m1,m2,m3; public void init() { m1=new Checkbox("W indow s xp"); m2=new Checkbox("W
indow s 7"); m3=new Checkbox("W indow s vista"); add(m1); add(m2); add(m3); m1.addItemListener(this);
m2.addItemListener(this); } public void itemStateChanged(ItemEvent ie) { if(ie.getSource()==m1)
setBackground(Color.red); if(ie.getSource()==m2) setBackground(Color.green); } } /*<applet
code=checkbackg.class height=150 w idth=150>
</applet>*/
277 For the follow ing code, fill up the correct listener name and event name. import java.aw t.*; import java.aw 2 N A 2 KeyListener, KeyEv
t.event.*; import java.applet.*; /* <applet code="SimpleKeyDemo" w idth=300 height=100> </applet> */
public class SimpleKeyDemo extends Applet implements
_____________ { String msg = ""; int X = 10, Y = 20; public void init() { addKeyListener(this);
requestFocus(); } public void keyPressed( _________ ke) { show Status("Key Dow n"); } public void
keyReleased( _________ ke) { show Status("Key Up"); } public void keyTyped(
____________ ke) { msg += ke.getKeyChar(); repaint(); } public void paint(Graphics g) {
g.draw String(msg, X, Y); } }
278 For the follow ing output complete the code given below . import java.aw t.*; import java.aw t.event.*; 2 Y1 U 2 public void actionPe
import javax.sw ing.*; /* <applet code="JRadioButtonDemo" w idth=300 height=50> </applet> */ public tf.setText(ae.getAc
class JRadioButtonDemo extends JApplet implements ActionListener { JTextField tf; public void init() {
Container contentPane = getContentPane(); contentPane.setLayout(new Flow Layout()); JRadioButton b1 =
new JRadioButton("A"); b1.addActionListener(this); contentPane.add(b1); JRadioButton b2 = new
JRadioButton("B"); b2.addActionListener(this); contentPane.add(b2); JRadioButton b3 = new
JRadioButton("C"); b3.addActionListener(this); contentPane.add(b3); tf = new JTextField(5);
contentPane.add(tf); ButtonGroup bg = new ButtonGroup(); bg.add(b1); bg.add(b2); bg.add(b3); } }
Figure:-
279 For the follow ing output w indow , w hat type of Event Listener and abstract method implementation should 2 Y1 A 2 ActionListener, acti
be done for event handling on the radiobutton?
Figure:-
281 From given list w hich is not method of Mouse Listener? 2 N U 2 mouseDragged()
282 From the follow ing code find the correct occurence of key event. import java.aw t.*; import java.aw 2 N A 2 Key Pressed Key Ty
t.event.*; public class S1Q46 extends Frame implements KeyListener{ TextField t1; public S1Q46(){
setLayout(new Flow Layout()); t1= new TextField(10); t1.addKeyListener(this); add(t1); setVisible(true); }
public void keyTyped(KeyEvent e) { System.out.println("Key Typed");
} public void keyPressed(KeyEvent e) { System.out.println("Key Pressed"); } public void
keyReleased(KeyEvent e) { System.out.println("Key Released"); } public static void main(String arg[]){
S1Q46 s = new S1Q46(); }
287 How many checkboxes of follow ing program are in checked state.? import java.aw t.*; import java.aw 2 N A 2 2
t.event.*; import java.applet.*; /* <applet code="CheckboxDemo" w idth=250 height=200> </applet> */
public class CheckboxDemo extends Applet implements ItemListener
{ String msg = ""; Checkbox w inXP, w inVista, solaris, mac; public void init() { w inXP = new Checkbox("W
indow s XP", null, true); w inVista = new Checkbox("W indow s Vista"); solaris = new
Checkbox("Solaris",true); mac = new Checkbox("Mac OS"); add(w inXP); add(w inVista); add(solaris);
add(mac); }}
How many component is used in follow ing program :- import java.aw t.*; import javax.sw ing.*; import java.ap
288 Button b1; Label l1,l2; TextField t1,t2; public void init() { l1=new Label("Enter the number"); l2=new Label("Sq2 N A 2 5
289 Identify correct output for follow ing program. import java.aw t.*; import java.aw t.event.*; import 2 Y2 A 2
java.applet.*; public class ListDemo extends Applet implements ActionListener { List os; String msg = "";
public void init() { os = new List(4, false); os.add("W indow s 98/XP"); os.add("W indow s NT/2000");
os.add("Solaris"); os.add("MacOS"); os.select(1); add(os); os.addActionListener(this); } public void
actionPerformed(ActionEvent ae) { repaint(); } public void paint(Graphics g) { msg = "Current OS: "; msg
+= os.getSelectedItem(); g.draw String(msg,
6, 140); } }
292 Identify the correct code to handle event on Scrollbar? 2 N A 2 import java.aw t.*; import java.aw t
294 Identify the correct syntax of adding MouseAdapter class to program? 2 N A 2 addMouseListener(n
295 Identify the Error Statement in the Follow ing Program import java.aw t.*; import java.aw t.event.*; import 2 N U 2 All of the above.
javax.sw ing.*; class ChangeBackClr extends JFrame { ChangeBackClr()
{ final Container oPane=getContainer(); addMouseListener(new MouseAdapter() { public void
mouseClicked(MouseEvent me) { int iR=(int)(Math.random()*255); int iG=(int) (Math.random()*255); int
iB=(int)(Math.random()*255); oPane.setBackcolor(new Color(iR,iG,iB));
} }); } }
Identify the missing statement in the program? import java.aw t.*; import java.aw t.event.*;
import java.applet.*; public class eventdemo extends Applet implements ActionListener { public
296 void init() { Button b1= new Button("Click"); TextField t1=new TextField(); add(b1); add(t1); } public void acti2 N A 2 b1.addActionlistener(this) should r
297 Identify the missing statements in the follow ing code. Figure:- 2 Y1 A 2 b1.addActionListene
298 Identify type of listener public class MouseEvents extends Applet implements 2 N A 2 None of Above
_______________________ { String msg = ""; int mouseX = 0, mouseY = 0; public void init() {
add__________________(this); } public void mouseDragged(MouseEvent me) { mouseX = me.getX();
mouseY = me.getY(); msg = "*"; show Status("Dragging mouse at " + mouseX + ", " + mouseY); repaint();
} public void mouseMoved(MouseEvent me) { show Status("Moving mouse at " + me.getX() + ", " +
me.getY()); } public void paint(Graphics g) { g.draw String(msg, mouseX, mouseY); } }
301 If w e close an applet w indow _____ events w ill be generated 2 N U 2 W indow Event
302 import java.applet.Applet; For the follow ing code select the method that can be used to handle event import ja 2 N A 2 adjustmentValueCh
303 import java.applet.Applet; import java.aw t.*; import java.aw t.event.*; /*<applet code="mlst" w idth=300 2 N A 2 Program w ill appen
height=300></applet>*/ public class mlst extends Applet implements ActionListener double clicked
{ TextArea t1; List l1; public void init() { t1=new TextArea("
",10,20,TextArea.SCROLLBARS_VERTICAL_ONLY); l1=new List(4,true); l1.add("sangamner"); l1.add("nasik");
l1.add("pune"); l1.add("mumbai"); add(l1); add(t1); l1.addActionListener(this); } public void
actionPerformed(ActionEvent e) { if(e.getSource()==l1) for(int
i=0;i<((String)l1.getSelectedItem()).length();i++) { t1.insert((String)l1.getSelectedItem(),0); }}}
304 import java.aw t.*; import java.applet.*; public class myapplet extends Applet { public void paint(Graphics g) {2 N A 2 A Simple Applet
305 import java.aw t.*; import java.applet.* class colordemo extends Applet implements ActionListener { String str=2 Y2 A 2
306 import java.aw t.*; import java.applet.*; public class LayoutDemo5 extends Applet { public void init() { int i,j,k2 N A 2 The output is obtain
Layout
code=LayoutDemo5.class w idth=300 height=400> </applet>*/ W hat w ill be the out put of above program?
307 import java.aw t.*; import java.aw t.event.*; import java.applet.*; /* <applet code="CountVow el.class" w 2 Y1 A 2 12
idth=300 height=100> </applet> */ public class CountVow el extends Applet implements ActionListener {
TextArea txtArea; TextField text; Button btn; public void init() { txtArea = new TextArea();
txtArea.setBounds(30,30,200,200); add(txtArea); text =
new TextField(20); text.setBounds(30,240,100,30); text.setEditable(false); add(text); btn = new
Button("Calculate"); btn.setBounds(150,230,70,30); add(btn); btn.addActionListener(this); } public void
actionPerformed(ActionEvent ae) { if(ae.getSource() == btn ) { String strTemp= txtArea.getText(); int
count=0; for(int i=0;i<strTemp.length();i++) { if(strTemp.charAt(i)=='a'|| strTemp.charAt(i)=='A'||
strTemp.charAt(i)=='e'|| strTemp.charAt(i)=='E'|| strTemp.charAt(i)=='i'|| strTemp.charAt(i)=='I'||
strTemp.charAt(i)=='o'|| strTemp.charAt(i)=='O'|| strTemp.charAt(i)=='u'|| strTemp.charAt(i)=='U') {
count++; } } String str=Integer.toString(count); text.setText(str); } }
} W hat w ill be the Output? Figure:-
308 importjava.aw t.*; importjava.applet.*; public class list2 extends Applet { public void init() { List l= new List(2 2 Y2 U 2
309 In follow ing Java program fill statement show ing ***. Select any one option from given options import java.ap2 N A 2 mousePressed()
310 In follow ing Java program fill statement show ing ***.Select any one option fro given options import java.aw t.2 N A 2 ActionListener, acti
311 In follow ing Java program fill statement show ing ***.Select any one option from given options import 2 N A 2 ActionListener
java.aw t.*; import java.aw t.event.*; class AEvent extends Frame implements ********{ TextField tf;
AEvent(){ tf=new TextField(); tf.setBounds(60,50,170,20); Button b=new Button("click me");
b.setBounds(100,120,80,30); b.addActionListener(this); add(b);add(tf); setSize(300,300); setLayout(null);
setVisible(true); } public void actionPerformed(ActionEvent e)
{ tf.setText("W elcome"); } public static void main(String args[]){ new AEvent(); } }
312 In order to obtain currunt value of scrollbar at run time w hich method you w ill use 2 N A 2 getValue()
313 In the follow ing output, the frame w indow doesn't close by default. Pick up the correct code in order to close 2 Y1 A 2 W indow Listener
the frame.
Figure:-
314 In w hich places can put the event handling code 2 N U 2 All mentioned above
316 itemStateChanged() method take w hich form from the follow ing? 2 N U 2 void itemStateChanged(Item ie)
317 Java packages such as ____________ support the Event handling mechanism 2 N A 2 all of these
319 keyTyped(KeyEvent e) Called w hen a key on the keyboard is ________________________ 2 N U 2 pressed and then released
320 List control in AW T, generates ………………….. Event on ………………. Click. 2 N A 2 Both Options A and B correct.
321 Match The Pair ? 1) Button() a) AdjustmentListener 2) Scrollbar() b) Non Of Above 3) Checkbox() 2 N U 2 1-d 2-a 3-c 4-b
c) ItemListener 4) Label() d) ActionListener
322 MouseListener interface belongs w hich of the follow ing methods? 2 N U 2 mouseExited,mouseEntered,mous
323 Observe the Follow ing Code... import java.aw t.*; import java.aw t.event.*; class TYIFEvent extends Frame im 2 N A 2 This Program Hand
324 Observe the follow ing output and determine w hich component and listener is required? Figure:- 2 Y1 U 2 Button, frame, actio
325 Observe the follow ing program .... import java.applet.Applet; import java.aw t.Button; /* <applet code="Disab 2 N A 2 The output w ill dis
"Cancle"
disabled
326 Observe the follow ing program .... import java.applet.Applet; import java.aw t.Button; /* <applet code="HideB2 N A 2 The Program contai
"Cancle"
be displayed
Observe the follow ing program .... import java.aw t.*; import javax.sw ing.*; public class
327 MyFlow Layout{ JFrame f; MyFlow Layout(){ f=new JFrame(); JButton b1=new JButton("1"); JButton b2=new J 2 N A 2 The output w ill dis
328 Observe the follow ing program .... import java.aw t.Color; import javax.sw ing.*; public class TyifArea { JTextA2 N A 2 The Output w ill Co
black
329 Pick the correct abstract method w hich belongs to MouseMotionListener interface 2 N U 2 mouseDragged()
330 Pick the correct statement to register a button b for event handling 2 N U 2 b.addActionListener(this);
331 Predict the output public class R1 extends Applet implements ItemListener { TextField t1, Checkbox c1; public 2 N A 2 Hi is printed in text
void init() { c1 = new Checkbox(); add(c1); t1 = new TextField(); add(t1); } public void
itemStateChanged(ItemEvent ie) { if(ae.getItemSelectable()==c1) t1.setText("Hi"); }
}
333 Referring to the above, w hat statement is added to itemStateChanged() so it w ill display "India" on selection 2 N U 2 msg=(String) e.get
of item? import java.applet.*; import java.aw t.*; import java.aw t.event.*; public class S1Q31 extends
Applet implements ItemListener { Choice c; String msg=""; public void init()
{ c = new Choice(); c.add("India"); c.add("Nepal"); c.add("Sri Lanka"); c.addItemListener(this); } public void
itemStateChanged(ItemEvent e) { repaint(); } public void paint(Graphics g){ g.draw String(msg,200, 200); }
} /* <applet code="combodemo" w idth=300 height=100>
</applet> */
334 Select correct Adapter class from given option for ******. import java.aw t.*; import java.aw t.event.*; import 2 N A 2 MouseAdapter
335 Select correct sequence of steps for selecting items w hich are specified in a Jtree a)The Clicked row is acquired 2 N U 2 a,c,b
336 select correct statement to get correct out? import javax.sw ing.*; import java.aw t.*; import java.aw 2 N A 2 ok.addActionListene
t.event.*; public class SimpleGUI extends JFrame { private Container contentPane; private JTextField ActionListener
textField; private JButton ok, cancel; private JLabel feedback; private JPanel panel; public static void main(
String[] args ) { SimpleGUI gui = new SimpleGUI(); gui.pack(); gui.setVisible( true ); } public SimpleGUI() {
contentPane = getContentPane(); contentPane.setLayout( new GridLayout( 3, 1 ) ); textField = new
JTextField(); textField.setColumns( 22 ); contentPane.add( textField ); panel = new JPanel( new Flow Layout()
); ok = new JButton( "OK" ); cancel = new JButton( "Cancel" ); panel.add( ok ); panel.add( cancel
); contentPane.add( panel ); feedback = new JLabel(); contentPane.add( feedback );
setDefaultCloseOperation( EXIT_ON_CLOSE ); } setDefaultCloseOperation( EXIT_ON_CLOSE ); }
}
337 Select currect sequence of current states of follow ing output 2 Y1 U 2 True,False,True,Fal
Figure:-
339 Select missing lines in follow ing code to get correct ouput . /*<applet code="demo2.class" w idth="310" 2 N A 2 cp.add(sp); tr.setEd
height="160"></applet>*/ import java.aw t.*; import javax.sw ing.*; import java.aw t.event.*; public class
demo2 extends JApplet implements ActionListener { public void init() { DefaultMutableTreeNode root=new
DefaultMutableTreeNode("root"); DefaultMutableTreeNode tr1=new DefaultMutableTreeNode("1");
root.add(tr1); DefaultMutableTreeNode tr11=new DefaultMutableTreeNode("1-1"); tr1.add(tr11);
DefaultMutableTreeNode tr111=new DefaultMutableTreeNode("1-1-1"); tr11.add(tr11);
DefaultMutableTreeNode tr112=new DefaultMutableTreeNode("1-1-2"); tr11.add(tr112);
DefaultMutableTreeNode tr12=new DefaultMutableTreeNode("1-2"); tr1.add(tr12); DefaultMutableTreeNode
tr2=new DefaultMutableTreeNode("2"); root.add(tr2); root.add(tr2); JTree tr=new JTree(root); JScorllPane
sp=new JScrollPane(tr); Container cp=getContentPane();
}}
340 Select missing statement in follow ing code /*<applet code="demo.class" w idth=300 height=200></applet>*/2 N A 2 setJMenuBar(mb);
341 select missing statement in follow ing code /*<applet code="demo.class" w idth="310" hieght="140"></applet 2 N U 2 cb.addActinListener
342 Select missing statement of follow ing code import java.aw t.*; import java.aw t.event.*; import java.applet.*; 2 N U 2 public void keyType
}
344 Select proper code for given output 2 Y1 A 2 import java.aw t.*;
Figure:- Applet { public void
con.add("Indi
con.add("Sou
code="ListDe
346 Select Proper Command to run follow ing program import java.aw t.*; import java.aw t.event.*; class FrameDem
2 N A 2 java FrameDemo
347 Select proper sequence of follow ing classes used for w riting menudriven program 1.Menu 2. MenuBar 3. MenuI2 N A 2 2,1,3
348 Select sequence of the missing statements in the follow ing program import java.aw t.*; import java.aw 2 N U 2 ActionListener addA
t.event.*; public class MenuDemo extends Frame implements ___________________ { MenuDemo() {
MenuBar mbr = new MenuBar(); Menu filemenu = new Menu("File"); Menu editmenu = new Menu("Edit");
Menu view menu = new Menu("View "); mbr.add(filemenu); mbr.add(editmenu); MenuItem new 1 = new
MenuItem("New "); MenuItem open1 = new MenuItem("Open"); filemenu.add(new 1); filemenu.add(open1);
new 1.********; open1.**********; } public static void main(String args[]) { MenuDemo m = new
MenuDemo(); m.setSize(200,200); m.setTitle("Menu Demo Program"); m.setVisible(true); } public void
________________________ { if(new 1=ae.getsource()) { System.out.println("You Pressed New menu
Item"); } else if(ae.getSource()==open1) { System.out.println("You Pressed Open menu Item"); } } }
351 Select the correct output for the follow ing program import java.aw t.*; import java.aw t.event.*; import 2 Y2 A 2 S1Q47Option i
javax.sw ing.*; import javax.sw ing.tree.*; /* <applet code="JTreeEvents" w idth=400 height=200>
</applet> */ public class JTreeEvents extends JApplet { JTree tree; JTextField jtf; public void init() { // Get
content pane Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout());
DefaultMutableTreeNode top = new DefaultMutableTreeNode("Options"); DefaultMutableTreeNode a = new
DefaultMutableTreeNode("A"); top.add(a); DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1");
a.add(a1); DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2"); a.add(a2);
DefaultMutableTreeNode b = new DefaultMutableTreeNode("B"); top.add(b); DefaultMutableTreeNode b1 =
new DefaultMutableTreeNode("B1"); b.add(b1); DefaultMutableTreeNode b2 = new
DefaultMutableTreeNode("B2"); b.add(b2); DefaultMutableTreeNode b3 = new
DefaultMutableTreeNode("B3"); b.add(b3); tree = new JTree(top); int v =
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h =
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPane jsp = new JScrollPane(tree, v, h);
contentPane.add(jsp, BorderLayout.CENTER); jtf = new JTextField("", 20); contentPane.add(jtf,
BorderLayout.SOUTH); tree.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent me) { doMouseClicked(me); } }); } void doMouseClicked(MouseEvent
me) { TreePath tp = tree.getPathForLocation(me.getX(), me.getY()); if(tp != null) jtf.setText(tp.toString());
else jtf.setText(""); } }
352 Select the Listeners needed for components show n in application. Figure:- 2 Y1 U 2 actionPerformed(Ac
Select the method used for Event Handle import java.aw t.*; import java.aw t.event.*; import java.applet.*; pu
353 b1,b2,b3; public void init() { b1=new Button("Yes"); add(b1); b2=new Button("No"); add(b2); b3=new 2 N A 2 actionPerformed(Ac
Button("Exit"); add(b3); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); }
public void _______________ { String str=ae.getActionCommand(); if(str.equals("Yes")) { msg="You
pressed Yes."; } else if(str.equals("No")) { msg="You pressed No."; } if(str.equals("Exit")) { msg="You
pressed Exit.";
} repaint(); } public void paint(Graphics g) { g.draw String(msg,6,100);} }
354 Select the method used to determine the event ID that represents the natures of the event 2 N U 2 public int getID()
355 Select the missing code in given statement import java.aw t.*; import java.applet.*; /* <applet code="Adapter 2 N U 2 both a & b
356 Select the missing code in the program for follow ing output import java.aw t.*; import java.aw t.event.*; 2 Y1 A 2 addItemListener(th
public class MenuD extends Frame { MenuD( ) { addW indow Listener(new W indow Adapter(){ public void w
indow Closing(W indow Event w e) { System.exit(0); } }); } public static void main(String a[]) { MenuD
m=new MenuD(); CheckboxMenuItem debug,test; m.setVisible(true); MenuBar mbr=new MenuBar();
m.setMenuBar(mbr); Menu file=new Menu("File"); Menu edit= new Menu("edit"); mbr.add(file);
mbr.add(edit); MenuItem new 1=new MenuItem("New "); MenuItem open=new MenuItem("Open");
file.add(new 1); file.add(open); MenuItem copy=new MenuItem("Copy"); MenuItem paste=new
MenuItem("Paste"); copy.setEnabled(false); edit.add(copy); edit.add(paste); debug =new
CheckboxMenuItem("Debug"); test =new CheckboxMenuItem("Test"); edit.add(test); edit.add(debug); } }
Figure:-
357 Select the missing in the program import java.applet.*; import java.aw t.*; import java.aw t.event.*; public 2 Y1 A 2 Method missing for
class textfield extends Applet implements ActionListener { TextField nm,psw ; public void init() { Label
nml=new Label("username:",Label.RIGHT); Label psw l=new Label("passw ord:",Label.RIGHT); nm=new
TextField(12); psw =new TextField(8); Button b=new Button("submit"); add(nml); add(nm); add(psw );
add(b); nm.addActionListener(this); psw .addActionListener(this); b.addActionListener(this); } public void
actionPerformed(ActionEvent ae) { repaint(); } }
Figure:-
358 Select the missing statement public class A1 extends Applet { Button b1; Label l1; public void init() { 2 N A 2 b1.addActionListene
setLayout(new Flow Layout()); b1=new Button("Click"); l1=new Label(); add(l1); add(b1);
} public void actionPerformed(ActionEvent ae) { if(ae.getSource()==b1) l1.setText("Hello"); } }
359 Select the missing statement public class A1 extends Applet { Button b1; Label l1; public void init() { setLayout2 N A 2 add(l1); add(b1);
360 Select the missing statement in given code importjava.aw t.*; importjava.applet.*; /* <applet code="mouse" 2 N U 2 all of above
w idth=300 height=100> </applet> */ public class mouse extends Applet implements MouseListener,
MouseMotionListener { String msg = ""; intmouseX = 0, mouseY = 0 public void init() { } public void
mouseClicked(MouseEvent me) { mouseX = 0; mouseY = 10; msg
= "Mouse clicked."; repaint(); } public void mouseEntered(MouseEvent me) { mouseX = 0; mouseY = 10;
msg = "Mouse entered."; repaint(); } public void mouseExited(MouseEvent me) { mouseX = 0; mouseY =
10; msg = "Mouse exited."; repaint(); } public void mousePressed(MouseEvent me) { mouseX = me.getX();
mouseY = me.getY(); msg = "Dow n"; repaint(); } public void mouseReleased(MouseEvent me) { mouseX =
me.getX(); mouseY = me.getY(); msg = "Up"; repaint(); } public void mouseDragged(MouseEvent me) {
mouseX = me.getX(); mouseY = me.getY(); msg = "*"; show Status("Dragging mouse at " + mouseX + ", "
+ mouseY); repaint(); } public void mouseMoved(MouseEvent me) { show Status("Moving mouse at " +
me.getX() + ", " + me.getY()); } public void paint(Graphics g) { g.draw String(msg, mouseX, mouseY); } }
361 Select the missing statement in given code // Demonstrate the mouse event handlers. import java.aw t.*; 2 N A 2 addMouseListener(t
import java.applet.*; /* <applet code="mouse" w idth=300 height=100> </applet> java.aw t.event.*;
*/ public class mouse extends Applet implements MouseListener, MouseMotionListener { String msg = "";
intmouseX = 0, mouseY = 0; // coordinates of mouse public void init() { } // Handle mouse clicked. public
void mouseClicked(MouseEvent me) { mouseX = 0; mouseY = 10; msg = "Mouse clicked."; repaint(); } //
Handle mouse entered. public void mouseEntered(MouseEvent me) { mouseX = 0; mouseY = 10; msg =
"Mouse entered."; repaint(); } // Handle mouse exited. public void mouseExited(MouseEvent me) { mouseX
= 0; mouseY = 10; msg = "Mouse exited."; repaint(); } // Handle button pressed. public void
mousePressed(MouseEvent me) { mouseX = me.getX(); mouseY = me.getY(); msg = "Dow n"; repaint(); } //
Handle button released. public void mouseReleased(MouseEvent me) { mouseX = me.getX(); mouseY =
me.getY(); msg = "Up"; repaint(); } // Handle mouse dragged. public void mouseDragged(MouseEvent me) {
mouseX = me.getX(); mouseY = me.getY(); msg = "*"; show Status("Dragging mouse at " + mouseX + ", "
+ mouseY); repaint(); } // Handle mouse moved. public void mouseMoved(MouseEvent me) { show
Status("Moving mouse at " + me.getX() + ", " + me.getY()); } // Display msg in applet w indow at current
X,Y location. public void paint(Graphics g) { g.draw String(msg, mouseX, mouseY); } }
362 Select the missing statement in given code import java.lang.*; import java.aw t.*; import java.applet.*; ------- 2 N U 2 All of Above
public void w indow Iconified(W indow Event w e){} public void w indow Deiconified(W indow Event w e){} ----
363 Select the missing statement in given code import java.applet.*; import java.aw t.event.*; import java.aw 2 N U 2 addMouseListener(t
t.*; public class MouseClickExample extends Applet implements MouseListener { int
xpos; int ypos; int rect1xco,rect1yco,rect1w idth,rect1height; boolean mouseEntered; boolean rect1Clicked;
public void init() { rect1xco = 20; rect1yco = 20; rect1w idth = 100; rect1height =
50; } public void paint(Graphics g) { g.setColor(Color.green); g.fillRect(rect1xco,rect1yco,rect1w
idth,rect1height); g.setColor(Color.red); g.draw String(" ("+xpos+","+ypos+")",xpos,ypos); if (rect1Clicked)
g.draw String("You clicked in the Rectangle",20,120); else g.draw String("You clicked outside of the
rectangle",20,120); if (mouseEntered) g.draw String("Mouse is in the applet area",20,160); else g.draw
String("Mouse is outside the Applet area",20,160); } public void mouseClicked (MouseEvent me) { xpos =
me.getX(); ypos = me.getY(); if (xpos > rect1xco && xpos < rect1xco+rect1w idth && ypos
>rect1yco && ypos < rect1yco+rect1height) rect1Clicked = true; else rect1Clicked = false; repaint(); } public
void mousePressed (MouseEvent me) {} public void mouseReleased (MouseEvent me) {} public void
mouseEntered (MouseEvent me) { mouseEntered = true; repaint(); } public void mouseExited (MouseEvent
me) { mouseEntered = false; repaint(); } }
364 Select the missing statement in given code import javax.sw ing.*; import java.aw t.event.*; import javax.sw 2 N U 2 Both option A and B
ing.tree.*; import java.applet.*; public class exp5 extends JApplet { JTree tr; public void init() { Container
ContentPane=getContentPane(); ContentPane.setLayout(new Flow Layout()); DefaultMutableTreeNode
top=new DefaultMutableTreeNode("India"); DefaultMutableTreeNode mh=new
DefaultMutableTreeNode("Maharashtra"); DefaultMutableTreeNode mb=new
DefaultMutableTreeNode("Mumbai"); mh.add(mb); DefaultMutableTreeNode na=new
DefaultMutableTreeNode("Nashik"); mh.add(na); DefaultMutableTreeNode w b=new
DefaultMutableTreeNode("W est Bengal"); top.add(w b); DefaultMutableTreeNode ap=new
DefaultMutableTreeNode("Andra pradesh"); top.add(ap); DefaultMutableTreeNode tn=new
DefaultMutableTreeNode("TamilNadu"); top.add(tn); DefaultMutableTreeNode ch=new
DefaultMutableTreeNode("chennai"); tn.add(ch); DefaultMutableTreeNode kn=new
DefaultMutableTreeNode("Karnataka"); top.add(kn); DefaultMutableTreeNode bg=new
DefaultMutableTreeNode("Balgaum"); kn.add(bg); DefaultMutableTreeNode bl=new
DefaultMutableTreeNode("Bangalore"); kn.add(bl); tr=new JTree(top); int
v=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALW AYS; int
h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALW AYS; JScrollPane jsp=new JScrollPane(tr,v,h);
ContentPane.add(jsp); tr.addMouseListener(new MouseAdapter() { public void MouseClicked(MouseEvent me)
{ doMouseClicked(me); } }); } void doMouseClicked(MouseEvent me) { TreePath
tp=tr.getPathForLocation(me.getX(),me.getY()); }
}
365 Select the missing statement in given code import java.applet.*; import java.aw t.event.*; import java.aw t.*; 2 N U 2 addW indow Listene
366 Select the missing statement in given code import java.aw t.*; import java.aw t.event.*; import java.applet.*; 2 N U 2 addKeyListener(this
367 Select the missing statement in given code import java.aw t.*; import java.applet.*; /* <APPLET Code="Action 2 N U 2 All of the above
368 Select the missing statement in given code import java.aw t.*; import java.aw t.event.*; class AEvent extends 2 N U 2 b.addActionListener
369 Select the missing statement in given code import java.aw t.*; import java.aw t.event.*; import java.applet.*; 2 N U 2 implements KeyList
370 Select the missing statement in given code import java.applet.*; import java.aw t.event.*; import java.aw t.*; 2 N U 2 actionPerformed(Ac
371 Select the missing statement in given code import java.aw t.*; import java.aw t.event.*; import 2 N U 2 os = new Choice();
java.applet.*; /* <applet code="ChoiceDemo" w idth=300 height=180> </applet> */ public class
ChoiceDemo extends Applet implements ItemListener { Choice os, brow ser; String msg = ""; public void
init() { // add items to os list os.add("W indow s 98/XP"); os.add("W indow s NT/2000"); os.add("Solaris");
os.add("MacOS"); // add items to brow ser list brow ser.add("Netscape 3.x"); brow ser.add("Netscape 4.x");
brow ser.add("Netscape 5.x"); brow ser.add("Netscape 6.x"); brow ser.add("Internet Explorer 4.0"); brow
ser.add("Internet Explorer 5.0"); brow ser.add("Internet Explorer 6.0"); brow ser.add("Lynx 2.4"); brow
ser.select("Netscape 4.x");
// add choice lists to w indow add(os); add(brow ser); // register to receive item events
os.addItemListener(this); brow ser.addItemListener(this); } public void itemStateChanged(ItemEvent ie) {
repaint(); } // Display current selections. public void paint(Graphics g) { msg = "Current OS: "; msg +=
os.getSelectedItem(); g.draw String(msg, 6,
120); msg = "Current Brow ser: "; msg += brow ser.getSelectedItem(); g.draw String(msg, 6,
140); } }
372 Select the missing statement in the follow ing code import java.aw t.*; class AppW indow extends Frame { 2 N A 2 Missing import java
AppW indow (String title) { super(title); this.addW indow Listener(new W indow Adapter() { public void w
indow Closing(W indow Event w e) { System.exit(0); } }); } public void paint(Graphics g) { g.draw
String("First Application W indow ",50,100); } public static void main(String args[]) { AppW indow app=new
AppW indow ("First W indow "); app.setSize(300,400); app.setVisible(true);
}}
373 Select the missing statement in the follow ing code import java.aw t.*; import java.aw t.event.*; import 2 N A 2 A and C are correct
java.applet.*; public class DemoChoice extends Applet { Choice ch; public void init() { ch=new Choice();
ch.add("A"); ch.add("B"); ch.add("C"); ch.addItemListener(this); } public void itemStateChanged(ItemEvent
ie) { if(ie.getSource()==ch) show Status(ch.getSelectedItem()); } }
/*<applet code="DemoChoice.class" w idth=300 height=200></applet>*/
Select the missing statement in the given code import javax.sw ing.*; import java.aw t.*; class CompDemo ext
374 label1=new Label("Name"); cpane.add(label1); JTextField jtextfield=new JTextField(15); cpane.add(jtextfield); 2 N U 2 Container cpane=jframe.getConte
375 Select the missing statement in the program import java.aw t.*; import java.aw t.event.*; public class combode2 N A 2 import javax.sw ing
376 Select the missing statement in the program import java.aw t.*; import java.aw t.event.*; import javax.sw 2 N A 2 jl = new JLabel(new
ing.*; /* <applet code="combodemo" w idth=300 height=100> </applet> */ public class combodemo
extends JApplet implementsItemListener { JLabeljl; ImageIconfrance, germany,
italy, japan; public void init() { Container contentPane = getContentPane(); contentPane.setLayout(new Flow
Layout()); JComboBoxjc = new JComboBox(); jc.addItem("France"); jc.addItem("Germany");
jc.addItem("Italy"); jc.addItem("Japan"); jc.addItemListener(this); contentPane.add(jc); contentPane.add(jl);
} public void itemStateChanged(ItemEventie) { String s = (String)ie.getItem(); jl.setIcon(new ImageIcon(s +
"star.gif")); } }
377 Select the missing statement in the program at ----------------------------- to get the follow ing output import 2 Y1 A 2 b1.addActionListene
java.aw t.*; import java.applet.*; import java.aw t.event.*; /* <APPLET Code="EventExample" W idth=200
Height=250> </APPLET> */ public class EventExample extends Applet implements ActionListener { Button
b1; TextField t1; public void init() { b1=new
Button("Message"); t1=new TextField(35); add(t1); add(b1); ---------------------------------- } public void
actionPerformed(ActionEvent ae) { if(ae.getSource()==b1) { t1.setText("Event Handling in Java"); } } }
Figure:-
378 Select the missing statement in the program at -----------------------------to get the follow ing output import 2 N A 2 b.addMouseListene
java.aw t.*; import java.aw t.event.*; import java.applet.*; public class Mouseclick extends Applet { int
fs=10; int x=10; int i=1; public void init() { Button b = new Button( "CLik"); add(b); ---------------------------
------------ } public void paint(Graphics g) { g.draw String("Hello Java",150,100+x); x=x+20; } class mouse
extends MouseAdapter { public void mouseClicked(MouseEvent me) { if(i<=10) { Font f=new Font("Times
new Roman",Font.BOLD,fs); fs=fs+2; Graphics g=getGraphics(); g.setFont(f); i++; paint(g); } } } }
/*<applet
code=Mouseclick w idth=500 height=500> </applet> */
Select the missing statement in the program for follow ing output import java.aw t.*; public class MenuDemo ex
380 Select the missing statement in the program for follow ing output import java.aw t.*; public class MenuDemo 2 Y1 A 2 mbr.add(view menu
extends Frame { public static void main(String args[]) { MenuDemo m = new MenuDemo();
m.setVisible(true); MenuBar mbr = new MenuBar(); m.setMenuBar(mbr); Menu filemenu = new Menu("File");
Menu editmenu = new Menu("Edit"); Menu view menu = new Menu("View "); mbr.add(filemenu);
mbr.add(editmenu); MenuItem new 1 = new MenuItem("New "); MenuItem open1 = new MenuItem("Open");
filemenu.add(new 1); filemenu.add(open1); } }
Figure:-
381 Select the missing statement in the program for follow ing output import java.aw t.*; public class MenuDemo 2 Y1 A 2 mbr.add(view menu
extends Frame { public static void main(String args[]) { MenuDemo m = new MenuDemo();
m.setVisible(true); MenuBar mbr = new MenuBar(); m.setMenuBar(mbr); Menu filemenu = new Menu("File");
Menu editmenu = new Menu("Edit"); Menu view menu = new Menu("View "); mbr.add(filemenu);
mbr.add(editmenu); MenuItem new 1 = new MenuItem("New "); MenuItem open1 = new MenuItem("Open");
filemenu.add(new 1); filemenu.add(open1); } }
Figure:-
382 Select the missing statement in the program for follow ing output import java.aw t.*; public class MenuDemo 2 N A 2 mbr.add(view menu
extends Frame { public static void main(String args[]) { MenuDemo m = new MenuDemo();
m.setVisible(true); MenuBar mbr = new MenuBar();
__________________________ Menu filemenu = new Menu("File"); Menu editmenu = new Menu("Edit");
Menu view menu = new Menu("View "); mbr.add(filemenu); mbr.add(editmenu); MenuItem new 1 = new
MenuItem("New "); MenuItem open1 = new MenuItem("Open"); filemenu.add(new 1); } }
383 Select the missing statement in the program for follow ing output import java.aw t.*; import java.aw 2 Y1 A 2 Both option A and B
t.event.*; class ListAction extends Frame { List list; Label label; public ListAction() { setTitle("List w ith
ItemListener Demo"); setSize(400,400); setLayout(new Flow Layout()); setLocationRelativeTo(null);
setVisible(true); list=new List(); label=new Label(); list.add("Apple"); list.add("Mango"); list.add("Guava");
list.add("Orange"); list.add("Pineapple"); list.add("Grapes"); list.addItemListener(new ItemListener() { public
void itemStateChanged(ItemEvent ie) { label.setText("You selected "+list.getSelectedItem()); } }); } public
static void main(String args[]) { new ListAction(); } }
Figure:-
384 Select the missing statement in the program for follow ing output import java.aw t.*; import java.aw 2 Y1 A 2 Both option A and B
t.event.*; class ListAction extends Frame { List list; Label label; public ListAction() { setTitle("List w ith
ItemListener Demo"); setSize(400,400); setLayout(new Flow Layout()); setLocationRelativeTo(null);
setVisible(true); list=new List(); label=new Label(); list.add("Apple"); list.add("Mango"); list.add("Guava");
list.add("Orange"); list.add("Pineapple"); list.add("Grapes"); list.addItemListener(new ItemListener() { public
void itemStateChanged(ItemEvent ie) { label.setText("You selected "+list.getSelectedItem()); } }); } public
static void main(String args[]) { new ListAction(); } }
Figure:-
385 select the missing statement in the program for the follow ing output import java.aw t.*; import java.aw 2 Y1 U 2 red.addActionListen
t.event.*; import java.applet.*; /*<applet code=ColorChange w idth=250 height=300>
</applet>*/ public class ColorChange extends Applet implements ActionListener { Button red; public void
init() { red=new Button("RED"); add(red); } public void actionPerformed(ActionEvent e) {
setBackground(Color.red); repaint(); } }
Figure:-
386 Select the missing statement in the program to get correct output. import java.aw t.*; import javax.sw ing.*; /*2 N U 2 All the above
387 Select the missing statement in the program to get the correct output import java.aw t.*; import java.applet.*; 2 N A 2 b1.addActionListene
388 Select the missing statement in the program to get the correct output import java.aw t.*; import javax.sw 2 N A 2 JScrollPane jsp=new
ing.*; public class JScrollPaneDemo extends JApplet { public void init() { Container
contentPane=getContentPane(); contentPane.setLayout(new BorderLayout()); JPanel jp=new JPanel();
jp.setLayout(new GridLayout(20,20)); int b=0; for(int i=0;i<20;i++) { for(int j=0;j<20;j++) { jp.add(new
JButton("Button"+b)); ++b; } } int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int
h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; -----------------------------------------
------------ contentPane.add(jsp,BorderLayout.CENTER); } }
Select the missing statement in the program to get the follow ing output importjava.aw t.*; importjava.aw t.eve
391 Select the missing statement in the program. import java.aw t.event.*; import javax.sw ing.*; public class 2 N A 2 ActionListener,addA
S1Q47 extends JFrame implements ************** { JRadioButton rb1,rb2; String msg; public S1Q47() {
rb1 = new JRadioButton("Select Me") ; rb1.addActionListener(this); rb2 = new JRadioButton("Select Me") ;
rb2.*************(this); add(rb1); add(rb2); setVisible(true); setSize(200,200);
setDefaultCloseOperation(S1Q47.EXIT_ON_CLOSE); } public void **********
{ System.out.println("Radion button selected"); } public static void main(String arg[]) { S1Q47 s
= new S1Q47(); } } }
392 Select the missing statements at --------------------- for follow ing program: import java.aw t.*; import java.app2 N U 2 import java.aw t.ev
b.addActionListener
393 Select the missing statements at ---------------------in bellow program import java.aw t.*; import java.aw 2 N U 2 both A and B
t.event.*; import java.applet.*; /*<applet code=keydemo w idth=400 height=400>
</applet>*/ public class keydemo extends Applet implements KeyListener { String msg=""; int i=0; public
void init() { ------------------------------ } public void keyPressed(KeyEvent e) { ------------
---------------- msg=e.getKeyChar()+""; repaint(); sw itch(i) { case KeyEvent.VK_UP: show Status("up key
pressed"); break; case KeyEvent.VK_DOW N: show Status("Dow n key pressed"); break; case
KeyEvent.VK_ENTER: show Status("Enter key pressed"); break; case KeyEvent.VK_LEFT: show Status("left
key pressed"); break; case KeyEvent.VK_RIGHT: show Status("right key pressed"); break; default : show
Status("nothing to print"); } } public void keyReleased(KeyEvent e) { show Status("Key released"); } public
void keyTyped(KeyEvent e) { msg=e.getKeyChar()+""; repaint(); } public void paint(Graphics g) { g.draw
String(msg,100,100);
}}
Select the missing statements in given code import java.aw t.*; import java.applet.*; /* <applet code="mouse
394 implements MouseMotionListener { String msg = ""; intmouseX = 0, mouseY = 0 public void init() 2 N U 2 import java.aw t.ev
{ } public void mouseDragged(MouseEvent me) { mouseX = me.getX(); mouseY = me.getY(); msg = "*";
show Status("Dragging mouse at " + mouseX + ", " + mouseY); repaint(); } public void
mouseMoved(MouseEvent me) { show Status("Moving mouse at " + me.getX() + ", " + me.getY()); } public
void paint(Graphics g) { g.draw String(msg, mouseX, mouseY); } }
395 Select the missing statements in the follow ing code import java.aw t.*; import java.applet.*; import java.aw t. 2 N A 2 t1=new TextField()
396 Select the Missing Statment in Program import java.aw t.*; import java.aw t.event.*; import java.applet.*; /* 2 N U 2 add(yes); add(no);
<applet code="ButtonDemo" w idth=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"); ----------------------- --------------
-------- ----------------------- yes.addActionListener(this); no.addActionListener(this);
maybe.addActionListener(this); } public void actionPerformed(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.draw
String(msg, 6, 100); } }
397 Select the proper code for the problem statement given below : Problem statement: Develope a prgram to 2 N A 2 import java.aw t,*;
display a button w ith a image icon on it using sw ing.The image on the button w ill change w hen the button
is clicked.
398 Select the proper command to run the follow ing code import java.aw t.*; import java.applet.*; import 2 N A 2 java fact
java.aw t.event.*; /*<applet code=fact.java w idth=400 height=400> </applet>*/ public class fact extends
Frame implements ActionListener { TextField t1,t2; Label l1,l2; Button b1; fact(String title) { super(title);
t1=new TextField(20); t2=new TextField(20); l1=new Label("ENTER NO"); l2=new Label("output"); b1=new
Button("find factorial"); setLayout(new GridLayout(3,2)); add(l1); add(t1); add(l2); add(t2); add(b1);
b1.addActionListener(this); addW indow Listener(new W indow Adapter() { public void w indow Closing(W
indow Event e) { System.exit(0); } }); } public static void main(String args[]) { fact f=new fact("factorial
example"); f.setVisible(true); f.setSize(300,300); } public void actionPerformed(ActionEvent ae) { String s;
int n; int fact=1; String s1=ae.getActionCommand(); if(s1.equals("find factorial")) { s=t1.getText();
n=Integer.parseInt(s); for(int i=1;i<=n;i++) { fact=fact*i; s=""+fact; t2.setText(s); } } } }
399 Select the proper command to run the follow ing code import java.aw t.*; import java.aw t.event.*; import java2 N A 2 appletview er comb
400 Select the proper method at _____________________ import java.aw t.*; import java.applet.*; import 2 N U 2 getActionCommand
java.aw t.event.*; public class applet2 extends Applet implements ActionListener { public void init() { Button
r=new Button("RED"); r.addActionListener(this); Button g=new Button("GREEN"); g.addActionListener(this);
Button b=new Button("BLUE"); b.addActionListener(this); add(r); add(g); add(b); } public void
actionPerformed(ActionEvent arg)
{ String click=arg._________________________(); if(click.equals("RED"))
setBackground(Color.red); else if(click.equals("GREEN")) setBackground(Color.green); else
if(click.equals("BLUE")) setBackground(Color.blue); } }
401 Select the proper method that can be used to handle the event import javax.sw ing.*; import java.aw t.*; 2 N A 2 actionPerformed(Ac
import java.aw t.event.*; public class JRadioDemo extends JApplet implements ActionListener { JRadioButton
r1,r2,r3; Container c; public void init() { c=getContentPane(); c.setLayout(new Flow Layout()); r1=new
JRadioButton("Red"); r2=new JRadioButton("Green"); r3=new JRadioButton("Blue"); ButtonGroup b=new
ButtonGroup(); b.add(r1);b.add(r2);b.add(r3); c.add(r1);c.add(r2);c.add(r3); r1.addActionListener(this);
r2.addActionListener(this); r3.addActionListener(this); } public void
_____________________________ { if(a.getSource()==r1) c.setBackground(Color.RED); else
if(a.getSource()==r2) c.setBackground(Color.GREEN); else c.setBackground(Color.BLUE); } } /*
<applet code=JRadioDemo.class w idth=500 height=500></applet>*/
402 Select the proper method to handle event in the follow ing program. import java.aw t.*; import java.aw 2 N U 2 adjustmentValueCh
t.event.AdjustmentEvent; import java.aw t.event.AdjustmentListener; import java.aw t.event.W indow
Adapter; import java.aw t.event.W indow Event; public class AdjustmentEventExample { public static void
main(String[] args) { Frame frame = new Frame("AdjustmentEventExample"); Label label = new Label("W
elcome To Java Programing"); Scrollbar h = new Scrollbar(Scrollbar.HORIZONTAL, 30, 20, 0, 300); Scrollbar v
= new Scrollbar(Scrollbar.VERTICAL, 30, 40, 0, 300); frame.setLayout(new BorderLayout()); frame.add(h,
BorderLayout.SOUTH); frame.add(v, BorderLayout.EAST); frame.add(label, BorderLayout.CENTER);
AdjustmentListener ad = new MyAdjustmentListener(); h.addAdjustmentListener(ad);
v.addAdjustmentListener(ad); frame.setSize(400, 400); frame.setVisible(true); frame.addW indow
Listener(new W indow Adapter() { public void w indow Closing(W indow Event e) { System.exit(0); } }); } }
class MyAdjustmentListener implements AdjustmentListener { public void
_____________________________________________ { System.out.println(ae.getValue()); }
}
403 select the proper methods of mouse motion listener 2 N U 2 void mouseMoved(MouseEvent me
404 Select the proper output for follow ing code import java.aw t.BorderLayout; import java.aw t.event.ActionEvent;2 Y2 A 2
405 Select the proper output for follow ing code import java.applet.Applet; import java.aw t.*; import java.applet.*;2 Y2 U 2 A
406 Select the proper output for follow ing code import java.aw t.*; import java.applet.*; public class S1Q31 extend2 Y2 U 2
407 Select the proper output for follow ing code import java.aw t.*; import java.aw t.event.*; import 2 Y2 A 2 S1Q47O1
java.applet.*; public class Demo extends Applet implements ItemListener { Checkbox cb1,cb2,cb3; public
void init() { cb1=new Checkbox("Red"); cb2=new Checkbox("Green"); cb3=new Checkbox("Blue"); add(cb1);
add(cb2); add(cb3); cb1.addItemListener(this); cb2.addItemListener(this); cb3.addItemListener(this); }
public void itemStateChanged(ItemEvent ie) { if(ie.getSource()==cb1) setBackground(Color.RED); else
if(ie.getSource()==cb2) setBackground(Color.YELLOW ); else setBackground(Color.BLUE); } } /*
<applet code="Demo.class" w idth=300 height=200></applet>*/
408 Select the proper output for follow ing code import java.aw t.*; import java.util.*; import javax.sw ing.tree.*; 2 Y2 U 2
class JMyTree extends JFrame { Container con; JTree jt1; Vector v; JMyTree()
{ con=this.getContentPane(); con.setLayout(new Flow Layout());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); v=new Vector(); v.addElement("My Computer");
v.addElement("D Drive"); v.addElement("E Drive"); jt1=new JTree(v); con.add(jt1);
} public static void main(String a[]) { JMyTree jf=new JMyTree(); jf.setSize(300,400);
jf.setVisible(true); } }
409 Select the proper output for follow ing code importjava.aw t.*; importjava.applet.*; public class list2 extends Ap2 Y2 A 2
410 select the proper output for the follow ing code import java.aw t.event.*; public class eh extends Applet implem2 Y2 A 2
412 State listener w ith its method used in follow ing program import java.aw t.*; import java.aw t.event.*; 2 N A 2 ActionListener,actio
import java.applet.*; /* <applet code=exp2.class w idth=200 height=200 >
</applet>*/ public class exp2 extends Applet implements ActionListener { TextField t1,t2; Button b1; Label
l1,l2; public void init() { t1=new TextField(5); t2=new TextField(5); b1=new Button("Factorial"); l1=new
Label("Enter no"); l2=new Label("Factorial is :"); add(l1); add(t1); add(b1); add(l2); add(t2);
b1.addActionListener(this); } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==b1) { int
n1=Integer.parseInt(t1.getText()); int fact=1,i; for(i=1;i<=n1;i++) { fact=fact*i; }
t2.setText(Integer.toString(fact)); } } }
413 State the missing statement in the program for follow ing output import javax.sw ing.*; public class MyMenu 2 Y1 A 2 all of the above
{ public static void main(String args[]) { JFrame frame; JMenuBar mb; frame=new JFrame("Frame w ith a
Menu"); mb=new JMenuBar(); frame.setJMenuBar(mb); JMenu mFile,mEdit; mFile=new JMenu("File");
mEdit=new JMenu("Edit"); JMenuItem mNew ,mClose,mCopy,mPaste; mNew =new JMenu("New ");
mClose=new JMenu("Close"); mCopy=new JMenu("Copy"); mPaste=new JMenu("Paste"); mFile.add("mNew
"); mFile.add("mclose"); mEdit.add("mCopy"); mEdit.add("mPaste"); JCheckBoxMenuItem mPrint;
mPrint=new JCheckBoxMenuItem("Print"); mFile.addSeparator(); JMenu mFont; mFont=new JMenu("Font");
mFile.add(mFont); mFont.add("Arial"); mFont.add("Times New Roman"); frame.setSize(400,400);
frame.setVisible(true); } }
Figure:-
414 state the output in follow ing code import java.aw t.*; import java.applet.*; import java.aw t.event.*; public 2 N A 2 sb1 Scrollbar is disp
class Scrollbarapp extends Applet implements AdjustmentListener { Scrollbar sb1,sb2; @Override public void
init() { // TODO Auto-generated method stub sb1=new Scrollbar(); sb2=new
Scrollbar(Scrollbar.HORIZONTAL, 200,0, 0, 500); add(sb1); add(sb2); sb2.addAdjustmentListener(this); }
@Override public void adjustmentValueChanged(AdjustmentEvent e) { // TODO Auto-generated method stub
repaint();
} @Override public void paint(Graphics g) { // TODO Auto-generated method stub
416 The AW T container is an instance of the ___________ class w hich holds various components and other contain2 N U 2 Container
417 The constructor that is defined by the Text Event class is: 2 N U 2 TextEvent(Obect source,int event_
418 The focusEvent can be recognized by tw o integer constant. 2 N U 2 Focus_Gained and Focus_Lost
419 The follow ing program contains some errors. Select the correct option to indicate them. import java.aw t.*; imp2 N A 2 Incorrect Listener m
420 The follow ing program w ill increase the font size of a given string by 2 point w ith every mouse click(max 10 2 N A 2 addMouseListener(t
clicks). Select the missing statement and indicate w here the statement should be added. import java.aw t.*;
import java.applet.*; import java.aw t.event.*; public class sample4 extends Applet implements
MouseListener { Font f; int i=0,c=14; public void init() { f=new Font("Times New Roman",Font.BOLD,c);
setFont(f); } public void mousePressed(MouseEvent me)
{ if(i<10) { c=c+2; f=new Font("Times New Roman",Font.BOLD,c); setFont(f); } i=i+1; } public void
mouseClicked(MouseEvent me) {} public void mouseReleased(MouseEvent me) {} public void
mouseEntered(MouseEvent me) {} public void mouseExited(MouseEvent me) {} public void paint(Graphics g)
{ g.draw String("Java prog",50,50); } }
421 The follow ing steps are required to perofrm 1) implement the Listener interface and overrides its methods 2) R 2 N U 2 Event Handling
422 The follow ing w indow Event defined by W indow Event Class. 2 N U 2 W indow _Activated,W indow _ICONI
423 The given code produces w hich event : import java.aw t.*; import java.applet.*; import java.aw t.event.*; 2 N A 2 Action Listner
/*<applet code=Fact height=150 w idth=200> </applet>*/ public class Fact extends Applet implements
ActionListener { int fact,n; TextField t1,t2; Button b1; Label l1,l2; public void init() { t1= new TextField(5);
t2= new TextField(5); l1= new Label("Enter number"); l2= new Label("Factorial is:"); b1=new Button("Find
Factorial"); b1.addActionListener(this);
//GridLayout g= new GridLayout(5,2); //setLayout(g); add(l1); add(t1); add(l2); add(t2); add(b1); } public
void actionPerformed(ActionEvent e) { if(e.getSource()==b1) { n= Integer.parseInt(t1.getText()); fact=1;
for(int i=1; i<=n; i++) { fact=fact*i; } t2.setText(Integer.toString(fact)); } repaint(); } }
424 The signature for the registration method for an ActionEvent should be __________. 2 N A 2 public void addActionListener(Actio
425 The value typed in TextArea is notified by________________Listener. 2 N A 2 TextListener
427 The ______________ class has tw o methods, mouseDragged() and mouseMoved() 2 N U 2 MouseMotionListener
428 To register a checkbox to event class follow ing statement must be get included in your program 2 N A 2 Both A & B
To get the follow ing output complete the code given below . import java.aw t.*; import javax.sw ing.*; /* JPaneljp = new JPa
<applet code="jscroll" w idth=300 height=250> </applet> */ public class jscroll extends JApplet { public
void init() { Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); } } int
v = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALW AYS; int h =
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPanejsp = new
JScrollPane(jp, v, h); contentPane.add(jsp, BorderLayout.CENTER); } } Figure:-
430 To get the follow ing output complete the code given below . import java.aw t.*; import java.aw t.event.*; 2 Y1 U 2 table = new JTable
import javax.sw ing.*; class SimpleTableExample extends JFrame { private JPanel topPanel; private JTable JScrollPane( table )
table; private JScrollPane scrollPane; public SimpleTableExample() { setTitle( "Simple Table Application" );
setSize( 300, 200 ); setBackground( Color.gray ); topPanel = new JPanel(); topPanel.setLayout( new
BorderLayout()
); getContentPane().add( topPanel ); String columnNames[] = { "Column 1", "Column 2", "Column 3" };
String dataValues[][] = { { "12", "234", "67" }, { "-123", "43", "853" }, { "93", "89.2", "109" }, { "279",
"9033", "3092" } }; topPanel.add( scrollPane, BorderLayout.CENTER );
} public static void main( String args[] ) { SimpleTableExample mainFrame = new
SimpleTableExample(); mainFrame.setVisible( true ); } } Figure:-
431 To get the proper output complete the code given below . import java.aw t.*; import java.aw t.event.*; 2 N U 2 All of the above
import java.applet.*; public class DemoKeyEvent extends Applet implements KeyListener { public void init() {
this.addKeyListener(this); } public void keyTyped(KeyEvent ke)
{ show Status("Key Typed"); } } /*<applet code="DemoKeyEvent.class" w idth=300 height=300>
</applet>*/
432 To handle JRadiobutton w hich Listener and Event Class is Required? Figure:- 2 Y1 U 2 ActionListener and
433 To have the follow ing output Inser proper commands in the given code at*__________________ import 2 Y2 A 2 JApplet implements
java.aw t.*; import java.aw t.event.*; import java.applet.*; import javax.sw ing.*; /*<applet
code="SimpleKey1.class" w idth=400 height=400></applet>*/ public class SimpleKey1 extends
*_________________________________________________
{ String msg=""; int x=10,y=20; public void init() { addKeyListener(this); requestFocus(); } public void
*___________________________________ { show Status("Key Dow n"); } public void
keyReleased(KeyEvent ke) { show Status("Key Up"); } public void keyTyped(KeyEvent ke) { msg
+=ke.getKeyChar(); repaint(); } public void paint(Graphics g) { g.draw String(msg,40,80); }
}
434 To use the ActionListener interface it must be implemented by class there are several w ays to do that find in th2 N U 2 D. All mentioned ab
435 User clicks a button, presses Return w hile typing in a text field, or chooses a menu item w ill use the follow ing2 N A 2 ActionListener
436 W hat type of eventlisteners can be added to the follow ing code import java.aw t. Container; import java.aw t. 2 N A 2 C. both A and B
437 w hat are the content are show n by follow ing code import java.aw t.*; import javax.sw ing.*; public class 2 N A 2 The output contains
JTabbedPaneDemo extends JApplet { public void init() { JTabbedPane jtp = new JTabbedPane(); ith JPanel
jtp.addTab("Cities", new ButtonPanel()); jtp.addTab("Table", new TablePanel()); jtp.addTab("flavours", new
flavoursPanel()); jtp.addTab("colours", new ColorsPanel());
Container contentPane = getContentPane(); contentPane.add(jtp); } } class ButtonPanel extends JPanel {
public ButtonPanel() { JButton b1 = new JButton("Parbhani"); JButton b2 = new JButton("Pune"); JButton b3
= new JButton("Mumbai"); JButton b4 = new JButton("Aurangabad"); JButton b5 = new JButton("Nanded");
add(b1); add(b2); add(b3); add(b4); add(b5); } } class ColorsPanel extends JPanel { public ColorsPanel() {
JCheckBox cb1=new JCheckBox("Red"); add(cb1); JCheckBox cb2=new JCheckBox("Green"); add(cb2);
JCheckBox cb3=new JCheckBox("Blue"); add(cb3); } } class TablePanel extends JPanel { public TablePanel()
{ String colHead[] = {"Event Source", "Event Type", "Event Listener"}; Object data[][] = { {"Button",
"ActionEvent", "ActionListener"}, {"ScrollBar", "AdjustmentEvent", "AdjustmentListener"}, {"Choice",
"ItemEvent", "ItemListener"}, {"TextField", "TextEvent", "TextListener"} }; JTable table = new JTable(data,
colHead); int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h =
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPane jsp = new JScrollPane(table, v, h);
setLayout(new BorderLayout()); add(jsp, BorderLayout.CENTER); } } class flavoursPanel extends JPanel {
public flavoursPanel() { JComboBox jc=new JComboBox();
jc.addItem("vannila"); jc.addItem("Chocolate"); jc.addItem("strabary"); add(jc); } } W hat w ill be the output
of the above program?
W hat are the minimum pakages required for executing the bellow program? class MyDemo extends Frame { Bu
438 Button("OK"); add(b); b.addActionListener(this); setLayout(new Flow Layout()); } public void actionPerformed( 2 N U 2 java.aw t.* and java.aw t.event.*
439 W hat error w ill occur w hile running given applet? import java.aw t.*; import java.aw t.event.*; import java.ap2 N A 2 NullPointerExceptio
440 W hat is error in follow ing program? import java.aw t.*; import java.aw t.event.*; import java.applet.*; /* <ap2 N A 2 ScrollDemo is not a
adjustmentValueCh
ScrollDemo extends
441 W hat is missing in follow ing code ? import java.aw t.*; import java.applet.*; /*<applet code=FontExample.cla2 N A 2 setFont(f)
442 W hat is missing in the follow ing program code? import java.aw t.*; ------------------------- public class DemoF 2 N U 2 All of the mentione
443 W hat is missing statement here ------------------ import java.aw t.*; import javax.sw ing.*; import java.aw 2 N A 2 All of the above
t.event.*; public class Radiodemo extends JFrame implements ActionListener { Container cp; JRadioButton
jb1,jb2,jb3; Radiodemo(String str) { super(str); cp=getContentPane(); cp.setLayout(new Flow Layout());
jb1=new JRadioButton("Red"); jb2=new
JRadioButton("Green"); jb3=new JRadioButton("Blue"); ButtonGroup bg=new ButtonGroup(); bg.add(jb1);
bg.add(jb2); bg.add(jb3); cp.add(jb1); cp.add(jb2); cp.add(jb3); } public void actionPerformed(ActionEvent
ae) { if(ae.getSource()==jb1) { cp.setBackground(Color.red); } if(ae.getSource()==jb2) {
cp.setBackground(Color.green); } if(ae.getSource()==jb3) { cp.setBackground(Color.blue); } } public static
void main(String args[]) { Radiodemo r=new Radiodemo("Changing Color"); r.setVisible(true);
r.setSize(500,400); } }
444 W hat is output of follw ong program ? import java.aw t.*; import java.aw t.event.*; public class MyW c extends2 N A 2 Error at compile tim
445 W hat is output of follow ing code. import java.aw t.*; import java.aw t.event.*; import java.applet.*; /* 2 Y2 A 2
<applet code="SimpleKey" w idth=300 height=100> </applet> */ public class KeyEventDemo extends
Applet implements KeyListener { String msg = ""; int X = 10, Y = 20; public void init() {
addKeyListener(this); requestFocus(); } public void keyPressed(KeyEvent ke)
{ show Status("Key Dow n"); } public void keyReleased(KeyEvent ke) { show Status("Key Up"); } public void
keyTyped(KeyEvent ke) { msg += ke.getKeyChar(); repaint(); } // Display keystrokes. public void
paint(Graphics g) { g.draw String(msg, X, Y); } }
W hat is output of follow ing program? import java.applet.Applet; import java.aw t.Graphics; import java.aw t.B
446 </applet> */ public class DetermineIfButtonEnabled extends Applet{ boolean isButton1Enabled; boolean 2 Y1 U 2 Is Button 1 enabled
isButton2Enabled; public void init(){ //create Buttons Button Button1 = new Button("Ok"); Button Button2 =
new Button("Cancel"); //add Buttons add(Button1); add(Button2); Button1.setEnabled(false);
isButton1Enabled = Button1.isEnabled(); isButton2Enabled = Button2.isEnabled(); } public void
paint(Graphics g){ g.draw String("Is
Button 1 enabled? " + isButton1Enabled, 10,50); g.draw String("Is Button 2 enabled? " +
isButton2Enabled, 10,70); } } Figure:-
447 W hat is the correct code to create Button w ith caption Ok? 2 N A 2 None of above
448 W hat is the correct syntax of method required in the given program given below . import java.aw t.*; import 2 N A 2 public void itemSta
java.aw t.event.*; import java.applet.*; public class eventdemo extends Applet implements ItemEvent {
public void init() { Choice c= new Choice(); TextField t1=new TextField(); add(c); c.addItemListener(this);
add(t1); } public void
_______________________(___________) { { t1.setText(c.getSelectedIteml()); } } }
449 W hat is the highest-level event class of the event-delegation model? 2 N U 2 java.util.eventObject
450 W hat is the missing Exception in follow ing program /* <applet code="TestMouse.class" w idth=300 2 N A 2 both A & B
height=100> </applet> */ importjava.aw t.*; importjava.aw t.event.*; importjava.applet.*; public class
TestMouse extends Applet implements_____________________ { String msg = ""; intmouseX = 0, mouseY
= 0 public void init() { addMouseListener(this); addMouseMotionListener(this); } public void
mouseClicked(MouseEvent me) { mouseX = 0; mouseY = 10; msg = "Mouse clicked."; repaint();
} public void mouseEntered(MouseEvent me) { mouseX = 0; mouseY = 10; msg = "Mouse entered.";
repaint(); } public void mouseExited(MouseEvent me) { mouseX = 0; mouseY = 10; msg = "Mouse exited.";
repaint(); } public void mousePressed(MouseEvent me) { mouseX = me.getX(); mouseY = me.getY(); msg =
"Dow n"; repaint(); } public void mouseReleased(MouseEvent me) { mouseX = me.getX(); mouseY =
me.getY(); msg = "Up"; repaint(); } public void mouseDragged(MouseEvent me) { mouseX = me.getX();
mouseY = me.getY(); msg = "*"; show Status("Dragging mouse at " + mouseX + ", " + mouseY); repaint();
} public void mouseMoved(MouseEvent me) { show Status("Moving mouse at " + me.getX() + ", "
+ me.getY()); } public void paint(Graphics g) { g.draw String(msg, mouseX, mouseY); } }
451 W hat is the missing in follow ing block of code? Public class JTextField extends JApplet { JTextField jtf; Public v2 N A 2 semicolon missing
452 W hat is the output of follow ing program : import java.aw t.*; import java.aw t.event.*; import java.applet.*; /2 N A 2 Key Up
453 w hat is the output of this program import java.aw t.*; import java.aw t.event.*; public class CloseDemo3 { pub2 N A 2 W indow is closed
454 W hat is the output of this program? Figure:- 2 Y1 A 2 W ill not show any
455 W hat is the output of this program? import java.aw t.*; import java.applet.*; import java.aw t.event.*; /*<app2 Y2 A 2
456 W hat is the preferred w ay to handle an object's events in java? 2 N A 2 Add one or more event listener to
457 W hat is the return type of the method getSource() defined in EventObject class. Select the one correct answ er 2 N U 2 object
458 W hat is use of of using action listeners in the follow ing program? import java.applet.*; import java.aw 2 N A 2 To handle the even
t.event.*; import java.aw t.*; public class EventListeners extends Applet implements ActionListener{
TextArea txtArea; String Add, Subtract,Multiply,Divide; int i = 10, j = 20, sum
=0,Sub=0,Mul = 0,Div = 0; public void init(){ txtArea = new TextArea(10,20); txtArea.setEditable(false);
add(txtArea,"center"); Button b = new Button("Add"); Button c = new Button("Subtract"); Button d = new
Button("Multiply"); Button e = new Button("Divide"); b.addActionListener(this); c.addActionListener(this);
d.addActionListener(this); e.addActionListener(this); add(b); add(c); add(d); add(e); } public void
actionPerformed(ActionEvent e){ sum = i + j; txtArea.setText(""); txtArea.append("i = "+ i + "\t"
+ "j = " + j + "\n"); Button source = (Button)e.getSource(); if(source.getLabel() == "Add"){
txtArea.append("Sum : " + sum + "\n"); } if(i >j){ Sub = i - j; } else{ Sub = j - i; } if(source.getLabel() ==
"Subtract"){ txtArea.append("Sub : " + Sub + "\n"); } Mul = i*j; if(source.getLabel() == "Multiply"){
txtArea.append("Mul = " + Mul + "\n"); } if(i > j){ Div = i / j; } else{ Div = j / i; } if(source.getLabel() ==
"Divide"){ txtArea.append("Divide = " + Div); } } }
Here is the HTML code of the program : <HTML> <BODY> <APPLET CODE ="EventListeners" W IDTH="800"
HEIGHT="500"></APPLET> </BODY> </HTML>
459 W hat is w rong in below program import java.aw t.*; import java.aw t.event.*; import java.applet.*; /*<apple 2 N A 2 The keydemo class
460 W hat method is used to handle item events from menus, checkboxes, and radio buttons? 2 N U 2 itemStateChanged()
W hat should be added so that w e can get follow ing output ? import java.aw t.*; import java.aw t.event.*; imp
462 W hat should be w ritten for ****** in follow ing code ? import java.aw t.*; import java.aw t.event.*; import 2 N A 2 AdjustmentValueCh
java.applet.*; /*<applet code=ScrollDemo.class height=400 w idth=600></applet>*/ public class
ScrollDemo extends Applet implements AdjustmentListener
{ Scrollbar v; public void init() { v=new Scrollbar(); add(v); v.addAdjustmentListener(this); }
public void *****************(AdjustmentEvent ae) { } }
463 W hat w ill be correct code for given output 2 Y1 A 2 import java.aw t.*;
Figure:- class assign extend
ButtonGroup bg; pu
ContentPane=getCo
Layout()); JRadioBu
464 W hat w ill be output for follow ing program: import java.aw t.*; import java.applet.*; import java.aw t.event.* 2 Y2 A 2 Compile time error
465 W hat w ill be output if user select second item from choice component in follow ing program: import java.aw t. 2 Y2 A 2 S1Q50O2
466 W hat w ill be output of follow ing code import javax.sw ing.*; import javax.aw t.*; public class Test extends JF 2 N A 2 Four buttons are di
467 W hat w ill be output of follow ing program import java.aw t.*; import java.applet.*; import java.aw t.event.*; 2 N U 2 One Button w ill be
468 W hat w ill be output of program w hen "Ok" button is pressed? import java.applet.Applet; import java.aw 2 Y2 U 2 OK button pressed
t.Button; import java.aw t.Graphics; import java.aw t.event.ActionEvent; import java.aw
t.event.ActionListener; /* <applet code="HandleActionEventExample" w idth=200 height=200> </applet> */
public class HandleActionEventExample extends Applet implements ActionListener{ String actionMessage="";
public void init(){ Button Button1 = new Button("Ok"); Button Button2 = new Button("Cancel");
add(Button1); add(Button2); Button1.addActionListener(this); Button2.addActionListener(this); } public void
paint(Graphics g)
{ g.draw String(actionMessage,10,50); } public void actionPerformed(ActionEvent ae){ String action =
ae.getActionCommand(); if(action.equals("Ok")) actionMessage = "Ok Button Pressed"; else
if(action.equals("Cancel")) actionMessage = "Cancel Button Pressed"; repaint(); } }
469 W hat w ill be the output of follow ing code? import java.applet.*; import java.aw t.event.*; /* 2 Y2 A 2 S15004
<applet code="InnerClassDemo" w idth=200 height=100> </applet> */ public class InnerClassDemo extends
Applet { public void init() { addMouseListener(new MyMouseAdapter()); } class MyMouseAdapter extends
MouseAdapter { public void mousePressed(MouseEvent me) { show Status("Mouse Pressed"); } } }
470 W hat w ill be the output of follow ing code? import java.aw t.*; import java.aw t.event.*; import java.applet.*;2 Y2 A 2 S14802
471 W hat w ill be the output of follow ing code? import java.aw t.*; import java.applet.*; import java.aw 2 Y2 A 2 46o1
t.event.*; public class ButtonDemo1 extends Applet implements ActionListener { String msg=" "; Button
b1,b2,b3; public void init() { b1=new Button("Red"); b2=new Button("Green"); b3=new Button("Blue");
add(b1); add(b2); add(b3); b1.addActionListener(this); b2.addActionListener(this);
b3.addActionListener(this); } public void actionPerformed(ActionEvent ae) { String
str=ae.getActionCommand(); if (str.equals("Red")) {
setBackground(Color.red); } else if (str.equals("Green")) { setBackground(Color.green); } else if
(str.equals("Blue")) { setBackground(Color.blue); } repaint(); } public void paint(Graphics g) { g.draw
String(msg,0,100); } } /*<applet code="ButtonDemo1.class" w idth=200 height=400>
</applet>*/
472 W hat w ill be the output of follow ing prgram? import java.aw t.*; import java.aw t.event.*; class Sample exten2 N A 2 A frame w indow w
473 W hat w ill be the output of given code import java.aw t.*; import java.aw t.event.*; import javax.sw ing.*; 2 Y2 A 2 A and B
import java.applet.*; public class expt4 extends JApplet implements ActionListener { JComboBox cb; public
void init() { Container co=getContentPane(); co.setLayout(new Flow Layout()); JComboBoxcb=new
JComboBox(); cb.addItem("Cricket"); cb.addItem("Football"); cb.addItem("Hockey");
cb.addActionListener(this); co.add(cb); } public void actionPerformed(ActionEvent AE) {
cb=(JComboBox)AE.getSource(); if("Cricket"==cb.getSelectedItem()) {
getContentPane().setBackground(Color.RED); } if("Football"==cb.getSelectedItem()) {
getContentPane().setBackground(Color.GREEN); }
if("Hockey"==cb.getSelectedItem()) { getContentPane().setBackground(Color.BLUE); } repaint();
} } /*<APPLET CODE="expt4.class" HEIGHT=200 W IDTH=200></APPLET>*/
474 W hat w ill be the output of the above program: import java.applet.*; import java.aw t.*; import java.aw 2 N A 2 W elcome to java p
t.event.*; /* <appet code=”fontdemo” w idth=200 height=100> </applet> */ public class fontdemo extends
Applet { int next=0; Font f; String msg; public void init() { setBackground(Color.yellow );
setForeground(Color.magnenta); f=new Font(“Times New Roman”, Font.ITALIC,18); msg=”W elcome to java
Programming”; setFont(); } Public void paint(Graphics g)
{ g.draw String(msg,100,50); }
475 W hat w ill be the output of the program given below import java.aw t.*; import java.applet.*; import java.aw t2 N U 2 The output w ill dis
Programming"
increase by tw o po
476 W hat w ill be the output of the program? Figure:- 2 Y1 A 2 Compilation error
477 W hat w ill be the output of the program? Figure:- 2 Y1 A 2 W ill produce label
478 w hat w ill be the result of follow ing code if value of no1=no2=no3=2 and Button pressed="ok"; import java.aw2 N A 2 6
481 W hat w ill happen w hen you attempt to compile and run the follow ing code? import java.aw t.*; import java.a2 N A 2 Compile time error
482 W hen a program class implements an interface, it must provide behavior for 2 N U 2 all methods defined in that interfa
483 W hen ContainerEvent is generated, follow ing action is done- 2 N U 2 Component is added or removed
484 W hen the event source generates an event the event source notifies to .............. that the event has occurred. 2 N U 2 all the listener obje
485 W hen the given output is generated ? Figure:- 2 Y1 U 2 W hen Alphabet key
486 W hen tw o or more object are added as listeners for the same events ,ehich listener is first invoked to handle t 2 N U 2 The last object that
487 W hen tw o or more objects are added as listeners for the same event, w hich listener is first invoked to handle 2 N A 2 There is no w ay to
488 W hen tw o or more objects are added as listeners for the same event, w hich listener is first invoked to handle 2 N U 2 The last object that
489 W hen tw o or more objects are added as listeners for the same events,w hich listener is first invoked to handled2 N U 2 There is no w ay to
490 W hen user change text present In text field then that event listen by 2 N U 2 TextListener
491 W hen you run the follow ing applet from a brow ser, w hat is displayed: import javax.sw ing.*; public class Tes2 N U 2 Default constructor
492 W hether the given code is correct to generate the given output import java.applet.*; import java.aw t.*; 2 Y1 A 2 No
public class MyControl5 extends Applet implements ActionListener { List l; TextField t; Button b; public void
init() { b=new Button("Add"); l=new List(); t=new TextField(); add(b); add(l); add(t);
b.addActionListener(this); } public void actionPerformed(ActionEvent ae) { l.add(t.getText()); } }
Figure:-
493 W hich of these events w ill be generated if w e close an applet's w indow ? 2 N A 2 W indow Event
494 W hich among the follow ing is true about the event? 2 N U 2 all of these
495 W hich are passive controls that do not support any interaction w ith the user? 2 N U 2 Labels
497 W hich AW T control is required for geting follow ing output 2 Y1 A 2 Label
Figure:-
498 W hich class header w ould be used to create an applet that accepts a click on a button? 2 N U 2 public class MyApplet extends Japp
499 W hich class is used for this Processing Method processActionEvent( )? 2 N A 2 Button,List,MenuItem
500 W hich controls are used to get the follow ing output 2 Y1 A 2 TextField, TextArea
Figure:-
501 W hich Event is /are handdled on List Component 2 N A 2 Any of one depends on single click
502 W hich Event is generated w hen a component is added to or removed from a container 2 N U 2 ContainerEvent
503 W hich Event is generated w hen applet w indow is closed by user? 2 N U 2 W indow Event
504 W hich event is generated w hen the position of scrollbar is changed.Select the correct answ er. 2 N A 2 AdjustmentEvent
505 w hich Event is required in to minimize and close the object draw n by the follow ing code import java.aw t. *; i 2 N A 2 C. W indow listener
506 W hich import statement is used for follow ing program. /* <applet code=exp1.class w idth=200 height=200> <2 N A 2 import java.aw t.ev
507 W hich is mssing statement in the follow ing code import java.aw t.*; import java.aw t.event.*; 2 N A 2 g1.addActionListene
import javax.sw ing.*; import java.applet.*; /*<applet code="JRadio1" w idth=300 height=100>
</applet>*/ public class JRadio1 extends JApplet implements ActionListener { Container
ContentPane=getContentPane(); JTextField tf; public void init() { ContentPane.setLayout(new Flow Layout());
JRadioButton r1=new JRadioButton("Red"); r1.addActionListener(this); ContentPane.add(r1); JRadioButton
g1=new JRadioButton("Green"); ContentPane.add(g1); JRadioButton b1=new JRadioButton("Blue");
b1.addActionListener(this); ContentPane.add(b1); ButtonGroup bg=new ButtonGroup(); bg.add(r1);
bg.add(g1); bg.add(b1); tf=new JTextField(5); ContentPane.add(tf); } public void
actionPerformed(ActionEvent ae) { String s; s=ae.getActionCommand(); if(s=="Red")
ContentPane.setBackground(Color.red); else if(s=="Green") ContentPane.setBackground(Color.green); else
if(s=="Blue") ContentPane.setBackground(Color.blue); } }
509 W hich line of code is missing in follow ing code import java.aw t.*; import java.aw t.event.*; import 2 N A 2 public void keyRele
java.applet.*; /*<applet code="KeyEventDemo.class" w idth=400 height=400> </applet>*/ }
public class KeyEventDemo extends Applet implements KeyListener { String msg=""; public void init() {
addKeyListener(this); } public void keyPressed(KeyEvent e) { show Status("Key Dow n"); int
key=e.getKeyCode(); repaint(); } public void keyTyped(KeyEvent e) { msg+=e.getKeyChar(); repaint(); }
public void paint(Graphics g) { g.draw String(msg,10,20); } }
510 W hich line of code is missing in follow ing code and error statement code line import java.aw t.*; import 2 N A 2 KeyListener public
java.aw t.event.*; import java.applet.*; /*<applet code="KeyEventDemo.class" w idth=400 height=400> show Status("
</applet>*/ public class KeyEventDemo extends Applet implements
_____________ { String msg=""; public void init() { addKeyListener(this); } public void
keyPressed(KeyEvent e) { show Status("Key Dow n"); int key=e.getKeyCode(); repaint(); } public void
keyTyped(KeyEvent e) { msg+=e.getKeyChar(); repaint(); } public void paint(Graphics g) { g.draw
String(msg,10,20); } }
w hich listener is missing in follow ing code.? import java.aw t.*; import java.aw t.event.*; import
511 java.applet.*; public class TextField_Demo extends Applet implements ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬ { Label l1,l2; 2 N A 2 ActionListener
515 W hich method is missing in the code given below :import java. Aw t. *; import java.aw t.event.*; class Aevent 2 N A 2 b.addActionListener
(100,120,80,30); add ( b);add(tf); setSize(3600,300); setLayout(null); setVisible (true); } public void actionPe
516 W hich method ******** is missing in follow ing program. import java.aw t.*; import java.aw t.event.*; 2 N A 2 w indow Closing()
class FrameDemo extends Frame { FrameDemo() { addW indow Listener(new MyW indow Adapter()); } public
static void main(String args[]) { FrameDemo f=new FrameDemo(); f.setSize(100,200); f.setTitle("Frame w
indow "); f.setVisible(true); } public void paint(Graphics g)
{ g.draw String("this is a frame",100,200); } class MyW indow Adapter extends W indow Adapter {
public void ********* (W indow Event w e) { System.exit(0); } } }
517 W hich method identifies the type of an event generated. Select the one correct answ er. 2 N U 2 getID()
519 W hich method is missing in follow ing program. import java.aw t.*; import java.aw t.event.*; import java.apple2 N A 2 mouseMoved()
520 W hich method is missing in follow ing program. import java.aw t.*; import java.aw t.event.*; import java.apple2 N A 2 mouseReleased()
524 W hich of the follow ing are valid return types, for listener methods ? 2 N A 2 void
525 W hich of the constant(s) from follow ing constants is defined in W indow Event class? 2 N U 2 ALL ABOVE
528 W hich of the follow ing code is required to display output in table format. 2 N U 2 Container c1=getContentPane(); c
529 w hich of the follow ing components generate item event 2 N A 2 Button
530 W hich of the follow ing does NOT generate GUI events? 2 N U 2 Displaying the text in a label.
531 W hich of the follow ing does not have it default Layout as BorderLayout 2 N U 2 Panel
532 W hich of the follow ing event of KeyEvent class is generated w hen a character is pressed? 2 N U 2 All of above
534 W hich of the follow ing handles event in Event Delegation Model? 2 N U 2 Listener
535 W hich of the follow ing integer constants are defined by AdjustmentEvent class that can be used to identify adj 2 N A 2 All are defined
536 w hich of the follow ing is not type of keyEvent class 2 N U 2 KEY_DOW N
537 W hich of the follow ing is the highest class in the event delegation class hierarchy? Figure:- 2 N U 2 java.util.EventObje
538 W hich of the follow ing methods of ItemListener must be overriden in order to handle ItemEvent? 2 N U 2 public void itemStateChanged(Ite
539 W hich of the follow ing MouseMotionListener interface methods? 2 N U 2 mouseDragged(MouseEvent me),
540 W hich of the follow ing statements are true? A. All events w ill be processed in the order, the listener w ere add2 N U 2 C and D
541 W hich of the follow ing statements are true? 2 N A 2 JButton has a const
542 W hich of the follow ing statements is true about MouseMotionListener? 2 N U 2 All of the mentioned
543 W hich of the follow ing statements registers a panel object p as a listener for a button variable jbt? 2 N U 2 jbt.addActionListen
544 W hich of the follw ing component cannot be registared w ith actionPerformed() method of 2 N U 2 CheckBox
ActionListener?
545 W hich of these are constants defined in W indow Event class? 2 N U 2 All of the mentioned
546 W hich of these are integer constants defined in ActionEvent class? 2 N A 2 ALL of the mentioned
548 W hich of these are integer constants of ComponentEvent class? 2 N A 2 All of the mentioned
549 W hich of these constant value w ill change w hen the button at the end of scroll bar w as clicked to increase its2 N U 2 UNIT_INCREMENT
550 W hich of these event w ill be generated if w e close an applet w indow ? 2 N U 2 W indow Event
553 W hich of these events is generated w hen the component is added or removed? 2 N U 2 ContainerEvent
554 w hich of these events w ill be generated if w e close an applet's w indow ? 2 N A 2 W indow Event
555 W hich of these Events w ill be notified if scroll bar is manipulated 2 N U 2 AdjustmentEvent
556 w hich of these Integer Constant Are defined in ActionEventClass 2 N A 2 all of the these
558 W hich of these interfaces handles the event w hen a component is added to a container? 2 N U 2 ContainerListener
560 W hich of these methods are used to register a keyboard event listener? 2 N U 2 addKeyListener()
561 w hich of these methods are used to register a mouse motion listener? 2 N A 2 addMouseMotionListener()
562 W hich of these methods can be used to obtain the coordinates of a mouse? 2 N U 2 getPoint()
563 W hich of these methods can be used to obtain the reference to the container that generated a 2 N U 2 getContainerEvent(
ContainerEvent?
566 W hich of these methods w ill respond w hen you click any button of mouse? 2 N U 2 all of this
567 W hich package contains all classes & methods required for Event Handling in Java? 2 N U 2 java.aw t.event
568 W hich package should be added in the follow ing program to get the proper output: public class JCheckBoxDem2 N A 2 All of these
569 W hich program segment w ill generate the follow ing output. Figure:- 2 Y1 A 2 W hich program seg
javax.sw ing.*; imp
DemoFrame extend
Container c; public
570 W hich statement allow s the button named click to react to a mouse click? 2 N U 2 click.addActionListener(this)
571 W hich statement among the follow ing is not true releated to Event? 2 N U 2 A component may o
573 W hich statement is incorrect or missing in the follow ing code import java.aw t.*; import java.aw t.event*; 2 N A 2 Both A and B
import javax.sw ing.*; public class radio extends JApplet implements
_____________ { pulic void init() { c.setLayout(new Flow Layout()); JRadioButton b1=new
JRadioButton("Red"); b1.addActionListener(this); c.add(b1); JRadioButton b2=new JRadioButton("Green");
b2.addActionListener(this); c.add(b2); JRadioButton b3=new JRadioButton("Blue");
b3.addActionListener(this); c.add(b3); ButtonGroup bg=______________; bg.add(b1); bg.add(b2);
bg.add(b3); } public voidactionPerformed(ActionEvent e){ setBackground(e.getActionCommand()); } }
574 W hich statement is missing in follow ing code : import java.aw t.*; import javax.sw ing.*; import 2 N A 2 b1.addActionListene
java.applet.*; import java.aw t.event.*; /* <applet code="Square" w idth=300 height=300>
</applet> */ public class Square extends Applet implements ActionListener { Button b1; Label l1,l2;
TextField t1,t2; public void init() { l1=new Label("Enter the number"); l2=new Label("Square of number");
t1=new TextField(); t2=new TextField(); b1=new Button("Square"); setLayout(new GridLayout(3,2));
add(l1); add(t1); add(l2); add(t2); add(b1); } public void actionPerformed(ActionEvent ae) {
if(ae.getSource()==b1) { float a=Float.parseFloat(t1.getText()); float c=a*a; t2.setText(Float.toString(c)); }
}}
575 W hich statement is true about the code fragment listed below ? class MyListener extends MouseAdapter implem2 N A 2 The code compiles
mouse listener.
576 W hich Statement w ith respect to inner class is true A)It is a w ay of logically grouping classes that are only us 2 N U 2 All A , B C are True
577 W hich statements are missing in follow ing program /*<applet code=ScrollRGB w idth=300 height=300> </ap 2 N A 2 add(blue); red.addA
578 W hich statements should w e add inorder to follow ing code to handle events for MenuItems import java.aw 2 N A 2 ActionListener, add
t.*; import java.aw t.event.*; public class MenuDemo extends Frame implements
___________________ { Label l; MenuDemo() { MenuBar mbr = new MenuBar(); setMenuBar(mbr);
Menu filemenu = new Menu("File"); mbr.add(filemenu); MenuItem new 1 = new MenuItem("New ");
filemenu.add(new 1); new 1.__________________ l=new Label(); add(l); } public static void main(String
args[]) {MenuDemo m = new MenuDemo(); m.setSize(200,200); m.setLocation(10,10); m.setVisible(true); }
public void
______________________ { l.setText("New Clicked"); } }
579 2 Y1 U 2 JButton,JscrollPane
580 W hich type of the follow ing program : import java.aw t.event.ActionEvent; import java.aw t.event.ActionListen2 N U 2 Anonymous Inner c
581 W hich values are defined in InputEvent class to represent modifiers? 2 N U 2 All the above
582 W hich w ill be the correct code for the follow ing output 2 Y1 A 2 import java.aw t.*;
Figure:- class EventDemo ex
void init() { ad
mouseClicked(Mous
W rite the missing statement import java.applet.Applet; import java.aw t.Checkbox; import java.aw
t.Graphics; import java.aw t.event.ItemEvent; ------------------------------------------------------
/* <applet code="HandleCheckboxEvent" w idth=200 height=200> </applet> */ public class
HandleCheckboxEvent extends Applet implements ItemListener{ Checkbox java = null;
Checkbox vb = null; Checkbox c = null; public void init(){ java = new Checkbox("Java"); vb = new
585 Checkbox("Visual Basic"); c = new Checkbox("C"); add(java); add(vb); add(c); java.addItemListener(this); 2 Y1 A 2 import java.aw t.ev
vb.addItemListener(this); c.addItemListener(this); } public void paint(Graphics g){ g.draw String("Java: " +
java.getState(),10,80); g.draw String("VB: " + vb.getState(), 10, 100); g.draw String("C: " + c.getState(),
10, 120); } public void itemStateChanged(ItemEvent ie) { repaint(); } }
Figure:-
586 You have created a simple Frame and overridden the paint method as follow s public void paint(Graphics g) { g.2 N A 2 The low er part of t
the top hidden
587 ______________is used to obtained the object that generate W indow event 2 N A 2 getW indow ()
588 _______________ method can be used to know the degree of adjustment made by user w ith 2 N U 2 getValue()
ScrollBar?
590 ……………method can be used to obtain refrence to the container that generate ContainerEvent. 2 N A 2 getContainerEvent()
e-Exam Manage Questions for Advanced Java Programming (17625) for topic 3 Go Back to Subjects
1 Calling ServerSocket() constructor w ith port value 'zero' means_________________3 N U 1 use a port number that
2 TCP/IP reserves the ____________ ports for specific protocols 3 N R 1 low er 1024
3 W hich of these package contains classes and interfaces for netw orking? 3 N R 1 java.net
10 A_______ is responsible for determining w hether code executing in the Java runtime3 N R 1 policy object
11 byte[] getData() method of DatagramPacket class returns______________________3 N R 1 Byte array of data conta
17 In InetAddress class w hich method returns the host name of the IP Address? 3 N R 1 public String getHostNam
18 In the format for defining the URL w hat is the last part? 3 N R 1 File path
25 Name the class w hich is used to create a port w here the server w ill listen? 3 N R 1 ServerSocket
38 TCP/IP sockets are used to impelement __________ connections. 3 N R 1 All of the above
39 The class w hich encapsulates both the numerical IP address and the domain name fo3 N R 1 InetAddress
40 The constructor w hich is used in ServerSocket may be______________. 3 N R 1 ServerSocket (int port).
41 The constructor w hich is used to create client socket is ____________. 3 N R 1 Socket(InetAddress IPAddress, int port).
42 The factory method for retrieving objects of InetAddress is 3 N R 1 All of the mentioned
___________________.
43 The factory method w hich returns an array of InetAddresses that represent all of the3 N R 1 getAllByName( )
44 The java.net.InetAddress class provides methods to get the____________________ 3 N R 1 IP of any host name
45 The method int getPort( ) of Socket class returns____________ 3 N R 1 remote port to w hich this Socket object i
http://w w w .rediff.com:80/index.htm/
47 The openConnection() is the method of w hich Class? 3 N R 1 URLConnection
50 The server listens for a connection request from a client using the follow ing statemen3 N R 1 Socket s = ServerSocke
51 The valid sequence for URL format is ___________________ 3 N R 1 protocol, Hostname, portnumber, filepath
56 To return an instance of InetAddress class you have to use 3 N R 1 Factory Methods of InetAddress class
57 To return the currently intalled policy object______________method is used. 3 N R 1 public static Policy getPo
60 UDP Protocol uses follow ing classes for communication 3 N R 1 DatagramPacket and DatagramSocket
63 W hat does the openConnection() method of java.net.* return? 3 N R 1 Object of URLConnection class
70 W hat is the return type of the method getAllByName( ) of InetAddress class? 3 N R 1 InetAddress[ ]
71 W hat w ill be displayed in the output? import java.net.*; class myAddress { public st 3 N R 1 The internet address of
74 W hich class defines follow ing methods. 1. int getContent Length() 2. long getDate() 3 N R 1 URLConnection
77 W hich class is used to designed to be a "listener" w hich w aits for client to connect b3 N R 1 ServerSocket
79 W hich class of java.net package can be used to find the host name and IP address of3 N R 1 The InetAddress class
80 W hich classes are used for connection-oriented socket programming 3 N R 1 Both A and B
81 W hich constructor of DatagramSocket class is used to create a datagram socket and 3 N R 1 DatagramSocket(int por
82 W hich datagram method returns the byte array of data contained in the datagram? 3 N R 1 byte[] getData()
83 W hich exception indicate that the IP address of a host could not be determined 3 N R 1 Unknow nHostException
89 W hich method is used to know the full URL of an URL object? 3 N R 1 toExternalForm()
90 W hich method is used to retrieve the host name associated w ith URL 3 N R 1 getHost()
91 W hich method is used to return the IPAddress of local machine 3 N R 1 static InetAddress getLocalHost( )
92 W hich method of ServerSocket w ill w ait for a client to initiate communications and t3 N R 1 accept()
94 W hich of the follow ing are Factory Methods of InetAddress class 3 N R 1 All the Above
96 W hich of the follow ing constructor of InetAddress is generally used? 3 N R 1 InetAddress class does not contain any vi
100 W hich of the follow ing is not a Factory method of an InetAddress 3 N R 1 Sting getHostAddress()
Class?
101 W hich of the follow ing is not true about TCP Socket? 3 N R 1 Socket is not used to cre
102 W hich of the follow ing is true about UDP? 3 N R 1 No retransmission of lost packets.
103 W hich of the follow ing is true for TCP ? 3 N R 1 TCP is realiable and connection oriented
104 W hich of the follow ing is true for UDP ? 3 N R 1 UDP is unrealiable and connection less
105 W hich of the follow ing method is used to obtain remote port to w hich 3 N R 1 getPort()
Socket object is connected.
106 W hich of the follow ing methods of InetAddress class returs the IP Address? 3 N R 1 getHostAddress()
107 W hich of the ServerSocket method listen client request for connection? 3 N R 1 accept()
109 W hich of these class is used to create servers that listen for either local or remote cli 3 N R 1 ServerSockets
110 W hich of these class is used to encapsulate IP address and DNS? 3 N R 1 InetAddress
111 w hich of these class must be used to send a datagram packets over a connection? 3 N R 1 All of the mentioned
112 W hich of these is a bundle of information passed betw een machines? 3 N R 1 Datagram
114 W hich of these is a not a factory method of InetAddress class? 3 N R 1 static InetAddress getAllName(String host
115 W hich of these is a protocol for breaking and sending packets to an address across a 3 N R 1 TCP/IP
118 W hich of these method does not belongs to DatagramPacket class 3 N R 1 getAddress()
119 w hich of these method of DatagramPacket is used to find the length of byte Array 3 N R 1 getLength()
120 W hich of these method of DatagramPacket is used to find the port number? 3 N R 1 getPort()
121 W hich of these method of DatagramPacket is used to obtain the byte array of data co3 N R 1 getData()
122 W hich of these methods is used to know the full URL of an URL object? 3 N R 1 toExternalForm()
123 W hich of these methods is used to know the type of content used in the URL? 3 N R 1 getContentType()
124 W hich of these methods is used to know w hen w as the URL last modified? 3 N R 1 getLastModified()
125 W hich package is used for handling security related issue? 3 N R 1 java.security
127 W hich type of exception is throw by InetAddress class Factory methods? 3 N R 1 Unknow nHostException
128 You can invoke ______________ on a Socket object, say socket, to obtain an InetAd3 N R 1 socket.getInetAddress()
130 ______is netw orking protocol for hypermedia, collaborative & 3 N R 1 HTTP
distributed information system.
131 ________ is a low level routing protocol that breaks data into smaller packets. 3 N R 1 Internet protocol.
132 __________ class is used for accessing the attribute of a remote resource. 3 N R 1 URLConnection Class
134 __________ is used to implement reliable, bidirectional, persistent point to point stre3 N R 1 TCP/IP client and server
135 __________method is used to examine the address and port information by the sock3 N R 1 getInetAddress()
136 __________method of URL class is used to obtained file path from given URL. 3 N R 1 getFile()
137 ____________ acts as a mediator betw een a client program and an external servers3 N R 1 Proxy server
139 _____________ protocol supports fast point to point datagram oriented model. 3 N R 1 UDP
141 ________________ is abstract class for representing access to a system resource. 3 N R 1 Permission
144 Arrange the follow ing code segment in proper order that represent TCP server a) 3 N U 2 a,c,b
creating serverSocket object. server=new ServerSocket(4000, 2);
System.out.println("Socket open"); b) //receive inputs from client receive=new
DataInputStream(client.getInputStream()); String data=null; w hile(true) {
data=receive.readUTF(); System.out.println(data); } c)
//accept() method listens for a connection to be made to this socket and accepts it.
client=server.accept(); System.out.println("Client connected");
145 Choose the class name to be used instead of A_Class to get correct output. import ja 3 N A 2 InetAdress
146 Choose the correct output import java.net.*; class myURL2 { public static void main( 3 N A 2 a) Protocol=http Host Na
File Name=
147 Choose the correct output import java.net.*; class netw orking { public static void 3 N A 2 true
main(String args[])throw s Unknow nHostException { InetAddress obj1
=InetAddress.getByName("msbte.com");
InetAddress obj2 =InetAddress.getByName("msbte.com"); boolean x =
obj1.equals(obj2); System.out.print(x); } }
148 Consider the follow ing programe w hat w ill happen after execution. import java.net. 3 N A 2 84
149 Find Error in follow ing program. import java.aw t.*; class URLDemo { public static 3 N A 2 both a and b
void main(String args[]) throw s urlexception { URL hp = new URL("http://w w w
.Abc.com/dow nloads"); System.out.println("Protocol: " + hp.getProtocol());
System.out.println("Port: " + hp.getPort()); System.out.println("Host: "
+ hp.getHost()); } }
For the follow ing client side code of TCP implementation of sockets, w hat should be import java.io.IOExcepti
{ public static void main
150 java.net.*; public class Client { public static void main(String[] args) throw s Unknow3 N A 2 ServerSocket ss=new S
151 From given list w hich address is called as loopback address ? 3 N U 2 127.0.0.0
154 getPort() method of socket class return 3 N A 2 Returns the port number on w hich the so
155 Give line numbers containing errors in follow ing program: import java.Net.*; 3 N A 2 Line No.: 1,7,8,10,12,14
import java.io.*; import java.util.*; public class HeaderView er {public static void
main(String args[]) {try {URL u = new URL("http://w w w
.rediffmail.com/index.html"); URLconnection uc = u.openconnection( );
System.out.println("Content-type: "
+uc.getContentType( )); System.out.println("Content-encoding: "+
uC.getContentEncoding( )); System.out.println("Date: " + new Date(uc.getDate(
))); System.out.println("Last modified: "+ new Date(uC.getLastModified( )));
System.out.println("Expiration date: "+ new Date(uc.getExpiration( )));
System.out.println("Content-length: "
+uC.getContentLength( )); } catch (MalformedURLException ex)
{System.out.println("I can't understand this URL..."); } } }
156 Given Statement may throw s w hich exception? InetAddress address 3 N U 2 Unknow nHostException
=InetAddress.getByName("w w w .xyz.com");
157 Given the follow ing lines from a Java program segment: byte[] dataOut 3 N A 2 DatagramPacket packet
= new byte [512]; String userInput = "Java Programming"; dataOut = userInput.length, InetAd
userInput.getBytes(); W hich of the follow ing lines of code could be used to create
a new UDP datagram packet to send the data that w as provided by the user to a
host identified by the InetAddress object IPAddress?
159 Identify the valid method of URL class. 3 N U 2 All of the mentioned
161 If port number is not specified in the URL, getPort() method returns 3 N U 2 -1
_______
162 If w e create the datagram packet w it follow ing constructor: DatagramPacket(byte d3 N U 2 size of the packet
163 If you use either Telnet or FTP, w hich is the highest layer you are using to transmit d3 N U 2 Application
164 import java.net.*; public class URLDemo{ public static void main(String args[])throw 3 N U 2 Protocal:http Port:-1 Ho
w w .javajazzup.com
165 import java.io.*; import java.net.*; class exp7_1{ public static void main(String 3 N A 2 -1
args[]) throw s MalformedURLException{ URL a=new URL("http://w w w
.msbte.com:/index.html"); System.out.println("port
:"+a.getPort()); } }
166 import java.io.*; import java.net.*; class Pw dClient { public static void main(String a3 N U 2 client side
167 import java.net.*; class netw orking { public static void main(String[] args) throw s M3 N U 2 http://w w w .sanfoundr
168 import java.net.*; class netw orking { public static void main(String[] args) throw s E3 N U 2 text/html
169 import java.net.*; class netw orking1 { public static void main(String[] args) throw s 3 N A 2 true
170 import java.net.*; class myAddress { public static void main (String args[]) { try { In3 N U 2 The internet address of
171 In follow ing java program fill statement show ing *****. Select any one option 3 N A 2 getByName("w w
from given options. import java.net.*; public class InetDemo { public static void
main(String[] args) { try { InetAddress ip=InetAddress.****************
System.out.println("Host Name: "+ip.getHostName()); System.out.println("IP
Address: "+ip.getHostAddress()); } catch(Exception e) { System.out.println(e); }
}}
172 In how many w ays w e can create URL A)URL url = new URL("http://hostname:80/in3 N U 2 A & B both
173 In InetAddress class w hich method it returns the host name of the IP Address? 3 N U 2 public static InetAddress
174 In order to receive message from client w hich thing is missing in given server side pr3 N A 2 OutputStream class
175 In the follow ing code, w hat type of protocol is Socket object "skt" 3 N U 2 TCP
uses? import java.io.*; import java.net.*; public class NetClient { public static void
main(String args[]) throw s Exception { Socket skt = new Socket("host",88); } }
176 In the follow ing program choose the correct strings from given options to pass in 3 N A 2 All
URL constructor to get an output w ithout any exception. import java.net.*; class
URLDemo { public static void main(String args[]) throw s MalformedURLException {
URL hp = new URL("__________"); System.out.println("Protocol: " +
hp.getProtocol()); System.out.println("Port: " + hp.getPort());
System.out.println("Host: " + hp.getHost()); System.out.println("File: "
+ hp.getFile()); } } A. http://w w w .msbte.com/mainsite/index.php B. http://w w
w .msbte.com:80/mainsite/index.php C. w w w .msbte.com/ D. w w w
.msbte.com/mainsite/index.php
177 In this construtor ServerSocket(int port, int maxQueue) w hat is the default value for3 N U 2 50
179 InputStream class is used in TCP Client-server program to 3 N U 2 Send/receive message from client to serv
183 Name the components of the URL in order of their appearance 3 N U 2 Protocol,Hostname,Port Number, File Nam
187 returns the socket and establish a connection betw een server and client. 3 N U 2 public Socket accept()
190 Select pacakge used for handling security related issues in a program 3 N U 2 java.security
191 Select proper method used to create the instance InetAddress class. 3 N U 2 getLocalHost(),getByName(),getAllByNam
193 Select the appropriate method for retrieving address of remote machine 3 N U 2 public Address getRemo
195 Select the method of DatagramPacket used to find the port number 3 N U 2 getPort()
197 Select the method w hich throw s UnKnow nHostException 3 N U 2 All of the above
198 select the proper class for creating servers that listen for either local or remote client 3 N U 2 ServerSockets
199 Select the proper constructor of ServerSocket 3 N U 2 ServerSocket(int port, int maxQueue)
200 Select the proper constructor of the Socket class 3 N U 2 Socket(String hostName, int port)
202 Select the proper InetAddress factory method. 3 N U 2 static InetAddress getLocalHost()
203 Select the proper method of URL class to create the object of 3 N U 2 openConnection()
URLConnection.
204 Select the proper method to know the type of content used in the URL. 3 N U 2 getContentType()
205 Select the proper method to retrieve the host name & IP address of remote machine 3 N U 2 static InetAddress getBy
Unknow nHostException
206 Select the proper method to retrieve the host name and IP Address of local machine 3 N U 2 static InetAddress getLo
Unknow nHostException
207 Select the proper method to retrieve the host name of local machine 3 N U 2 static InetAddress.getLo
Unknow nHostException
208 select the proper method to retrive the data from DatagramPacket 3 N U 2 getData()
Select the proper output for follow ing code import java.net.*; class
209 DemoURL { public static void main(String args[])throw s MalformedURLException { U3 N A 2 Port: -1 File: /dow nload
210 ServerSocket has a method called __________, w hich is a blocking call that w ill w a3 N U 2 accept()
211 Socket connection = server.accept( ); In the above statement, server is an object 3 N U 2 ServerSocket, IOExcept
of ___________class and accept() method throw s
________exception.
213 TCP does not supports Multicasting and Broadcasting because: 3 N U 2 It is connection oriented protocol.
214 The URL connection classes are good enough for simple programs that w ant to conne3 N U 2 HTTP
215 The -------------- method in the InetAddress class returns the IP 3 N U 2 getHostAddress()
address.
216 The client request a connection to a server using the follow ing statement. 3 N A 2 Socket s=new Socket(S
219 The follow ing code can be used to produce a permisson to read the file named "abc "3 N U 2 perm=new java.io.FilePe
220 The follow ing program is w ritten for ____________________ import java.net.*; im 3 N A 2 TCPIP server
221 The follow ing program w ill display _____________________ import java.net.*; pub3 N A 2 All IP addresses of w w w
222 The follow ing Server program _____________________ import java.net.*; import j 3 N A 2 w aits for client request
message to all clients
223 The purpose of URL is 3 N U 2 a and b
224 The server listens for a connection request from a client using the follow ing statemen3 N U 2 Socket s = serverSocket
225 The Socket class has how many constructors that a client uses to connect to a server 3 N A 2 2
227 The ____________________models an IP address,w hich can be used to find the ho 3 N U 2 InetAddress class
228 The _____________________________ w hich contains a set of pre- w ritten netw o3 N U 2 java.net package
229 This program is w ritten for ___________ side import java.net.*; import java.io.*; pu3 N U 2 client
230 To Get All addresses by name of a URL - "w w w .google.com" follow ing command is 3 N U 2 InetAddress[] addresses
231 To access the URLConnection Class object w hich of the transfer protocol is used? 3 N U 2 http
232 To connect to a serevr running on the same machine w ith client, w hich of the follow 3 N U 2 All of the above
234 To create a server socket on the specified port w ith a maximum queue length of max3 N U 2 b and c
237 To return the currently installed policy object ____________ method is used. 3 N U 2 public static Policy getPo
238 URL Connection is class used for_____________________. 3 N U 2 Accessing the attributes of a remote resou
239 URL string encompasses four parts in sequence 3 N U 2 1. Netw ork Protocol 2.H
242 W hat correction should be done in the program to get correct output? import 3 N A 2 Use of created object no
java.net.*; import java.io.*; public class URLTest { public static void main(String
args[]) throw s MalformedURLException { URL url = new URL("http://w w w
.msbte.com/dow nload"); System.out.println("Protocol:"+ url1.getProtocol());
System.out.println("Port:"+ url1.getPort()); System.out.println("Host:"+
url1.getHost()); System.out.println("File:"+ url1.getFile()); } }
243 W hat correction should be done in the program to get corrected output import 3 N A 2 Missing package stateme
java.net.*; import java.io.*; class UrlDemo1 { public static void main(String a[])
throw s Exception { URL ur= new URL("http://w w w .msbte.com/mainsite/");
URLConnection con=ur.openConnection(); System.out.println("Date : "+new
Date(con.getDate())); System.out.println("Content type :
"+con.getContentType()); System.out.println("Expires : "
+con.getExpiration()); System.out.println("Last Modified : "+new
Date(con.getLastModified())); int len=con.getContentLength();
System.out.println("content length : "+len); } }
244 W hat correction should be done in the program to get the correct output import java3 N A 2 }
247 W hat is 1432 in follow ing program. import java.net.*; import java.io.*; public class 3 N A 2 port number
248 W hat is correct code for the given problem statement: Develop a program to send a 3 N A 2 both a& b
249 W hat is correct code to get ip address of host machine ? 3 N A 2 import java.net.*; class
250 W hat is missing in the follow ing program code? import java.io.*; class Sender { pub3 N U 2 All of the mentioned
251 W hat is out put of follow ing Program import java.net.*; class netw orking { public st3 N U 2 text/html
252 W hat is output of follow ing program import java.net.*; public class InetAddressExam3 N A 2 Gives default IP address
253 What is proper method to retrieve the host name of local machine 3 N U 2 static InetAddressgetLocalHost( )throw s
254 W hat is the default length of the queue in follow ing constructor of 3 N U 2 50
Serversocket? ServerSocket(int portno)
255 W hat is the error in given code? import java.net.*; public class Hostname{ public 3 N A 2 System.out.println (&qu
static void main(String args[]){ try{ InetAddress local= local.getLocalHostName(
InetAddress.getLocalHost(); System.out.println ("Local hostname is: " +
local.getLocalHostName()); } catch
(Unknow nHostException e){ System.err.println ("Can't detect localhost
: " + e); } } }
258 W hat is the missing statement in the output of the follow ing code: 3 N A 2 Content-Type: text/htm
import java.net.*; import java.io.*; import java.util.Date; class UCDemo
{ public static void main(String args[]) throw s Exception { int c; URL hp
= new URL("http://w w w .internic.net"); URLConnection hpCon =
hp.openConnection(); long d = hpCon.getDate(); if(d==0) System.out.println("No
date information."); else System.out.println("Date: " + new Date(d));
System.out.println("Content-Type: " + hpCon.getContentType()); d =
hpCon.getExpiration(); if(d==0) System.out.println("No expiration information.");
else System.out.println("Expires: " + new Date(d)); d = hpCon.getLastModified();
if(d==0) System.out.println("No last-modified information."); else
System.out.println("Last-Modified: " + new Date(d)); int len =
hpCon.getContentLength(); if(len == -1) System.out.println("Content length
unavailable."); else
System.out.println("Content-Length: " + len); }} Output: Date: Sat Apr
27 12:17:32 CDT 2002 No expiration information. Last-Modified: Tue
Mar 19 17:52:42 CST 2002 Content-Length: 5299
259 W hat is the ouput of follow ing code? import java.net.InetAddress; import java.net.U3 N A 2 local m/c Address
260 w hat is the out of follow ing code if Host URL w as last modified on july 3 N A 2 Tue Jun 18 2013
18 tuesday 2013 . mport java.net.*; class netw orking { public static void
main(String[] args) throw s Exception { URL obj = new URL("http://w w w
.sanfoundry.com/javamcq"); URLConnection obj1 = obj.openConnection();
System.out.print(obj1.getLastModified); } }
261 W hat is the output of this program? Figure:- 3 Y1 A 2 cisco.com
262 W hat is the output of this program? import java.net.*; class netw orking { public sta3 N A 2 msbte.com
InetAddress.getByName("msbte.com"); System.out.print(obj1.getHostName()); } }
263 W hat is the output of this program? import java. Net.*; class netw orking { public st 3 N A 2 http
264 W hat is the purpose of InetAddress class? 3 N U 2 To retrieve IP address of the specified hos
265 W hat is the return type of getAddress() method of DatagramPacket class? 3 N U 2 InetAddress
266 W hat is the use of bind() method 3 N U 2 bind a socket to a local IP address and po
267 W hat is the use of w riteUTF( ) method? 3 N U 2 This method w rites a string into underlyin
268 W hat method is used to establish a port w here a server w aits for requests? 3 N U 2 ServerSocket()
269 W hat statement is needed to get the output as show n in fig. in bellow program 3 Y1 A 2 c=new urlconn(); in mai
import java.net.*; import java.io.*; import java.aw t.event.*; import javax.sw
ing.*; import java.aw t.*; class urlconn extends JFrame implements ActionListener
{JTextField f=new JTextField(); JTextArea a=new JTextArea(); String s=""; public
urlconn() { getContentPane().add(f,BorderLayout.NORTH);
getContentPane().add(a,BorderLayout.CENTER); f.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400,400);
} public void actionPerformed(ActionEvent e) { if(e.getSource()==f) { try { URL
u=new URL(f.getText()); URLConnection con=u.openConnection(); BufferedReader
br=new BufferedReader(new InputStreamReader(con.getInputStream())); int
len=con.getContentLength(); if(len!=0) { w hile((s=br.readLine())!=null)
a.append("\n"+s); br.close(); } else a.append("\n"+"content unavailable");
}catch(Exception ae){} } } public static void main(String ar[])throw s Exception {
urlconn c; c.setVisible(true); } }
Figure:-
270 W hat the method getDate() of URLConnection class returns? 3 N U 2 returns time and date of response in term
272 W hat type of exception might be throw n by Socket class. 3 N U 2 Unknow nHostException
273 W hat w ill be displayed in the output import java.net.*; class InetAddressTest { publ3 N U 2 The array of internet ad
274 W hat w ill be displayed in the output? import java.net.*; classmyAddress { public sta3 N U 2 The internet address of
275 W hen client and server is communicating using TCP protocol then communication is _3 N U 2 connection-oriented, con
276 w hen creating a client on a server port that is alerady in use 3 N U 2 client can connect to the
________________
277 W hen Unknow nHostException is throw n, that indicates 3 N U 2 The IP address of a host could not be dete
278 W hich datagram method returns the byte array of data contained in the datagram? 3 N U 2 byte[] getData ()
279 W hich is correct client code for follow ing server code? import java.net.*; import java3 N A 2 import java.net.*; impo
void main(String args[])
BufferedReader b=null;
Socket(InetAddress.getL
BufferedReader(new Inp
catch(Unknow nHostExc
know host"); Syst
hile((inp=b.readLine())!
b.close(); s.close(); } }
280 W hich Statement is missing in follow ing code import java.net.*; public class InetAdd3 N A 2 InetAddress ad=InetAdd
281 W hich class can be used to create a server socket. This object is used to establish co3 N U 2 Both A & B
282 W hich code segment listens for a socket connection? 3 N U 2 Socket socket = HttpURLConnection.open
286 W hich five parameters uniquely identify a Connection ? 3 N U 2 Local IP, Remote IP, Loc
288 W hich is correct sequence of steps for establishing TCP Connection betw een client a 3 N U 2 a,c,b,d
293 W hich is responsible for determining w hether code executing in Java runtime enviro 3 N U 2 security class
294 W hich is the class present in java.net package used to create packet from byte array3 N U 2 DatagramPacket
295 W hich method is used to obtain the Portno of client in Client Program 3 N U 2 getLocalPort()
296 W hich method Returns the output stream of the URL connection ? 3 N U 2 getOutputStream()
297 W hich methods are commonly used in ServerScocket class ? 3 N U 2 public Socket accept()
298 W hich minimum package statements are missing? class InetDemo { public static 3 N U 2 import java.net.*; impo
void main(String args[]) { try { Socket s=new Socket("127.0.0.1",1234);
InputStream ip=s.getInputStream(); OutputStream op=s.getOutputStream();
Date d=new Date(); String datemsg=String.valueOf(d); op.w
rite(datemsg.getBytes()); op.close();
} catch(Exception e) { System.out.println(e); } } }
299 W hich of the follow ing is not a factory method of InetAddress class 3 N U 2 static InetAddress getAl
Unknow nHostException
W hich of the follow ing statement is missing in follow ing code: import java.io.*; imp
301 W hich of these are correct constructor/s of URL class? 3 N U 2 All of above
302 W hich of these class is used to encapsulate IP address and DNS? 3 N U 2 InetAddress
304 w hich of this class is not related to input and output stream in terms of functioning? 3 N A 2 Reader
305 W hich protocol w ill be used/printed in the follow ing example import java.net.*; 3 N A 2 HTTP
public class URLDemo { public static void main(String args[]) throw s
MalformedURLException { URL hp = new URL("http://w w w .msbte.com/dow
nloads"); System.out.println("Protocol: " + hp.getProtocol());
System.out.println("Port: " + hp.getPort()); System.out.println("Host: "
+ hp.getHost()); System.out.println("File: " + hp.getFile());
System.out.println("Ext:" + hp.toExternalForm()); } }
306 W hich Statement gives an error import java.net.*; import java.io.*; public class URL3 N A 2 C.Both A and B
307 W hich statement is missing from the code import java.net.*; import java. io.*; class 3 N A 2 getProtocol()
308 W rite a syntax to prepare DatagramPacket Object as sendPacket by using other para3 N A 2 DatagramPacket sendPa
sendData.length, IPAddr
309 You can invoke ______________ on a Socket object, say socket, to obtain an InetAd3 N A 2 socket.getInetAddress()
310 You can obtain the server's hostname by invoking _________ on an applet. 3 N U 2 getCodeBase().getHost(
311 _______ method is used to examine the address and port information by the socket. 3 N U 2 getInetAddress().
312 _________ is a protocol for breaking and sending packets to an address across a net 3 N U 2 TCP/IP
313 __________are used to implement reliable, bidirectional, persistent point to point str 3 N U 2 TCP/IP
315 ___________ is a general-purpose class for accessing the attributes of a remote 3 N U 2 URLConnection
317 ___________is a factory method of InetAddress class w hich returns an array of Inet3 N U 2 getAllByName()
321 …………….. method is used for testing w hether the specified element is a file or not. 3 N A 2 isFile()
323 …………………throw n to indiacate that IP address of Host could not be 3 N U 2 UNknw onHostExecption
Determined
324 ……………………….method of datagram packet is used to find the port number. 3 N U 2 getPort()
325 A technique that creates a subletting effect; one server answ ers ARP 3 N U 2 Proxy Server
requests for multiple hosts?
326 W hich client accesses the W eb server by using a GET MESSAGE? 3 N U 2 HTTP
327 W hich of these is a protocol for breaking and sending packets to an address across a 3 N U 2 TCIP/IP
e-Exam Manage Questions for Advanced Java Programming (17625) for topic 4 Go Back to Subjects
1 A Java program cannot directly communicate w ith an ODBC driver because 4 N R 1 ODBC w ritten in C language
2 A JDBC technology -based driver ("JDBC driver") makes it possible to do ? 4 N R 1 All mentioned above
6 API w hich controls access to the row result of a given Statement and holds data retrieved from a database af4 N R 1 java.sql.ResultSet
13 Choose the correct syntax for getConnection() method 4 N R 1 public static Connecti
SQLException
14 Class.forName("_________________________") 4 N R 1 sun.jdbc.odbc.JdbcOdbcDriver
16 Connection object can be initialized using the _______ method of the DriverManager Class. 4 N R 1 getConnection()
17 createStatement() method w ithout any parameter is used to create a statement w ith 4 N R 1 a forw ard only and re
__________
20 DriverManager.getConnection(_______ , ______ , ______) W hat are the tw o parameters that are included ?4 N R 1 URL or machine name
22 Every driver must provide a class that should implement the __________________ 4 N R 1 Driver interface
23 execution of delete SQL query in JDBC, ............. method must be used. 4 N R 1 executeUpdate()
25 For execution of INSERT SQL query in JDBC, ............. method must be used. 4 N R 1 executeUpdate()
26 For execution of SELECT SQL query in JDBC, ___________________ method must be used. 4 N R 1 executeQuery()
30 How can you execute DML statements (i.e. insert, delete, update) in the database? 4 N R 1 By invoking the executeUpdate(...) m
31 How can you retrieve information from a ResultSet? 4 N R 1 By invoking the speci
32 How many JDBC driver types are available by sun Microsystem? 4 N R 1 Four
33 How many steps are used to connect any java application w ith the database using JDBC? 4 N R 1 5
35 If a PreparedStatement is a SQL SELECT statement, you execute the statement using 4 N R 1 PreparedStatement.ex
________.
36 If you need to use a stored procedure w ith output parameters, w hich of the follow ing statement type should4 N R 1 CallableStatement
38 In JDBC _________imports all java classes concerned w ith database connectivity. 4 N R 1 java.sql.*
39 In the follow ing JDBC drivers w hich is know n as partly java driver? 4 N R 1 Native-API driver
40 In the three tier model the middle tier of the services acts as a mediator betw een 4 N R 1 Java application and d
________________________ and _________________.
41 In w hich model java application or applet supports for database access? 4 N R 1 both a and b
42 In w hich type of driver must Odbc drivers be loaded on client machine? 4 N R 1 Type 1
44 JDBC is a --------------------- interface, w hich means that it is used to invoke SQL commands directly. 4 N R 1 low level
47 JDBC-ODBC bridge product provide _________ access via ____________. 4 N R 1 JDBC driver, ODBC drivers
50 Name the type number belongs to JDBC ODBC Bridge driver? 4 N R 1 Type 1
51 Native API converts __________________into the _______________________ used by 4 N R 1 JDBC API, Native API
DBMS.
52 Native – protocol pure Java converts ……….. in to the ………… used by DBMSs directly. 4 N R 1 JDBC calls, netw ork protocol
54 ODBC is not appropriate for direct use from java because it uses a .............. 4 N R 1 C interface
56 ODBC requires configuring _______ w hich represents the target database. 4 N R 1 Data Source Name
65 The -----------------method executes a simple query and returns a single Result Set object 4 N R 1 executeQuery()
66 The .................. object provides you w ith methods to access data from the table. 4 N R 1 ResultSet
67 The ...................... method sets the query parameters of the PreparedStatement Object. 4 N R 1 setString()
69 The ......................... method executes an SQL statement that may return multiple results. 4 N R 1 execute()
70 The ............................. package contains classes that help in connecting to a database, sending SQL statem4 N R 1 java.sql
71 The command to remove all the row s from a table 'CUSTOMER' is: 4 N R 1 DELETE FROM CUSTOMER
72 The correct string for loading Jdbc-Odbc bridge driver using Class.forName() method is: 4 N R 1 sun.jdbc.odbc.JdbcOdbcDriver
75 The JDBC API is an application interface of java for connection java as 4 N R 1 Middle
76 The JDBC API is application interface connecting java as ____ 4 N R 1 Front End
77 The parameters of the PreparedStatement object are ...................... w hen the user clicks on the Query butto4 N R 1 initialized
78 The PreparedStatement__________symbol is placeholder that is replaced by the input parameter at seen tim4 N R 1 ?
79 The ResultSet __________________provides methods for retrieving and manipulating the results of executed4 N R 1 interface
81 The valid constant to represent ResultSet type is ___________________ 4 N R 1 All of the mentioned
82 The _____ object provides you w ith methods to access data from the table. 4 N R 1 ResultSet
83 The _____ package contains classes that help in connecting to a database, sending SQL 4 N R 1 java.sql.*
statements to the database and processing the query results.
84 The ___________ interface Provides various methods for getting information about Database. 4 N R 1 DatabaseMetaData
85 The ______________driver resolves JDBC call and makes equivalent ODBC Call 4 N R 1 JDBC-ODBC bridge
86 The_____________________ is the language for interacting w ith Database. 4 N R 1 Structured Query Language(SQL)
91 Type II JDBC driver is also know n as __________________ 4 N R 1 Native API partly Java driver
92 Type IV JDBC driver is also know n as __________________ 4 N R 1 Native Protocol Pure-Java Driver
93 Type4 driver is also know n as: 4 N R 1 100% Pure Java
95 W hat maintains a cursor pointing to a particular row of data initially, cursor points to before the first row ? 4 N R 1 ResultSet interface
100 W hich class/ interface is used for an SQL statement that is executed frequently? 4 N R 1 PreparedStatement
101 W hich driver provides JDBC API access via one or more ODBC drivers 4 N R 1 JDBC-ODBC bridge driver
103 W hich driver is efficient and alw ays preferable for using JDBC applications? 4 N R 1 Type-4
104 W hich driver is needed to connect to Microsoft database? 4 N R 1 JDBC-ODBC Bridge Driver
105 W hich driver type use middlew are server(Application Server)? 4 N R 1 Type 3
109 W hich interface provides methods to execute queries w ith the database? 4 N R 1 Statement interface
112 W hich is the correct syntax of next( ) method of ResultSet? 4 N R 1 boolean next( )
113 W hich JDBC driver Type (s) can be used in either applet or servelt code? 4 N R 1 Both Type 3 and Type 4
114 W hich JDBC driver Type(s) can you use in a three-tier architecture and if the W eb server and the DBMS are 4 N R 1 Both Type 3 and 4
115 W hich JDBC driver Types are used for over communications netw orks? 4 N R 1 Both Type 3 and Type 4
116 W hich kind of driver convert JDBC calls into calls on the client API for Oracle, Sybase, Informix, IBM DB@ , o4 N R 1 Native-API partly-Java
117 W hich method is used to obtain count of total row s of ResultSet 4 N R 1 getRow
119 W hich method is used to send CREATE TABLE queries to database using JDBC? 4 N R 1 executeUpdate()
120 W hich method must be used to execute INSERT, UPDATE, or DELETE statement . 4 N R 1 executeUpdate()
121 W hich method of class is used to register & dynamically load the driver class? 4 N R 1 forName()
122 W hich of the follow ing describes the correct sequence of the steps involved in making a connection w ith a d4 N R 1 1,3,4,2
123 w hich of the follow ing function is used to find the column count of the particular ResultSet ? 4 N R 1 getColumnCount()
124 W hich of the follow ing invokes functions in sql ? 4 N R 1 Callable statements
127 W hich of the follow ing is the correct order of keyw ords for SQL SELECT statements? 4 N R 1 SELECT, FROM, W HERE
128 W hich of the follow ing is used for sending SQL statements? 4 N R 1 Statement
129 W hich of the follow ing method is method is used to load and register driver ? 4 N R 1 Class.forName("sun.jdbc.odbc.
130 W hich of the follow ing methods are needed for loading a database driver in JDBC? 4 N R 1 Both A and B
131 W hich of the follow ing model is java applet or application directly communicates w ith data source? 4 N R 1 Tw o tier
132 W hich of the follow ing model is know n as client/server configuration. 4 N R 1 Tw o-tier
133 W hich of the follow ing package contains all JDBC API’s those are required to make connection w ith databas 4 N R 1 java.sql.*
134 W hich of the follow ing statement is a prepared statements ? 4 N R 1 Insert into department values(?,?,?)
135 W hich of the follow ing statements loads the JDBC-ODBC driver? 4 N R 1 Class.forName("sun.jdbc.odbc.
136 W hich of the follow ing translates the socket information in call format required by the DBMS. 4 N R 1 Middlew are Application Server
137 W hich of the follw ing statement is false as far as different type of statements is concern in 4 N R 1 Interim statement
JDBC?
138 W hich of these API represents that softw are programs can follow to communicate w ith each other? 4 N R 1 Both A & B
139 W hich one of the follow ing w ill not get the data from the first column of ResultSet rs, returned from executi4 N R 1 rs.getString(0)
140 W hich package is necessary to import all java classes concerned w ith database connectivity? 4 N R 1 java.sql.*
141 W hich package need to be imported for establishing connection w ith database 4 N R 1 java.sql
143 W hich statements about JDBC are true? 4 N R 1 Both II and III
144 W hich type of driver provides JDBC access one or more ODBC drivers? 4 N R 1 Type 1 driver
145 W hich type of driver converts JDBC calls into the netw ork protocol used by the database management syste 4 N R 1 Type 4 Driver
147 W hich w as first most w idely used programming interface for accessing relational databases on almost all pl 4 N R 1 ODBC API
149 You can add a row using SQL in a database w ith w hich of the follow ing? 4 N R 1 INSERT
150 _______ calls get converted into native C or C++ API calls. 4 N R 1 JDBC Native API
151 ________ is an interface by w hich application programs can access and process SQL 4 N R 1 ODBC
databases in a DBMS-independent manner.
153 __________ interface is used to know the capabilities or information about a database 4 N R 1 Database Metadata
Management system DBMS w ith JDBC Driver.
155 __________ method of DriverManager class is used to create connection w ith database. 4 N R 1 getConnection()
158 ___________________ interface represents the comprehensive information about the database package. 4 N R 1 DatabaseMetaData
159 W hat is data in follow ing program: import java.sql.*; public class Selectdbase { public static void main(Strin4 N A 2 data source name
161 .Find out error from follow ing code. import java.sql.*; public class Updatedbase { public static void 4 N A 2 ; missing
main(String args[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:data2"); Statement st=con.createStatement(); resultSet
rs=st.executeQuery("select * from college"); w hile(rs.next()) { System.out.println("id:"+rs.getInt("id"))
System.out.println("name1:"+rs.getString("name1"));
} con.close(); } catch(SQLException e) {} catch(Exception e) { } }}
162 1. Choose the correct option to establish a connection to database named student and display its contents. 4 N A 2 import java.sql.*; cla
try{ Class.forName(&
con=DriverManager.g
"jdbc:oracle:thi
Statement stmt=con.
from student");
"+rs.getString(2
System.out.println(e)
163 A benefit of the three-tier architecture is w hich of the follow ing? 4 N U 2 New modules can be built to support
164 afterLast() method returns……………………. 4 N U 2 Moves cursor to the end of resultset
165 All raw data types including binary documents or images should be read and uploaded to the database as an a4 N U 2 byte
166 Analyse the follow ing code and fill the appropriate statement in the blanks import java.sql.*; class DB { publ4 N A 2 executeQuery()
167 Analyse the follow ing code and find errors. import java.sql.*; class DisplayRecord { public static void main(S4 N A 2 Error is in query exec
168 Analyse the follow ing code and find out errors import java.sql.*; class Record { public static void main(String4 N A 2 Error is in statement
169 Analyse the follow ing code and find out missing statement. import java.sql.*; class Record { public static voi4 N A 2 Missing driver registra
170 Analyze the follow ing code: ResultSet resultSet = statement.executeQuery ("select firstName, mi, lastName 4 N U 2 The program w ill hav
171 Analyze the follow ing code: ResultSet resultSet = statement.executeQuery ("select firstName, mi, lastName 4 N A 2 II, III
172 API is w hich of the follow ing 4 N U 2 Middlew are that provide access to d
175 By using w hich interface one can store images in the database in java ? 4 N U 2 PreparedStatement interface
176 Choose missing statements in follow ing code from given options. import java.sql.*; class DBTest { public sta4 N A 2 } missing
177 Choose missing statements in follow ing code from given options. Import java.sql.*; Class conn 4 N A 2 Class.forName(“sun.jd
{ Public static void main(String args[]) { try { System.out.println(“Drivers are properly loaded”); String
url=”jdbc:odbc:abc”; Connection con=DriveManager.getConnection(url); System.out.println(“Connection
Established”); con.close(); } catch(SQLExcption e) { System.out.println(“SQL Error has occurred ”);
catch(Exception e) { System.out.println(“Error! Connection not established”); } } }
178 Choose missing statements in follow ing code from given options. import java.sql.*; class DemoFetch { public4 N A 2 stmt.executeQuery(qr
179 Choose missing statements in follow ing code from given options. import java.sql.*; class DemoFetch1 { 4 N A 2 pstmt.executeQuery(q
public static void main(String args[]) { Connection con; PreparedStatement pstmt; ResultSet rs; String
qry,url; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); url="Jdbc:Odbc:studdsn";
con=DriverManager.getConnection(url,"",""); qry="select * from stud"; pstmt=con.prepareStatement(qry);
rs=___________________; System.out.println("Roll No\tName\tPercentage"); w hile(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)
{System.out.println(e.toString());} } }
180 Choose missing statements in follow ing code from given options. import java.sql.*; import java.io.*; class D 4 N A 2 "insert into stud
}catch(Exception e){} } }
181 Choose the correct alternative to update employee table 4 N A 2 PreparedStatement ps
W HERE id = ? "
… } finally { pstmt. C
182 Choose the correct output for the given code: import java.sql.*; class Mydatabase1 { public static void main( 4 Y2 A 2 S1Q54O1
183 Choose the correct syntax of creating query to read records w ith salary > 10000 4 N A 2 select * from employee w here salary
184 class Ddemo1 { public static void main(String args[]) throw s Exception { 4 N A 2 Missing package state
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," "); Statement s=c.createStatement(); ResultSet
rs=s.executeQuery("select *from StudTable"); System .out.println("Name" + " \t " + "Roll_No" + " \t " +
"Avg"); w hile(rs.next()) 26 { System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t
\t"+rs.getDouble(3)); } s.close(); c.close(); } class Ddemo1 { public static void main(String args[]) throw
s Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," "); Statement s=c.createStatement(); ResultSet
rs=s.executeQuery("select *from StudTable"); System
.out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg"); w hile(rs.next()) {
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3)); } s.close(); c.close(); }
185 Connection con = DriverManager.getConnection ("jdbc:odbc:w ombat", "login", "passw ord"); Statement stmt4 N A 2 Retrieval of the fields
186 Connection con=DriverManager.getConnection(url); this command w ill create the follow ing 4 N A 2 new con object of connection class in
187 Connection object can be initialized using the ............................ method of the Driver Manager class. 4 N R 2 getConnection()
188 Consider follow ing code and state missing code ? import java.sql.*; class exp2 { public static void main(Strin4 N A 2 sun.jdbc.odbc.JdbcOd
189 Consider follow ing code and state w hich statement is missing in follow ing code ? import java.sql.*; class 4 N A 2 Statement s=c.create
JDBCDEMO { { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," "); ResultSet rs=s.executeQuery("select *from
StudTable"); System .out.println("Name" + " \t " + "Roll_No"
+ " \t " + "Avg"); w hile(rs.next()) { System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t
\t"+rs.getDouble(3)); } s.close(); c.close(); } }
190 Consider Follow ing Code. Select the statement that should be added to the program to get correct output. im4 N A 2 Connection conn=Driv
192 Consider follow ing program w hat should be the correction done in the program to get correct output? Class d4 N A 2 Both B and C option
193 Consider follow ing program.W hat should be the output. import java.sql.*; public class Select_Demo { public4 N A 2 Output display numbe
194 Consider given database and Select correct output for follow ing code: import java.sql.*; class StudentData 4 Y1 U 2 Students having mark
{ public static void main(String args[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con
=DriverManager.getConnection("jdbc:odbc:stud"); PreparedStatement ps
=con.prepareStatement("select * from Student w here Marks > ?"); ps.setInt(1,70); //set question marks
place holder ResultSet rs = ps.executeQuery(); //execute System.out.println("Students having marks > 70
are:"); w hile(rs.next()) System.out.println(rs.getString(2)); con.close(); }catch(Exception e){ } } }
Figure:-
195 Consider the follow ing code. Fill the proper method in the blank space . import java.sql.*; import java.io.*; p4 N A 2 executeUpdate()
198 Consider the follow ing code. PreparedStatement stmt=con.prepareStatement("select * from emp"); 4 N A 2 retrieve the record
ResultSet rs=stmt.executeQuery(); w hile(rs.next()){ System.out.println(rs.getInt(1)+" "+rs.getString(2));
} This is an example of prepared statement interface that w ill
_______________?
199 Consider the follow ing code.find error statement to execute the code import java.sql.*; public class 4 N A 2 Both option i and ii
JDBCExample { static final String JDBC_DRIVER = "com.mysql.jdbc.Driver" static final String DB_URL =
"jdbc:mysql://localhost/STUDENTS"; static final String USER = "username"; static final String PASS =
"passw ord"; public static void main(String[] args) { Connection conn
= null; try{ Class.forName("com.mysql.jdbc.Driver"); System.out.println("Connecting to a selected
database..."); conn = DriverManager.getConnection(DB_URL, USER, PASS); System.out.println("Connected
database successfully..."); }catch(SQLException se) { se.printStackTrace(); } catch(Exception e) {
e.printStackTrace(); } finally{ try{ if(conn!=null) conn.close(); }catch(SQLException se){
se.printStackTrace(); } } System.out.println("Goodbye!"); }
200 Consider the follow ing code.find missing statement in code so that get desired output import java.sql.*; 4 N A 2 String s= ("jdbc
public class mytabledelete { public static void main(String[] args) throw s Exception
{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection(s);
System.out.println("Connection Established"); PreparedStatement studste = con.prepareStatement("delete
from student w here rno=3"); studste.executeUpdate(); Statement s1 = con.createStatement(); String
studqry = "select * from student"; ResultSet Rset = s1.executeQuery(studqry); w hile (Rset.next()) { int
studid = Rset.getInt("rno"); String studname = Rset.getString("name"); System.out.println(studid + " "
+ studname); } } }
201 Consider the follow ing code.W hat should be the correction done in the code to get correct output? import jav4 N A 2 Both option i and ii
202 Consider the follow ing code.W hat w ill be student table data after executing this code as table w as 4 N A 2 only one record in tab
empty. import java.sql.*; public class mytableins { public static void main(String[] args) throw s Exception
{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String s = ("jdbc:odbc:mystudtable"); Connection
con=DriverManager.getConnection(s); System.out.println("Connection Established"); PreparedStatement
studste = con.prepareStatement("insert into student values(2,'Rani')"); studste .executeUpdate();
Statement s1 = con.createStatement(); ResultSet Rset = s1.executeQuery( "select * from student");
System.out.println("Roll No ....Name"); w hile (Rset.next()) { int studid = Rset.getInt("rno"); String
studname = Rset.getString("name"); System.out.println(studid + " "
+studname); } } }
Consider the follow ing code.W hich statement need to update student table data by this code?
203 import java.sql.*; public class mytableupdate { public static void main(String[] args) throw s Exception { Cla 4 N A 2 studste.executeUpdat
204 Consider the follow ing database: ID name Salary 1 ramesh 1200 2 ganesh 1111 6 sanjay 4 N A 2 Driver Loaded Connec
9500 W hat w ill be the correct output for follow ing code: import java.sql.*; class SelectDemo { public name : ganesh Salary
static void main(String a[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded"); String url="jdbc:odbc:mydsn"; Connection
con=DriverManager.getConnection(url); System.out.println(" Connection to DataBase created"); Statement
stmt=con.createStatement(); String query="select * from emp"; ResultSet rs=stmt.executeQuery(query);
w hile(rs.next()) { System.out.println(" ID : "+ rs.getInt(1)); System.out.println(" name : "+
rs.getString(2)); System.out.println(" Salary : "+ rs.getInt(3)); System.out.println(); } }
catch(ClassNotFoundException e) { e.printStackTrace();
} catch(SQLException e) { e.printStackTrace(); } } }
205 Consider the follow ing program Select the statement that should be added to the program to get correct 4 N A 2 st.executeQuery()
output. import java.sql.*; public class JdbcOdbc { public static void main(String args[]) { try { Connection
con; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con =
DriverManager.getConnection("jdbc:odbc:datastud"); try { System.out.println("Getting All
Row s from a table!"); Statement st = con.createStatement(); ResultSet res =----------------------
-----("SELECT * FROM college"); System.out.println("student_code: " + "\t" + "student_name: "); w hile
(res.next()) { int i = res.getInt("stud_code"); String s = res.getString("stud_name"); System.out.println(i
+ "\t\t" + s); } con.close(); } catch (SQLException s) { System.out.println("SQL code does not execute.");
} } catch (Exception e) { System.out.println("Error:connection not created"); } } }
206 Consider the follow ing program Select the statement that should be added to the program to get correct 4 N A 2 Use satement Class.fo
output. import java.sql.*; public class db15 { public static void main(String args[])throw s Exception {
Connection c
=DriverManager.getConnection("jdbc:odbc:MyDSN","",""); PreparedStatement s=c.prepareStatement(
"update db3 set Name=? w here Roll_no=?"); Statement s=c.createStatement( ); s.setString(1,args[0]);
s.setString(2,args[1]); s.setString(3,args[2]); s.executeUpdate(); ResultSet rs=s.executeQuery("select*
from db3"); System.out.println("Name"+"\t"+"Roll no"+"\t"+"Avg"); w hile(rs.next()) {
System.out.println(rs.getString(1)+"\t"+rs.getInt(2)+"\t"+rs.getDouble(3)); } s.close(); c.close(); } }
207 Consider the follow ing program Select the statement that should be added to the program to get correct outp4 N A 2 ps1.executeUpdate();
208 Consider the follow ing program Select the statement that should be added to the program to get correct outp4 N A 2 PreparedStatement st
");
Consider the follow ing program W hat correction should be done in the program to get correct output? import
210 Consider the follow ing program W hat w ill be displayed in the output? import java.sql.*; class ConnectionTe 4 N A 2 Driver loaded Connec
211 Consider the follow ing program W hat w ill be the output of follow ing Code? import java.sql.*; public class 4 N A 2 Empty Table
db15 { public static void main(String args[])throw s Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c
=DriverManager.getConnection("jdbc:odbc:DSN2","",""); Statement s=c.createStatement( ); int
n=s.executeUpdtae("delete from db3"); ResultSet rs=s.executeQuery("select* from db3");
System.out.println("Name"+"\t"+"Roll no"+"\t"+"Avg"); w hile(rs.next()) {
System.out.println(rs.getString(1)+"\t"+rs.getInt(2)+"\t"+rs.getDouble(3)); } s.close(); c.close(); } }
212 Consider the follow ing program W hich package should be added to the program to get corret code?. public 4 N A 2 java.sql.*
class db15 { public static void main(String args[])throw s Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c
=DriverManager.getConnection("jdbc:odbc:Mybm","",""); PreparedStatement s=c.prepareStatement(
"update db3 set Name=? w here Roll_no=?"); Statement s=c.createStatement( ); ResultSet
rs=s.executeQuery("select* from db3"); System.out.println("Name"+"\t"+"Roll no"+"\t"+"Avg"); w
hile(rs.next()) { System.out.println(rs.getString(1)+"\t"+rs.getInt(2)+"\t"+rs.getDouble(3)); } s.close();
c.close(); } }
213 Consider the follow ing program ,w hat should be the correction done in the program to get the correct output4 N A 2 missing }
214 Consider the follow ing program . Select the statement that should be added to the program to get correct 4 N A 2 All the above
output. import java.sql.*; class PreparedInsert { public static void main(String a[])
{ Try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:javadb"); System.out.println(" Connection to DataBase
created"); String a1 = "Insert into employee(id,name,salary) values(?,?,?)"; PreparedStatement ps =
con.prepareStatement(a1); ps.execute(a1); System.out.println("Record Inserted"); String querySel =
"Select * from employee"; ResultSet rs = ps.executeQuery(querySel); System.out.println("After
Insertion"); w hile(rs.next()) { System.out.println(" ID : "+ rs.getInt(1)); System.out.println(" Name : "+
rs.getString(2)); System.out.println(" Salary : "+ rs.getInt(3)); System.out.println(); } con.close(); }
catch(SQLException e) { System.out.println(“SQL Error”); } catch(Exception e) {
System.out.println(“Error”); } } }
215 Consider the follow ing program and identify the missing statement. import java.sql.*; class ps_isert { public 4 N A 2 missing catch block
216 Consider the follow ing program and identify the missing statement. class Type4_simple { public static void 4 N A 2 Missing semicolon &a
main(String[] args) {try { Class.forName("oracle.jdbc.driver.OracleDriver"); String
url="jdbc:oracle:thin:@pearl:1521:oracle10g"; Connection conn =
DriverManager.getConnection(url,"java","java"); System.out.println("successfully connected");
} catch(Exception e){e.printStackTrace()} } }
217 Consider the follow ing program and identify the missing statement. public class SimpleDemo { public 4 N A 2 All of the above
static void main(String[] args) { Connection con=null; Statement stmt=null; ResultSet rs=null; try {
String jdbcurl="jdbc:mysql://localhost:3306/test"; con=DriverManager.getConnection(jdbcurl, "root",
"root"); System.out.println("Connection established"); stmt=con.createStatement();
rs=stmt.executeQuery("select * from emp"); System.out.println("Empid \t Emap name \t City \t Salary");
w hile(rs.next()) { System.out.print(rs.getInt(1)+"\t"); System.out.print(rs.getString(2)+"\t");
System.out.print(rs.getString(3)+"\t"); System.out.print(rs.getFloat(4)); System.out.println(); }
} catch(ClassNotFoundException e) { e.printStackTrace();} catch(SQLException e)
{e.printStackTrace()} finally {try { rs.close(); stmt.close(); con.close(); } catch(Exception e){}
}} }
218 Consider the follow ing program W hat should be the correction done in the program to get the correct output4 N U 2 missing semicolon
219 Consider the follow ing program, it has 10 Records in the Table. W hat w ill be the output of follow ing 4 N A 2 Ramesh name w ill be
Code? import java.sql.*; public class db15 { public static void main(String args[])throw s Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c
=DriverManager.getConnection("jdbc:odbc:DSN2","",""); Statement s=c.createStatement( ); int
n=s.executeUpdate("update table set name='Ramesh'"); ResultSet rs=s.executeQuery("select* from db3");
System.out.println("Name"+"\t"+"Roll no"+"\t"+"Avg"); w hile(rs.next()) {
System.out.println(rs.getString(1)+"\t"+rs.getInt(2)+"\t"+rs.getDouble(3)); } s.close(); c.close(); } }
220 Consider the follow ing program,Select the statement that should be added to the program to get correct 4 N A 2 use ? in PreparedStat
output. import java.sql.*; public class db15 { public static void main(String args[])throw s Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c
=DriverManager.getConnection("jdbc:odbc:MyDSN","",""); PreparedStatement s=c.prepareStatement(
"update db3 set Name=# w here Roll_no=#"); Statement s=c.createStatement( ); s.setString(1,args[0]);
s.setString(2,args[1]); s.setString(3,args[2]); s.executeUpdate(); ResultSet rs=s.executeQuery("select*
from db3"); System.out.println("Name"+"\t"+"Roll no"+"\t"+"Avg"); w hile(rs.next()) {
System.out.println(rs.getString(1)+"\t"+rs.getInt(2)+"\t"+rs.getDouble(3)); } s.close(); c.close(); } }
221 Consider the follow ing program,Select the statement that should be added to the program to get correct 4 N A 2 Connection con =s.cre
output. import java.sql.*; public class db15 { public static void main(String args[])throw s Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c
=DriverManager.getConnection("jdbc:odbc:MyDSN","",""); PreparedStatement s=c.prepareStatement(
"update db3 set Name=? w here Roll_no=?"); Connection con
=s.createStatement(); s.setString(1,args[0]); s.setString(2,args[1]); s.setString(3,args[2]); ResultSet
rs=s.executeQuery("select* from db3"); System.out.println("Name"+"\t"+"Roll no"+"\t"+"Avg"); w
hile(rs.next()) {
System.out.println(rs.getString(1)+"\t"+rs.getInt(2)+"\t"+rs.getDouble(3)); } s.close();
c.close(); } }
222 Consider the follow ing program,Select the statement that should be added to the program to get correct 4 N A 2 s.executeUpdate()
output. import java.sql.*; public class db15 { public static void main(String args[])throw s Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c
=DriverManager.getConnection("jdbc:odbc:MyDSN","",""); PreparedStatement s=c.prepareStatement(
"update db3 set Name=? w here Roll_no=?"); Statement s=c.createStatement( ); s.setString(1,args[0]);
s.setString(2,args[1]); s.setString(3,args[2]); ResultSet rs=s.executeQuery("select* from db3");
System.out.println("Name"+"\t"+"Roll no"+"\t"+"Avg"); w hile(rs.next()) {
System.out.println(rs.getString(1)+"\t"+rs.getInt(2)+"\t"+rs.getDouble(3)); } s.close(); c.close(); } }
223 Consider the follow ing program. Select the statement that should be added to the program to get correct out4 N A 2 Statement st=conn.cr
224 Consider the follow ing program. W hat should be added in the program to get correct output? import java.sql4 N A 2 ResultSet rs=s.execut
225 Consider the follow ing program. W hat should be the ******* value in the program to get correct output? 4 N A 2 setString,setInt
public class MyPreparedStatement { public static void main(String a[]){ Connection con = null;
PreparedStatement prSt = null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:MyDSN"); String query = "insert into emp(name,salary)
values(?,?)"; prSt = con.prepareStatement(query); prSt.******(1, "John"); prSt.*****(2, 10000); int
count = prSt.executeUpdate(); } catch (ClassNotFoundException e)
{ e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } finally{ try{ if(prSt !=
null) prSt.close(); if(con != null) con.close(); } catch(Exception ex){} } } }
226 Consider the follow ing program. W hat should be the correction done in the program to get correct output? cl4 N A 2 Missing package
227 Consider the follow ing program. W hat should be the correction done in the program to get correct output? im4 N A 2 Missing }
228 Consider the follow ing program. W hat should be the correction done in the program to get correct output? im4 N A 2 PreparedStatement ps
values(?,?)"); p
230 Consider the follow ing program. W hat should be the correction done in the program to get correct output? cl4 N A 2 Missing Package state
231 Consider the follow ing program. W hat should be the correction done in the program to get correct output? im4 N A 2 Missing semicolon
232 Consider the follow ing program. W hat should be the correction done in the program to get correct output? im4 N A 2 s.executeUpdate(s1)
233 Consider the follow ing program. W hat should be the correction done in the program to get correct output? im4 N A 2 mssing try and catch
234 Consider the follow ing program. W hat should be the correction done in the program to get correct output? im4 N A 2 Missing semicolon
235 Consider the follow ing program. W hat should be the correction done in the program to get correct output? im4 N A 2 Missing }
Consider the follow ing program. W hat should be the correction done in the program to get correct output?
import java.sql.*; public class JdbcTest { public static void main(String a[]){ try
{ Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver"); Connection con =
238 Consider the follow ing program. W hat should be the correction done in the program to get correct output? im4 N A 2 replace executeUpdat
239 Consider the follow ing program. W hat should be the correction done in the program to get correct output? im4 N A 2 Missing }
240 Consider the follow ing program. W hat should be the correction done in the program to get correct output? im4 N A 2 add try and catch bloc
241 Consider the follow ing program. W hat should be the correction done in the program to get correct output? 4 N A 2 W rite executeQuery
import java.sql.*; class Ddemo1 { public static void main(String args[]) throw s Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," "); Statement s=c.createStatement(); ResultSet
rs=s.("select *from StudTable"); System .out.println("Name" + " \t " + "Roll_No" + "
\t " + "Avg"); w hile(rs.next()) { System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t
\t"+rs.getDouble(3)); } s.close(); c.close(); } }
242 Consider the follow ing program. W hat should be the correction done in the program to get correct output? im4 N A 2 Error in main()
243 Consider the follow ing program. W hat should be the correction done in the program to get correct output? im4 N A 2 Missing }
245 Consider the follow ing program. W hat should be the correction done in the program to get correct output? 4 N A 2 SQL Error has Occure
import java.sql.*; class Ddemo1 { public static void main(String args[]) throw s Exception {try{
Class.forName("sun.jdbc.odbc.JdbcodbcDriver");System .out.println("Driver Loaded Succsessfuly");}
catch(SQLException) { System .out.println("SQL Error has Occured");
}}}
246 Consider the follow ing program. W hat should be the correction done in the program to get correct output? im4 N A 2 Missing try and catch
247 Consider the follow ing program. W hat should be the correction done in the program to get correct output? im4 N A 2 Missing main()
248 4
Consider the follow ing program. W hat should be the correction done in the program to get correct output? Im N A 2 Connection con=Drive
249 Consider the follow ing program. W hat should be the correction done in the program to get correct output? 4 N A 2 Missing } and Incomp
import java.sql.*; class Testdemo { public static void main(String srgs[]) { try {
Class.forname("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Driver loaded"); String
url="jdbc:odbc:info"; Connection con=DriverManager.getConnection(str); System.out.println("connection to
database created"); Statement smt=con.createStatement(); System.out.println("Statement object
created"); String sql="Select Name,Age from Amol"; ResultSet result=smt._______________________
String text=""; w hile(result.next()) { text
+result.getString(1)+""+results.getInt(2)+'\n'; } System.out.println(text); } catch(sQLException e) {
System.out.pritln("SQL error"); } catch(Exceptionn e) { System.out.println("error"); }
250 Consider the follow ing program. W hat should be the correction done in the program to get correct output? 4 N A 2 Missing close stateme
import java.sql.*; import java.io.*; class Deleterecord { public static void main(String[] args) { ResultSet
rs; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con =
DriverManager.getConnection("jdbc:odbc:oraodbc","scott","tiger"); Statement stmt =
con.createStatement(); stmt.executeUpdate("delete from CUSTOMERS w here CUST_NUM = 101"); rs =
stmt.executeQuery("select * from customers"); System.out.println("CUST_NUM" + "\tCOMPANY" +
"\t\tCUST_REP" + "\tCREDIT_LIMIT"); w hile(rs.next()) { int no=rs.getInt(1); String
company=rs.getString(2); int rep=rs.getInt(3); double credit=rs.getDouble(4); System.out.println( no +
"\t\t"+company + "\t" + rep + "\t\t" + credit); } stmt.close(); System.out.println("Record Successfully
deleted"); }catch(Exception e)
{ e.printStackTrace(); } } }
Consider the follow ing program. W hat should be the correction done in the program to get correct output? im
252 Consider the follow ing program. W hat should be the correction done in the program to get correct output? im4 N A 2 Missing connection
253 Consider the follow ing program. W hat should be the correction done in the program to get correct output? 4 N A 2 All the Above
import java.sql.*; class StudentData { public static void main(String args[]) { {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") Connection con =
DriverManager.getConnection("jdbc:odbc:stud"); Statement st = con.createStatement(); ResultSet rs =
st.executeQuery("select * from Student"); System.out.println("The Database
is:-"); System.out.println("Roll\tName\t\tMarks Pass Birth-Date");
System.out.println("====================================="); w hile(rs.next()) int roll
= rs.getInt(1); String name = rs.getString(2); int marks = rs.getInt("Marks"); boolean pass
= rs.getBoolean(4); Date d = rs.getDate(5); System.out.printf("%-5d",roll); System.out.printf("%-
10s",name); System.out.printf("%-6d",marks); if(pass) System.out.printf("Yes "); else
System.out.printf("No ");
System.out.printf("%-15s\n",d.toString()); con.close(); } (Exception e){ } } }
254 Consider the follow ing program. W hat should be the correction done in the program to get correct output? cl4 N A 2 missing package state
255 Consider the follow ing program. W hat should be the correction done in the program to get correct output? im4 N A 2 missing c.close();
Consider the follow ing program. W hat should be the correction done in the program to get correct output? i
256 System.out.println("Connection error"); } try { String str="jdbc.odbc:dsn1"; con=DriverManager(str,"",""); S 4 N A 2 all of the above
257 Consider the follow ing program. W hat should be the correction done in the program to get correct output? 4 N A 2 error in createStatem
import java.sql.*; class login1 { public static void main(String args[]) { try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn=
DriverManager.getConnection("jdbc:odbc:mcm"); Statement stmt = conn.createStatement() ResultSet rs=
stmt.executeQuery("select passw ord from login w here login='"+args[0]+"'"); if(rs.next()) {
if(args[1].equals(rs.getString(1))) System.out.println("Login succesfully"); else System.out.println("W rong
Passw ord"); } else System.out.println("Login Name Not Found"); rs.close(); stmt.close(); conn.close(); }
catch(ClassNotFoundException ce)
{System.out.println("1");} catch(SQLException se){} } }
258 Consider the follow ing program. W hat should be the correction done in the program to get correct output? 4 N A 2 missing database nam
import java.sql.*; import java.io.*; public class InsertRecord2 { public static void main(String args[]) { try
{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
conn=DriverManager.getConnection("jdbc:odbc:"); Statement stmt=conn.createStatement();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("\nEnter
userid:"); String uid=br.readLine(); System.out.println("\nEnter passw ord:"); String ps=br.readLine();
stmt.executeUpdate("insert into login values(' "+uid+"
',' "+ps+" ')"); System.out.println("Record Inserted.........."); stmt.close(); conn.close(); br.close(); }
catch(ClassNotFoundException ce){} catch(SQLException se){} catch(IOException ie){} } }
259 Consider the follow ing program. W hat should be the correction done in the program to get correct output? 4 N A 2 Error in main()
import java.sql.*; class StudentData { public static void main(String args[]) ; { try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con =
DriverManager.getConnection("jdbc:odbc:stud"); Statement st = con.createStatement(); ResultSet rs =
st.executeQuery("select * from Student"); System.out.println("The Database
is:-"); System.out.println("Roll\tName\t\tMarks Pass Birth-Date");
System.out.println("====================================="); w hile(rs.next()) { int
roll = rs.getInt(1); String name = rs.getString(2); int marks = rs.getInt("Marks"); boolean pass =
rs.getBoolean(4); Date d = rs.getDate(5); System.out.printf("%-5d",roll); System.out.printf("%-
10s",name); System.out.printf("%-6d",marks); if(pass) System.out.printf("Yes "); else
System.out.printf("No ");
System.out.printf("%-15s\n",d.toString()); } con.close(); } catch(Exception e){ } } }
260 Consider the follow ing program. W hat should be the correction done in the program to get correct output?im4 N A 2 Error in main()
261 Consider the follow ing program. W hat should be the method used in follow ing program to get correct 4 N A 2 Connection()
output? import java.sql.*; class Ddemo1 { public static void main(String args[]) throw s Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
c=DriverManager.get***********("jdbc:odbc:ODSN"," "," "); Statement s=c.createStatement(); ResultSet
rs=s.executeQuery("select *from StudTable"); System
.out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg"); w hile(rs.next()) {
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3)); s.close(); c.close(); } } }
Consider the follow ing program. W hat w ill be the output? import java.sql.*; class Ddemo1 { public static vo
262 c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," "); Statement s=c.createStatement(); ResultSet rs= 4 N A 2 Display All the Records of StudTable
263 Consider the follow ing program. W hich statement is missing to get correct output? import java.sql.*; class 4 N A 2 Connection c not close
Ddemo1 { public static void main(String args[]) throw s Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," "); Statement s=c.createStatement(); ResultSet
rs=s.("select *from StudTable"); System .out.println("Name" + " \t " + "Roll_No" + "
\t " + "Avg"); w hile(rs.next()) { System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t
\t"+rs.getDouble(3)); } s.close(); } }
264 Consider the follow ing program. W hat should be the correction done in the program to get correct output? im4 N A 2 Missing Semicolon
265 Consider the follow ing program. W hat should be the correction done in the program to get correct output? 4 N A 2 Missing semicolon and
import java.sql.*; import javax.sw ing.*; import java.io.*; class datadd { public static void main(String
a[]) { try { Driver d= new sun.jdbc.odbc.JdbcOdbcDriver(); DriverManager.registerDriver(d); Connection
con
=DriverManager.getConnection("Jdbc:Odbc:xxx"); Statement s=con.createStatement(); ResultSet
rs=s.executeQuery("Select * from Table1 ") w hile(rs.next()) { String n=rs.getString("name");
System.out.println("name:"+n); String n1=rs.getString("rollnu"); System.out.println("rollnumber:"+n1); }
con.close(); } catch(Exception e) { System.out.println("not Deleted"+e); } }
266 Consider the follow ing program. In w hich statement there is an error? import java.sql.*; class DBEx { 4 N A 2 Error in Connection st
public static void main(String args[]) { try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c
= DriverManager.openConnection("jdbc:odbc:mydsn","",""); Statement s=c.createStatement(); ResultSet
rs = s.executeQuery("select * from StudTable"); w hile(rs.next()) { System.out.println("Roll No.:
"+rs.getInt(1)); System.out.println("Name : "+rs.getString(2)); System.out.println("Branch :
"+rs.getString("Branch")+"\n"); } s.close(); c.close();
}catch(Exception e) { System.out.println("Caught: "+e); } } }
267 Consider the follow ing program. Select the statement that should be added to get correct output. import 4 N A 2 Statement s = c.creat
java.sql.*; class DBEx { public static void main(String args[]) { try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c =
DriverManager.getConnection("jdbc:odbc:mydsn","",""); ResultSet rs = s.executeQuery("select
* from StudTable"); w hile(rs.next()) { System.out.println("Roll No.: "+rs.getInt(1));
System.out.println("Name : "+rs.getString(2)); System.out.println("Branch :
"+rs.getString("Branch")+"\n"); } s.close(); c.close(); }catch(Exception e) { System.out.println("Caught:
"+e); } } }
268 Consider the follow ing program. W hat should be the correction done in the program to get correct output?. i 4 N A 2 Statement missing
Consider the follow ing program. W hat should be the correction done in the program to get correct output?. i
270 Consider the follow ing program. W hat should be the correction done to get correct output? import java.sql.* 4 N A 2 Use ? symbol instead
271 Consider the follow ing program. W hat should be the correction done to get correct output? import java.sql.* 4 N A 2 No correction is requi
272 Consider the follow ing program. W hich tw o exceptions are throw n? package javaapplication21; import 4 N A 2 ClassNotFoundExcept
java.sql.*; public class db15 { public static void main(String args[]) throw s _____________________,
__________________ { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c
=DriverManager.getConnection("jdbc:odbc:MyDSN","",""); System.out.println("Connection
Established"); } }
273 Consider the follow ing program.Find error in the program. import java.sql.*; public class dbAccess { public s 4 N A 2 exception in main cla
274 Consider the follow ing program.Find out the output ? import java.sql.*; class Ddemo1 { public static void ma4 N A 2 Riya w ill be inserted
275 Consider the follow ing program.Find w hich statement contains error. import java.io.*; class Demp1 { public 4 N A 2 Error in package
276 Consider the follow ing program.Select the statement that should be added to the program to delete the recor4 N A 2 stm.executeUpdate(q
277 Consider the follow ing program.Select the statement that should be added to the program to get correct outp4 N A 2 con.close()
278 Consider the follow ing program.W hat shoud be added to the program to get the correct output. import java. 4 N A 2 ps.executeUpdate();
279 Consider the follow ing programe & find the error statement. import java.sql.*; class Test{ public static 4 N A 2 Missing Statement st=
void main(String ar[]){ try{ String url="jdbc:odbc:mydsn";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c=DriverManager.getConnection(url);
ResultSet rs=st.executeQuery("select * from login"); w hile(rs.next()){
System.out.println(rs.getString(1)); } }catch(Exception ee)
{System.out.println(ee);} } }
280 Consider the given code.W hat should be the correction in the program to get correct output? import java.sql.4 N A 2 Type of exception not
285 Debug the follow ing code and find w hich statement contains error. import java.sql.*; import java.io.*; class 4 N A 2 All of the above
286 Debug the follow ing code and find w hich statement contains error. import java.sql.*; import java.io.*; class 4 N A 2 Error in statement w
287 DriverManager class does not provides methods for ___________________ 4 N R 2 Executing sql statement and retrievi
289 Find Correction in follow ing statment to prepare prepareStatment Object. PreparedStatement pstmt; String q4 N U 2 pstmt = con.prepareS
pstmt.setString(2,&qu
Find Errors import java.sql.*; class Test{ public static void main(String ar[])throw s Exception {
292 Find Missing Statemt in program. import java.sql.*; import java.net.*; class conn { public static void main(St4 N U 2 Connection con=Drive
293 find out the error in the follow ing program to get correct output? import java.sql.*; import java.io.*; class 4 N A 2 error in main()
InsertDemo { public Static void Main(String args[]) { int c=0; try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String myURL="jdbc:odbc:college"; Connection
con=DriverManager.getConnection(myURL); Statement st=con.createStatement();
c=st.executeUpdate("insert into emp values(1,4000)") if(c!=0) System.out.println("Record inserted"); else
System.out.println("Record NOT inserted"); con.close(); }catch(Exception e){}
}}
294 Find out the missing statement to get the correct output in bellow program import java.sql.*; class stud2 { 4 N A 2 s1=con.createStatem
public static void main(String ar[])throw s Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:studdsn"); Statement s1; ResultSet res;
System.out.println("Before deletion"); res=s1.executeQuery("select * from student"); w hile(res.next()) {
System.out.println("Name\t"+res.getString(1)+" Roll_NO\t"+res.getInt(2)+" per\t"+res.getInt(3)); }
Statement st=con.createStatement(); st.executeUpdate("delete from student w here Roll_No=2");
System.out.println("deleted"); System.out.println("After
deletion"); res=s1.executeQuery("select * from student"); w hile(res.next()) {
System.out.println("Name\t"+res.getString(1)+" Roll_NO\t"+res.getInt(2)+" per\t"+res.getInt(3)); } } }
295 Find out the statement containing error. import java.sql.*; import java.io.*; class DisTable1 { public static vo4 N A 2 Statement w here pre
296 Find the error in follow ing program. import java.sql.*; class conn3 { public static void main(String h[]) { 4 N A 2 Error in PreparedState
try { int i; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Driver are properly
loaded"); String url="jdbc:odbc:abc1"; Connection con=DriverManager.getConnection(url);
System.out.println("connection established"); PreparedStatement state=con.PrepareStatement("select
Name,Age from stud9 w here
Age=?"); System.out.println("statement obj created"); String sql="select Name,Age from stud9 w here
Age=?"; int Age=2; state.setInt(1,Age); ResultSet rs=state.executeQuery(); String text=""; w
hile(rs.next()) { text=text+rs.getString(1)+""+rs.getInt(2); } System.out.println(text); }
catch(SQLException e) { System.out.println("Sql error has occured"+e.getMessage()); } catch(Exception e)
{ System.out.println("error!connection not establishd"+e.getMessage()); } } }
297 Find the error in the follow ing program import java.sql.*; public class dbDemo2 { public static void 4 N A 2 Both A and C
main(String args[])throw s Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c
=DriverManager.getConnection("jdbc:odbc:MyDSN","",""); Statement s=c.createStatement("select* from
student"); ResultSet rs=s.executeUpdate(); System.out.println("Name"+"\t"+"Roll no"+"\t"+"Avg"); w
hile(rs.next())
{System.out.println(rs.getString(1)+"\t"+rs.getInt(2)+"\t"+rs.getDouble(3)); } s.close();
c.close(); } }
298 Find the error in the follow ing program import java.sql.*; class Ddemo1 { public static void main(String args4 N A 2 error in call to execut
299 Find the error in the given code import java.sql.*; class Mydatabase1 { public static void main(String args[]) 4 N A 2 Drivermanager class n
300 Find the error in the given code import java.sql.*; class Mydatabase1 { public static void main(String args[]) 4 N A 2 Syntax of SetInt &am
301 Find the error in the given code Statement st=c.createStatement(); Resultset rs=st.executeQuery("Select * f 4 N A 2 Resultset interface na
302 Find the error of follow ing code import java.sql.*; public class dbAccess { public static void main(String[] arg4 N U 2 Try and catch block m
303 Find the missing method in follow ing code. class jdbc1 { public static void main(String ar[])throw s Exception4 N A 2 createStatement();
304 Find the missing statement import java.sql.*; class Ddemo1 { public static void main(String args[]) throw s E4 N A 2 ResultSet rs=s.execut
305 find the missing statement import java.sql.*; public class dbDemo1 {public static void main(String args[])thr4 N A 2 s.executeUpdate(quer
306 Find the missing statement from w hich the output w ill be displayed as connection established. import java.s4 N A 2 con=DriverManager.g
307 Find the missing statement to get output. import java.sql.*; class conn1 { public static void main(String h[]) 4 N A 2 Missing }
308 getConnection() method have w hich parameters: _____________________ 4 N R 2 URL -JdbclOdbc:DSN ,String Usernam
313 How is a pre-compiled query w ritten? Pick out the correct statement. 4 N A 2 Class.forName("
c=DriverManager.getC
"); PreparedSta
empid=?"); Res
314 How many firstname w ill be displayed using follow ing code ? import java.sql.*; public class 4 N A 2 3
JdbcPreparedstatementExample { static private final String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; static
private final String connection = "jdbc:odbc:emp"; public static void main(String args[]) { Connection con
= null; PreparedStatement pst = null; ResultSet rs = null; try { Class.forName(driver); con =
DriverManager.getConnection(connection); String sql = "select * from Employees w here FirstName " +
"in(?,?,?)"; pst = con.prepareStatement(sql); pst.setString(1, "komal"); pst.setString(2, "ajay");
pst.setString(3, "santosh"); rs = pst.executeQuery(); System.out.println("EmployeeID\tFirstName"); w hile
(rs.next()) { System.out.print(" "+rs.getString(1)); System.out.print("\t\t"+rs.getString(2));
System.out.println("\t\t"+rs.getString(3)); } } catch (Exception e) { System.out.println(e); } }
}
315 How w ill JDBC help the programmers to w rite java applications that manage programming activities: 4 N U 2 All of Above
317 Identify correct syntax of executeQuery() method of statement interface. 4 N U 2 public ResultSet executeQuery( Strin
318 Identify the correct code to retrive values from database 4 N A 2 Statement st=con.cre
}
319 Identify the missing code in the program given below . import java.sql.*; class stud_records { public static vo4 N A 2 prepareStatement();
322 If ___________is set to true,then a commit is implicitly applied after the execution of every 4 N R 2 AutoCommit
SQL statement.
323 import java.io.IOException; import java.sql.*; w hat is the correction in the follow ing code to get the output 4 N A 2 Missing Semicolon
324 import java.sql.*; public class jdbcConn { public static void main(String[] args) throw s Exception{ 4 N A 2 Id Name Job 23 Rosha
Class.forName("org.apache.derby.jdbc.ClientDriver"); Connection con = DriverManager.getConnection
("jdbc:derby://localhost:1527/testDb","name","pass"); PreparedStatement updateemp =
con.prepareStatement ("insert into emp values(?,?,?)"); updateemp.setInt(1,23);
updateemp.setString(2,"Roshan"); updateemp.setString(3, "CEO"); updateemp.executeUpdate();
Statement stmt = con.createStatement(); String query = "select
* from emp"; ResultSet rs = stmt.executeQuery(query); System.out.println("Id Name Job"); w hile
(rs.next()) { int id = rs.getInt("id"); String name = rs.getString("name"); String job = rs.getString("job");
System.out.println(id + " " + name+" "+job); } } }
325 import java.sql.*; public class jdbcConn { public static void main(String[] args) throw s Exception{ Class.forN4 N A 2 no of columns in the t
No of characters in 3r
326 Import java.sql.*; class connectionTest { public static void main(String args[]) { try { Class.forName(“sun.jd 4 N A 2 undefined symbol url
327 import java.sql.*; class S14 { public static void main(String args[])throw s Exception; { Class.forName("sun.j4 N A 2 Error in main()
328 import java.sql.*; import java.io.*; import java.sql.Satement; import java.lang; public class conTestTable { p4 N A 2 Selected record is del
329 import java.sql.*; import sun.jdbc.odbc.*; class mydatabase { public static void main(String args[]) throw s S4 N A 2 this program w ill cha
330 import java.sql.*; public class Pstatement { public static void main(String args[]) { try { Class.forName("sun 4 N A 2 ?,?
331 import java.sql.*; class FetchRecord{ public static void main(String args[])throw s Exception{ Class.forName 4 N A 2 deletes the record hav
332 import java.sql.*; class InsertPrepared{ public static void main(String args[]){ try{ 4 N A 2 101 is inserted at firs
Class.forName("oracle.jdbc.driver.OracleDriver"); Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
PreparedStatement stmt=con.prepareStatement("insert into Emp values(?,?)"); stmt.setInt(1,101);//1
specifies the first parameter in the query stmt.setString(2,"Ratan"); int i=stmt.executeUpdate();
System.out.println(i+" records inserted"); con.close();
}catch(Exception e){ System.out.println(e);} } }
333 In W hich driver Netw ork connection is indirect that a JDBC client makes to a middlew are process that acts a4 N U 2 A.JDBC-Net
334 In DriverManager class w hich method is used to establish the connection w ith the specified url? 4 N A 2 public static Connecti
335 In follow ing Java code fill statement show ing ***.Select any one option from given options import java.io.*;4 N A 2 insert into student va
336 In follow ing Java program fill statement show ing **************.Select any one option to get correct outp4 N A 2 pstm.setInt(1, rno); a
337 In follow ing Java program fill statement show ing ***.Select any one option fro given options import java.sq 4 N A 2 con.createStatement(
338 In follow ing Java program fill statement show ing ________________. Select any one option fro given 4 N A 2 DriverManager.getCon
options import java.sql.*; class Type1 { public static void main(String[] args) {try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url="jdbc:odbc:dsn3"; Connection conn
= ____________________ System.out.println("successfully connected"); }catch(Exception e)
{System.out.println(e); } } }
In follow ing Java program fill statement show ing _______________________.Select any one option fro give
340 In setXxx() methods used for PreparedStatement the first argument specifies w hich value? 4 N U 2 index of Question mark
341 In the below code, rs is an object of _________ interface of JDBC API w hile (rs.next()) { System.out.println(4 N U 2 ResultSet
342 In the below statement, w hich type of query can be used w ith executeUpdate() method statement.executeU4 N U 2 INSERT, UPDATE, DEL
343 In the follow ing JDBC drivers w hich are know n as fully java driver? 4 N A 2 Both B & C
344 In the follow ing JDBC drivers w hich is know n as partially java driver? 4 N A 2 Native-API driver
345 In the follow ing program make corrections to get correct output: import java.sql.*; class DBEx 4 N A 2 s.executeUpdate(sql);
{ public static void main(String args[]) { try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
c = DriverManager.getConnection("jdbc:odbc:mydsn","",""); Statement s =
c.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE); String sql =
"create table Product(prod_id Integer, prod_name varchar(25), price Double)"; s.executeCreate(sql);
System.out.println("Table created."); c.close(); }catch(Exception e) { System.out.println("Exception
generated: "+e); } } }
347 In Transaction Management of JDBC w hich means once a transaction has been committed, it w ill remain so, 4 N A 2 Durability
348 In w hich layer tw o tier model are divided into tw o parts 4 N R 2 application layer & database la
349 In w hich the result set generally does not show changes to the underlying database that are made w hile it is4 N U 2 B.TYPE_SCROLL_INSE
350 insert the missing statement ,rectify incorrect statement and choose the correct option for given program. Im4 N A 2 import java.sql.*; con
352 JDBC is …………………level interface w hich means that it is used to invoke SQL command directly 4 N A 2 low level
354 kind of driver converts JDBC calls on client API for Oracle, cybase, Informix, DB2, or other DBMS 4 N U 2 Native API partly-Java
is know n as__________
355 Method w hich drops the driver from the list of drivers registered in the DriveManager class. 4 N A 2 deregisterDriver(Driver driver)
359 Observe follow ing code and find out missing statement. import java.io.*; import java.sql.*; 4 N A 2 Semicolon Missing
class updatdb {public static void main(String args[]) {try
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con
=DriverManager.getConnection("jdbc:odbc:stud"); Statement s = con.createStatement(); int r
= s.executeUpdate("update stud set name=priti w here name='preety'"); System.out.println("No. of row
updated:"+r) ResultSet rs=s.executeQuery("select * from stud"); w hile(rs.next())
{System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3));
} con.close(); } catch(Exception e){ } } }
360 Observe follow ing code and select correct statement for it to be executed. ResultSetMetaData md = rs.getMe4 N A 2 ResultSetMetaData m
361 Observe the follow ing code and w hat w ill be the output of the program import java.sql.*; import java.io.*; 4 N A 2 The output w ill give i
362 Observe the follow ing figure and identify the type of architecture. Figure:- 4 Y1 R 2 Tw o-Tier
363 Observe the follow ing program import java.sql.*; class TYIFCon{ public static void main(String args[]){ try{ 4 N A 2 This program w ill fet
364 Observer the follow ing program. import java.sql.*; import java.io.*; class TYIFloop{ public static void main(S4 N A 2 This program w ill ins
System.out.println(i+" records affected"); System.out.println("Do you w ant to continue: y/n"); String s=br.r
365 Observer the follow ing program. import java.sql.*; class Test{ public static void main(String ar[]){ try{ 4 N A 2 Follow ing statement
String url="jdbc:odbc:mydsn"; Connection c=DriverManager.getConnection(url); Statement
st=c.createStatement(); ResultSet rs=st.executeQuery("select * from login"); w hile(rs.next()){
System.out.println(rs.getString(1)); } }catch(Exception ee)
{System.out.println(ee);} }
366 Observer the follow ing program. import java.sql.*; class Test{ public static void main(String ar[]){ try{ Strin4 N A 2 There is compiler erro
367 Observer the follow ing program. import java.sql.*; class TYIFCon{ public static void main(String args[]){ try4 N A 2 In This program execu
368 Output of follow ing code is : import java.sql.*; class createTable { public static void main(String[] args) { tr 4 N A 2 driver loaded connect
Record Inserted :: 3 R
CCC
369 Output of the follow ing program import java.sql.*; Class ExecuteUpdateTest { Public static void 4 N A 2 Driver loaded Connec
main(String argu[]) { Try { int I; Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); Record Inserted 2 Rec
System.out.println(“Driver Loaded”); String url=”jdbc:odbc:xyz”; Connection
con=DriverManager.getConnection(url); System.out.println(“Connection to database created”); Statement
state=con.createStatement(); System.out.println(“Statement object created”); String sql=”Insert into tanni
values(‘Tanmy’,2)”; I=state.executeUpdate(sql); System.out.println(“Record inserted ”+i); String
sql1=”Insert into tanni values(‘Raddhi’,2)”;
I=state.executeUpdate(sql1); System.out.println(“Record inserted”+i); String sql2=”Insert into tanni
values(‘Siddi’,2)”; I=state.executeUpdate(sql2); System.out.println(“Record inserted”+i);
} Catch(SQLException e) { System.out.println(“SQL error”); } Catch(Exception e){ System.out.println(“SQL
error”); } } }
371 Predict output import java.sql.*; class Test{ public static void main(String ar[])throw s Exception { String url 4 N A 2 Drivers Loaded and co
372 Predict output import java.sql.*; class Test{ public static void main(String ar[])throw s Exception { String url 4 N A 2 Error
373 Prepared Statement interface creates an object that represents a________________ 4 N U 2 Precompiled SQL Statement
376 PreparedStatement updateemp = con.prepareStatement("insert into emp values(?,?,?)"); How many values a4 N A 2 3
380 Rearrange the steps to connect to the database in SQL a. Create the connection object b. Execute the query c4 N U 2 d-a-e-b-c
381 ReslutSetMetaData Interface Object created by ______________ method, of ____________ 4 N U 2 getMetaData(), Resul
interface
382 ResultSet interface is used to retrive the result form the database table? 4 N A 2 1
383 ResultSet is __________________W hich Represents a data from database 4 N R 2 Table of Data
384 ResultSet rs = stmt.executeQuery("SELECT COF_NAME, PRICE FROM COFFEES"); w here the stmt is Stateme 4 N A 2 pst = con.prepareStat
ResultSet rs = pst.exe
387 select correct statement to delete row from table employee w here emp_id=? 4 N A 2 String sql=”delete fro
388 Select correct statement w hich is to be used here for inserting a new record in DB having columns 4 N A 2 int r = s.executeUpda
RollNo,Name and Percentage. import java.io.*; import java.sql.*; import java.sql.Statement; class insertdb
{public static void main(String args[]) {try
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con
=DriverManager.getConnection("jdbc:odbc:stud"); Statement s = con.createStatement();
System.out.println("No. of row updated:"+r); ResultSet rs=s.executeQuery("select * from stud"); w
hile(rs.next()) {System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3));
} con.close(); } catch(Exception e){ } } }
389 Select correct statements to be w ritten in space provided w ith * in follow ing given codeimport java.sql.*; c 4 N A 2 Connection con=Drive
390 Select the correct method(s) to create CallableStatement: 4 N U 2 All of the above
391 Select the correct option for fill in the blank import java.sql.*; class data { public static void main(String 4 N A 2 A. PreparedStatement
a[]) { Driver d= new sun.jdbc.odbc.JdbcOdbcDriver(); DriverManager.registerDriver(d); Connection con
=DriverManager.getConnection("Jdbc:Odbc:UUU");
_____________________________________________ } }
Select the correct option for fill in the blank import java.sql.*; class data { public static void
392 main(String a[]) { try { Driver d= new sun.jdbc.odbc.JdbcOdbcDriver(); DriverManager.registerDriver(d); 4 N A 2 DSN name and con.cr
Connection con
=DriverManager.getConnection("Jdbc:Odbc:_____________________"); Statement
s=_____________________________ int n=s.executeUpdate("Insert into Table1 values('hhh',12)");
if(n==1) { System.out.println("Record inserted "); con.close(); } } catch(Exception e) {
System.out.println("not Inserted"+e); } } }
393 Select the correct option that can be used to create a result set in w hich the cursor can move in both the dire4 N U 2 TYPE_SCROLL_SENSI
394 select the missing statement from program given below import java.sql.*; class ps_insert { public static void 4 N U 2 String str="inse
ps=con.prepareStatem
395 Select the missing statement in the program to get the follow ing output. import java.sql.*; class Demo1 { 4 N A 2 ps.setString(2,s1);
public static void main(String args[]) throw s Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:student"," "," "); int r1=11; String s1="suhas";
String str="insert into studTable values(?,?); PreparedStatement ps=c.prepareStatement(str);
ps.setInt(1,r1); ps.executeUpdate(); System.out.println("Data inserted:"); s.close(); c.close();
}}
396 Select the missing statement in the program to get the output import java.sql.*; import java.io.*; class RS{ p4 N A 2 ps.executeUpdate();
397 Select the proper missing method for the follow ing code String queryLehigh = "select * from Lehigh"; Result 4 N A 2 executeQuery()
398 select the proper statement to establish the connection w ith database 4 N U 2 Connection con=DriverManager.getC
399 Select the statement from options that should get added at ********************** in bellow program 4 N A 2 st.executeUpdate();
import java.sql.*; class stud4 { public static void main(String ar[])throw s Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:studdsn"); Statement s1=con.createStatement(); ResultSet
res; System.out.println("Before Updation"); res=s1.executeQuery("select * from student"); w
hile(res.next()) { System.out.println("Name\t"+res.getString(1)+" Roll_NO\t"+res.getInt(2)+"
per\t"+res.getInt(3)); } PreparedStatement st=con.prepareStatement("update student set Name=? w here
Name=? "); st.setString(1,"Ram"); st.setString(2,"Ramesh");
**************************************************** System.out.println("updated");
System.out.println("After updation"); res=s1.executeQuery("select * from student"); w hile(res.next()) {
System.out.println("Name\t"+res.getString(1)+" Roll_NO\t"+res.getInt(2)+" per\t"+res.getInt(3)); } } }
Select the statement that should be added to program to get corrected output import java.sql.*; import java.
400 s1; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Drivers loaded"); String url="j 4 N A 2 ResultSet rs=st.execu
401 Select the statement that should be added to the follow ing program to get the correct output. import java.sq 4 N A 2 Class.forName("
402 Select the statement that should be added to the program to get correct output. import java.sql.*; public 4 N A 2 s.executeUpdate()
class db15 { public static void main(String args[])throw s Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c
=DriverManager.getConnection("jdbc:odbc:MyDSN","",""); PreparedStatement s=c.prepareStatement(
"update db3 set Name=? w here Roll_no=?"); Statement s=c.createStatement( ); s.setString(1,args[0]);
s.setString(2,args[1]); s.setString(3,args[2]); ResultSet rs=s.executeQuery("select* from db3");
System.out.println("Name"+"\t"+"Roll no"+"\t"+"Avg"); w hile(rs.next()) {
System.out.println(rs.getString(1)+"\t"+rs.getInt(2)+"\t"+rs.getDouble(3)); } s.close(); c.close(); } }
403 Set XXX() method binds values to the parameters. W here XXX represents 4 N U 2 Data Type
404 Statement interface is used for ________________________________ 4 N U 2 sending SQL queries to the databas
405 Stored procedures have w hich of the follow ing advantages? 4 N U 2 Data integrity improves as multiple a
406 Suggest corrections in the follow ing program segment import java.sql.*; import sun.jdbc.odbc.*; class myda 4 N A 2 public static void main
DriverManager.getCon
409 The follow ing example to connect Java Application w ith access? import java.sql.*; class Test { public static v4 N A 2 w ith DSN
410 The follow ing step is for stmt.executeUpdate(sql); sql = "INSERT INTO Registration " + "VALUES(103, 'Sumit4 N A 2 Insert
412 The JDBC-ODBC bridge allow s ---------------------- to be used as --------------------------- 4 N U 2 ODBC drivers,JDBC drivers
415 The method - "public DatabaseMetaData getMetaData()" - belongs to the Interface 4 N A 2 Connection interface
_____________________
417 The output of follow ing program is : import java.sql.*; class preparestmt { public static void main(String[] a 4 N A 2 driver loaded connect
418 The parameters of the PreparedStatement object are _____w hen the user clicks on the Query button 4 N U 2 initialized
420 The Statement interface is mainly used to_______________ 4 N U 2 To execute queries asked to databa
421 The statement ___________ changes the Course title to Java Programming for the CourseID 4 N U 2 update Course set titl
11111.
422 The __________ method can be used on a ___________ object to create its meta data object 4 N U 2 getMetaData(),Result
423 The __________ package contains classes that help in connecting to a database, sending 4 N U 2 java.sql
SQL statements to the database, and processing the query result
424 The __________method sets the query parameters of the PreparedStatement Object. 4 N U 2 setString()
425 The __________object provides you w ith methods to access data from the table. 4 N U 2 ResultSet
426 This is an example of prepared statement interface that ? PreparedStatement stmt=con.prepareStatement("se4 N A 2 B. retrieve the record
427 This is an example of Statement interface that? import java.sql.*; class PreStat { public static void 4 N A 2 retrieve the record
main(String args[]) throw s Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
c=DriverManager.getConnection("jdbc:odbc:student"," "," "); Statement s=c.createStatement("select *
from studTable"); ResultSet rs=s.executeQuery(); System
.out.println("Name" + " \t " + "Roll_No"); w hile(rs.next()) { System.out.println(rs.getInt(1)+" \t
"+rs.getString(2)); } s.close(); c.close(); } }
428 This statement Tells the DB to empty transaction log & bring DB back to the state, before the changes in tran4 N U 2 rollback()
429 Three-tier Architecture includes w hich of the follow ing. 4 N U 2 client layer and tw o server layers
430 To connect to a local MySQL database named test, use 4 N U 2 Connection connection
431 To delete reord from database table student w hat modification w e have to do in follow ing program. import j4 N A 2 int result=stmt.execu
432 To establish connection w ith database w hich method of DriverManager class is used? 4 N U 2 getConnection()
433 To establish the connection w ith the specified url? 4 N U 2 public static Connection getConnection(Str
434 To execute a SELECT statement "select * from Address" on a Statement object stmt, use 4 N U 2 stmt.executeQuery("select * from Ad
To execute a stored procedure "totalStock" in a database server, w hich of the follow ing code CallableStatement clbstmnt = con.prepare
435 4 N U 2
is used? totalStock}");cs.executeQuery();
436 To execute create query w hich method is used? 4 N U 2 execute()
To obtain a scrollable or updateable result set, you must first create a statement using the Statement statement = connection.createS
437 4 N U 2
follow ing syntax: ResultSet.CONCUR_UPDATABLE);
438 To set the parameters in PreparedStatement w hich methods are used? 4 N U 2 both a& b
439 To syntax for creating a table named Course should begin w ith __________. 4 N U 2 create table Course (
To to get the column names and row data from a table. Select the proper statement from the
follow ing AT *____________line import java.sql.*; public class SelDemo { public static void
main(String args[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con =
DriverManager.getConnection("jdbc:odb c: myDSN "); Statement st = con.createStatement();
440 *_________________________________//(Choose correct option for this line) 4 N A 2 ResultSet sel = st.executeQuery ("se
w hile(sel.next()) { String name = sel.getString(1); String pass = sel.getString(2);
System.out.println(name+" "+pass); } } catch(Exception e) {
System.out.println("Errooorrrr"+e.getMessage()); } } }
try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
441 Class.forName("oracle.jdbc.driver.OracleDriver"); } catch(ClassNotFoundException cnfe) { 4 N A 2 W ill load tw o different drivers
System.err.println("Error loading driver: " + cnfe); }
442 tw o-tiers and three-tiers architecture is applicable w ith the database? 4 N A 2 YES
444 W e can use ResultSet navigation methods w hen w e have ResultSet that is of type 4 N U 2 both b&c
445 W hat contains object specific to database,and Used to create Connection object from the options ? 4 N R 2 Driver Interface / Conn
W hat correction should be done in the program to get corrected output import java.sql.*;
import java.io.*; class JdbcP { public static void main(String arg[]) { try { DataInputStream
in=new DataInputStream(System.in); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Drivers loaded"); String url="jdbc.odbc.abc"; Connection
con=DriverManager.getConnection(url); System.out.println("connection established");
PreparedStatement ps=con.prepareStatement("create table movie6(num Integer,mvnm
446 Varchar(30))"); ps.executeUpdate(); System.out.println("Table Created"); String sql="insert 4 N A 2 String url="jdbc:odbc:abc";
into movie6 VALUES(?,?)"; PreparedStatement ps2=con.prepareStatement(sql);
System.out.println("Enter movie code"); int mcd=Integer.parseInt(in.readLine());
ps2.setInt(1,mcd); System.out.println("Enter movie name"); String name=in.readLine();
ps2.setString(2,name); ps2.executeUpdate(); con.close(); } catch(SQLException e) {
System.out.println(" sql error"); } catch(Exception e) { System.out.println(" connection
error1"); } } }
W hat correction should be done in the program to get corrected output import java.sql.*;
import java.io.*; class JdbcP { public static void main(String arg[]) { try { DataInputStream
in=new DataInputStream(System.in); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Drivers loaded"); String url="jdbc:odbc:abc"; Connection
con=DriverManager.getConnection(url); System.out.println("connection established");
447 ps.executeUpdate(); System.out.println("Table Created"); String sql="insert into movie6 4 N A 2 Missing Statement
VALUES(?,?)"; PreparedStatement ps2=con.prepareStatement(sql); System.out.println("Enter
movie code"); int mcd=Integer.parseInt(in.readLine()); ps2.setInt(1,mcd);
System.out.println("Enter movie name"); String name=in.readLine(); ps2.setString(2,name);
ps2.executeUpdate(); con.close(); } catch(SQLException e) { System.out.println(" sql error");
} catch(Exception e) { System.out.println(" connection error1"); } } }
W hat does "msbte" indicate in the below code?
448 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection 4 N U 2 Data Source Name
con=DriverManager.getConnection("jdbc:odbc:msbte");
449 W hat does the follow ing code do? smt=con.createStatement(); 4 N A 2 A Statement object is created to sen
450 W hat happens after executation of follow ing code import java.sql.*; public class JdbcAccessConnectionDemo4 N A 2 Connecction OK.
451 W hat happens after executation of follow ing code import java.sql.*; import java.io.*; public class new { 4 N A 2 Successfully Run and
public static void main(String args[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Drivers are loaded properly."); String url = "jdbc:odbc:Demo"; Connection c1 =
DriverManager.getConnection(url); String sql="create table emp1(emp_id INTEGER,emp_name
varchar(20))"; PreparedStatement ps = c1.prepareStatement(sql); ps.executeUpdate(); c1.close();
}catch(SQLException se) { System.out.println("SQL Error."); }catch(Exception e) {
System.out.println("Other Error."); } }
}}
452 W hat happens if the follow ing code is executed? import java.sql.*; public class S1Q57{ public static void 4 N A 2 There is a compiler er
main(String[] args) { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con =
DriverManager.getConnection("jdbc:odbc:shree"); Statement stm = con.createstatement(); String query
="select rollno,name,percent from student "; ResultSet rs
= stm.executeQuery(query); w hile(rs.next()){ System.out.println("Roll No = "+rs.getInt(1));
System.out.println("Name = "+rs.getString(2)); System.out.println("per = "+rs.getDouble(3));
} con.close(); } }
453 W hat happens if you call deleteRow () on a ResultSet object? 4 N A 2 The row you are positioned on is del
454 W hat happens if you call the method close() on a ResultSet object? 4 N U 2 the database and JDBC resources ar
455 W hat is correct about DDL statements (create, grant,…)? 4 N A 2 DDL statements are t
456 W hat is error in follow ing program import java.sql.*; class PreparedStatementDemo { public static void mai 4 N A 2 error:incompatible typ
457 W hat is error in follow ing program? import java.sql.*; class PreparedStatementDemo { public static void ma4 N A 2 java.sql.SQLException
458 W hat is error in follow ing program? import java.sql.*; class PreparedStatementDemo { public static void 4 N A 2 java.sql.SQLException
main(String args[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con= operator) in query exp
DriverManager.getConnection("jdbc:odbc:Samarth"); PreparedStatement
ps1=con.prepareStatement("update student set Name=? City=? ID=? w here ID=?");
ps1.setString(1,"tttt"); ps1.setString(2,"Belhe"); ps1.setInt(3,777); ps1.setInt(4,777);
ps1.executeUpdate(); ps1.close(); con.close(); } catch(Exception e) { System.out.println(e); }
}}
459 W hat is error in follow ing program? import java.sql.*; class PreparedStatementDemo { public static void ma4 N A 2 java.sql.SQLException
W hat is error in follow ing program? import java.sql.*; class Demo3 { public static void
461 W hat is meaning of follow ing code snippet System.out.println("NAME\tAGE"); String sql = "select Name, Ag 4 N A 2 executeQuery() meth
ResultSet class
462 W hat is missing in the follow ing program? import java.sql.*; public class execute { public static void main(S4 N A 2 to register the driver
463 w hat is Native Protocol, Pure Java Driver? 4 N A 2 This type of driver, w ritten entirely in
464 W hat is output of follow ing code import java.sql.*; import java.io.*; public class StudentTableInsert { public4 N A 2 Driver Loaded Connec
465 W hat is output of follow ing program. import java.sql.*; public class jdbc1 { public static void main(String 4 N A 2 values of id and name
args[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:data"); Statement st=con.createStatement(); ResultSet
rs=st.executeQuery("select * from student"); w hile(rs.next()) { System.out.println("id:"+rs.getInt("id"));
System.out.println("name:"+rs.getString("name1"));
} con.close(); } catch(SQLException e) {} catch(Exception e) { } } }
467 W hat is the disadvantage of Type-4 Native-Protocol Driver? 4 N A 2 At client side, a separate driver is ne
468 W hat is the error in this code import java.sql.*; class ConnectionDemo { public static void main(String args[ 4 N A 2 Statement not created
470 W hat is the missing in the follow ing program import java.sql.*; public class connection { public static void m4 N A 2 Connection to databas
471 w hat is the missing statement in follow ing program to access the database using jdbcodbc connection 4 N A 2 Statement stmt = con
import java.util.*; import java.sql.*; public class JdbcDemo { public static void main(String args[]) { String
query = "SELECT Name,Description,Qty,Cost FROM Stock"; try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection
("jdbc:odbc:Inventory"); ResultSet rs = stmt.executeQuery(query); w hile (rs.next()) { String name =
rs.getString("Name"); String desc
= rs.getString("Description"); int qty = rs.getInt("Qty"); float cost = rs.getFloat("Cost");
472 W hat is the ouput of follow ing code?Assume suitable data import java.sql.*; class contest { public static voi 4 N A 2 Table created
473 w hat is the output of follow ing code import java.sql.*; class StudentData { public static void main(String 4 N A 2 marks>40
args[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con =
DriverManager.getConnection("jdbc:odbc:stud"); PreparedStatement ps = con.prepareStatement("select *
from Student w here Marks > ?"); ps.setInt(1,40); ResultSet rs
= ps.executeQuery(); System.out.println("marks"); w hile(rs.next()) System.out.println(rs.getString(2));
con.close(); } catch(Exception e){ } } }
474 w hat is the output of follow ing code import java.sql.*; class cont { public static void main(String args[]){ tr 4 N A 2 both b and c
475 w hat is the output of follow ing code Try{ String sql=”update emp set salary=? W here id=?”; PreparedState 4 N A 2 update emp by accep
476 W hat is the output of follow ing Program import java.sql.*; public class jdbcConn { public static void 4 N A 2 No. of row s before co
main(String[] args) throw s Exception{ Class.forName("org.apache.derby.jdbc.ClientDriver"); Connection
con = DriverManager.getConnection("jdbc:derby://localhost:1527/testDb","name","pass"); Statement stmt
= con.createStatement(); String query = "insert into emp values(2,'name1','job')"; String query1 ="insert
into emp values(5,'name2','job')"; String
query2 = "select * from emp"; ResultSet rs = stmt.executeQuery(query2); int no_of_row s = 0;
w hile (rs.next()) { no_of_row s++; } System.out.println("No. of row s before commit statement
= "+ no_of_row s); con.setAutoCommit(false); stmt.execute(query1); stmt.execute(query); con.commit();
rs = stmt.executeQuery(query2); no_of_row s = 0; w hile (rs.next()) { no_of_row s++; }
System.out.println("No. of row s after commit statement = "+ no_of_row s); }
477 W hat is the output of follow ing program: import java.sql.*; class exp10_5 { public static void main(String 4 N A 2 Compile Error
m[])throw s Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:dsnname"); Statement cmd=con.createStatement();
rs=cmd.executeQuery("select * from tabel1"); w hile(rs.next()) {
System.out.println(rs.getInt(1)+""+rs.getInt(2)+""+rs.getString(3)); } cmd.close(); con.close();
}}
478 W hat is the purpose of follow ing code? import java.sql.*; class DeleteRecord { public static void 4 N A 2 Deletes all the record
main(String args[])throw s Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:xyz"); Statement stmt=con.createStatement(); int
result=stmt.executeUpdate("delete from emp"); con.close();
}}
479 W hat is the purpose of next() method? 4 N U 2 next ( ) method is used to retain nex
480 W hat is the query used to display all tables names in SQL Server (Query analyzer)? 4 N A 2 select * from information_schema.ta
481 W hat is the return value from stmt.executeQuery("insert into T values (100, 'Smith')") 4 N A 2 Result Set object
482 W hat is the return value from stmt.executeUpdate("insert into T values (100, 'Smith')") 4 N A 2 an int value indicating how many ro
483 w hat is the syntax of close() method in conection interface method 4 N A 2 public void close() throw s SQLExcept
484 W hat is the type of 'cmd' object in the follow ing program. import java.sql.*; class exp11_4 { public static 4 N A 2 PreparedStatement
void main(String arg[]) { Class.forName("sun.jdbc.odbc,JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:dsnname"); String str="select * from emp w here
ename='ram'";
____________________cmd=con.__________________(str); ResultSet rs=cmd.executeQuery(); w
hile(rs.next()) { System.out.println(rs.getString(1)+" "+rs.getString(2)); } cmd1.close(); con.close(); } }
485 W hat is the use of Statement interface? 4 N U 2 Statement interface provides metho
487 w hat may be the output of follow ing program import java.sql.*; class exp10_1 { public static void main(Stri4 N A 2 1 123 Mahesh 2 453 S
488 W hat MySQL property is used to create a surrogate key in MySQL? 4 N U 2 AUTO_INCREMENT
489 W hat should be at the place of ________ to get the correct output: import java.sql.*; public class 4 N A 2 createStatement()
Updatedbase { public static void main(String args[]) { try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:data"); Statement st=con._______________; ResultSet
rs=st.executeQuery("select * from emp"); System.out.println("before change"); w hile(rs.next()) {
System.out.println("id:"+rs.getInt("id")); System.out.println("salary:"+rs.getString("salary"));
System.out.println("name:"+rs.getString("name1")); } int k=st.executeUpdate("Update emp set
salary=1000 w here id=3"); System.out.println("row s affected:"+k); System.out.println("\n\nafter
change"); rs=st.executeQuery("select * from emp"); w hile(rs.next()) {
System.out.println("id:"+rs.getInt("id")); System.out.println("salary:"+rs.getString("salary"));
System.out.println("name1:"+rs.getString("name1")); } con.close(); } catch(SQLException e)
{} catch(Exception e) {} } }
490 W hat should be the correction done in the follow ing program to get correct output? import java.sql.*; 4 N A 2 missing semicolon
import java.io.*; class InsertDemo { public static void main(String args[]) { int c=0; try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String myURL="jdbc:odbc:college"; Connection
con=DriverManager.getConnection(myURL); Statement st=con.createStatement();
c=st.executeUpdate("insert into emp values(1,4000)") if(c!=0) System.out.println("Record inserted"); else
System.out.println("Record NOT inserted"); con.close(); }catch(Exception e){}
}}
491 W hat should be the correction done in the follow ing program to get correct output? import java.Sql.*; 4 N A 2 import java.SQL.*;
import java.io.*; class insertDemo { public static void main(String args[]) { int c=0; try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String myURL="jdbc:odbc:college"; Connection
con=DriverManager.getConnection(myURL); Statement st=con.createStatement();
c=st.executeUpdate("insert into emp values(1,4000)"); if(c!=0) System.out.println("Record inserted"); else
System.out.println("Record NOT inserted"); con.close(); }catch(Exception e){}
}}
492 W hat should be the correction done in the program to get correct output? class Ddemo1 { public static void m4 N A 2 Missing package state
W hat should be the correction done in the program to get correct output? import java.sql.*; class Ddemo1 {
493 c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," "); Statement s=c.createStatement(); ResultSet rs= 4 N A 2 Missing }
494 W hat should be the correction done in the program to get correct output? import java.sql.*; class TestData {4 N A 2 Error in connection st
495 W hat statement should be modified to get the output as show n in fig. import java.sql.*; class stud1 { 4 Y1 A 2 System.out.println(&q
public static void main(String ar[])throw s Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); "+res.getInt(2)+
Connection con=DriverManager.getConnection("jdbc:odbc:studdsn"); Statement System.out.println(&q
s1=con.createStatement(); ResultSet res; System.out.println("Before insertion"); "+res.getInt(2)+
res=s1.executeQuery("select * from student"); w hile(res.next()) {
System.out.println("Name\t"+res.getInt(1)+" Roll_NO\t"+res.getInt(2)+" per\t"+res.getInt(3));
} Statement st=con.createStatement(); st.executeUpdate("insert into student values('Joshi',10,75)");
System.out.println("inserted"); System.out.println("After insertion"); res=s1.executeQuery("select * from
student"); w hile(res.next()) { System.out.println("Name\t"+res.getString(1)+"
Roll_NO\t"+res.getInt(2)+" per\t"+res.getInt(3)); } } }
Figure:-
496 W hat the follow ing statement returns? SQLW arning w arning = statement.getW arnings(); System.out.print4 N U 2 Description about SQL
497 W hat w ill be display in output using the follow ing code. import java.sql.*; class Test { public static void ma4 N A 2 connection establishe
498 w hat w ill be output of given code //Load the database Driver Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"4 N A 2 record w ill be deleted
499 W hat w ill be output of this program import java.sql.*; public class JDBCExample { public static void main(S 4 N A 2 It w ill create a table
W hat w ill be the out of the follow ing code? import java.aw t.*; import java.io.*; public class
500 Demo { public static void main(String args[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System4 N U 2 Error
501 W hat w ill be the output for follow ing code? import java.sql.*; class SelectD { public static void main(String 4 N A 2 Display student’ roll n
greater than 70.
502 W hat w ill be the Output of follow ing code? import java.sql.*; public class SmtInterfaceDemo { public static 4 N U 2 Table is created w ith
503 W hat w ill be the output of follow ing code? import java.sql.*; public class JdbcGetConnection { 4 N A 2 Connection is closed :
public static void main(String args[]) { Connection con = null; Statement st = null; ResultSet rs
= null; try { Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/komal", "root", "root"); System.out.println("Connection is closed
: " + con.isClosed()); con.close(); System.out.println("Connection is closed : " +
con.isClosed()); } catch (Exception e) { System.out.println(e); } } }
504 W hat w ill be the output of follow ing program? import java.sql.*; class DBTest { public static void main(Stri 4 N A 2 Driver Loaded Connec
505 W hat w ill be the output of follow ing program? import java.sql.*; class conn1 { public static void main(Strin 4 N A 2 Driver are properly lo
506 W HAT W ILL BE THE OUTPUT OF THE BELOW PROGRAM: import java.sql.*; class ConnectionTest 4 N A 2 BOTH Option i and Op
{ public static void main(String args[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver loaded"); String url="jdbc:odbc:xyz"; Connection con =
DriverManager.getConnection(url); System.out.println("connection to database created"); }
catch(SQLException e) { System.out.println("SQL error"); } catch(Exception e) {
System.out.println("error"); } } }
507 W hat w ill be the result of executing the follow ing code snippet? Statement sql2 = 4 N A 2 W ill result in compila
con.createStatement(); int result=sql2.executeUpdate("Select * From Publishers");
508 W hat w ill happen if resultSet() is not present in JDBC? 4 N A 2 None of the above
509 W hat w ill happen if w e does not use the close() method? 4 N A 2 Connection w ill does not close
510 W hat w ill the follow ing statement display? select Student.* from Student, Course, Enrollment w here Stude4 N A 2 The statement display
starting w ith S.
512 W hen the message "No suitable drivers found" is displayed? 4 N U 2 if JDBC database URL passed is not c
513 W hen using ODBC, w hich of the follow ing processes ODBC requests and submits specific SQL 4 N A 2 Driver.
statements to a given type of data source?
515 W here to w rite query to delete records in the follow ing program import java.sql.*; public class DeleteRecord4 N A 2 As a parameter to Exe
516 W hich are the statements related to retrieving table names from a database? 4 N A 2 … Connection con = …
517 W hich class has traditionally been the backbone of the JDBC architecure ? 4 N U 2 A.the JDBC driver manager
521 w hich are the methods are used for Connection interface 4 N U 2 All of the above
523 W hich class w ill use to create the ps object in the given code? import java.sql.*; public class create { public 4 N A 2 PreparedStatement
524 W hich code is correct to generate the given output? Figure:- 4 Y1 A 2 a) PreparedStatement
Name='Ram'");
525 W hich code segment could execute the stored procedure "countRecs()" located in a database server? 4 N U 2 CallableStatement cs
527 W hich driver is efficient and alw ays preferable to use in JDBC applications? 4 N U 2 Type 4
528 W hich interface provides methods to execute queries w ith the database? 4 N U 2 Statement interface
529 w hich interfaces provide methods for batch processing in JDBC 4 N U 2 Both A & B
532 w hich is the correct discription of the close() method 4 N A 2 closes the curtrent stmt object
533 W hich is the correct method for updating table row s from given option. import java.sql.*; public class 4 N A 2 executeUpdate()
Updatedbase { public static void main(String args[]) { try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:data"); Statement st=con.createStatement(); ResultSet
rs=st.executeQuery("select * from emp"); St.********("Update emp set name1='jack' w here id=2");
System.out.println("\n\nafter change"); rs=st.executeQuery("select * from emp"); w hile(rs.next()) {
System.out.println("id:"+rs.getInt("id")); System.out.println("salary:"+rs.getString("salary"));
} con.close(); } catch(SQLException e){} catch(Exception e) { } } }
534 W hich is the correct option form the follow ing for JDBC driver types? 4 N U 2 1 JDBC-ODBC bridge
535 W hich JDBC driver maps the JDBC calls to the native method calls, w hich are passed to the local native Call 4 N U 2 Native-API-Partly-Jav
536 W hich JDBC driver Type(s) can be used in either applet or servlet code? 4 N A 2 Both Type 3 and Type 4
537 W hich JDBC driver Type(s) can you use in a three-tier architecture and if the W eb server and the DBMS are 4 N A 2 All of Type 1, Type 2,
538 W hich JDBC driver Type(s) is (are) the JDBC-ODBC bridge? 4 N U 2 Type-1
539 W hich JDBC driver Types are for use over communications netw orks? 4 N A 2 Both Type 3 and Type 4
540 W hich kind of driver converts JDBC calls into calls on the client API for Oracle, Sybase, Informix, IBM DB2, or4 N U 2 B. Native -API partly-
541 W hich list gives a quick w ay to determine w hich Connection method is appropriate for creating different typ4 N U 2 D.All of the mentione
542 W hich maintains a cursor pointing to a particular row of data,Initially, cursor points to before the first row ? 4 N U 2 ResultSet interface
543 W hich method executes an sql statement that may return multiple results. 4 N U 2 execute()
545 W hich method is missing of statement Interface to create table? import java.sql.*; public class createtable { 4 N A 2 execute()
546 W hich method returns the current result in multiple result statements? 4 N A 2 getUpdateCount()
547 W hich minimum package statements are missing? class conn { conn() { try { 4 N U 2 java.sql.*;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:samarth"); PreparedStatement
ps=con.prepareStatement("Select * from Book"); ResultSet rs=ps.executeQuery(); w hile(rs.next()) {
System.out.println("ID="+rs.getInt(1)); System.out.println("Name="+rs.getString(2));
System.out.println("Author="+rs.getString(3)); }
} catch(Exception e) { System.out.println(e); } } public static void main(String args[]) { new conn(); } }
550 W hich object provides you w ith methods to access data from the table? 4 N U 2 ResultSet
551 W hich of the follow ing statement is a prepared statements ? 4 N A 2 Insert into department values(?,?,?)
552 W hich of the follow ing are the methods of statement interface? 4 N A 2 Both A & B
553 W hich of the follow ing describes the correct sequence of the steps involved in making a connection w ith a d4 N A 2 1,3,4,2
554 W hich of the follow ing describes the correct url String format of getConnection() method. 4 N U 2 protocol,subprotocol,datasource na
555 W hich of the follow ing invokes stored procedures in sql? 4 N U 2 callable statements
556 W hich of the follow ing is correct sequence of steps regarding to establish the connection w ith database. 1. C4 N U 2 1,4,3,2
557 w hich of the follow ing is not true for Statement and PreparedStatment? 4 N U 2 None of above
558 W hich of the follow ing is the correct syntax of executeQuery() method? 4 N U 2 ResultSet executeQuery(String str)
559 W hich of the follow ing is true 4 N A 2 The tw o tiers are ofte
560 W hich of the follow ing is used to access the database server at time of executing the program and get the d 4 N U 2 Dynamic SQL
561 W hich of the follow ing method is supported by Statement interface? 4 N U 2 All of the mentioned
562 W hich of the follow ing method is used to open the connection w ith the database 4 N U 2 Connection con = DriverManager. ge
563 W hich of the follow ing piece of code show s how to retrieve the value of the Row Id for a particular Row ? 4 N U 2 String selectQuery =
564 W hich of the follow ing query is correct to fetch all thye records from database. Import java. Sql.*; class 4 N A 2 C. Stmt.executeQuery
MysqlCon{ public static void main (String args[]){ try { Class.forName ("com.mysql.jdbc. Driver");
Connection con = DriverManager. getConnection ("jdbc:mysql://localhost:3306/abc","root","root'');
Statement stmt = stmt = con. createStatement(); ResultSet rs =
______________________________________________________________ w hile (
rs.next()) System.out printIn(rs.getInt(1)+ " " + rs. getString (2) + "" + rs. getString(3));
con.close(); } catch (Exception e ) { System.out.println(e);} }}
565 W hich of the follow ing query is used for SELECT query? 4 N U 2 executeQuery(String sql)
566 W hich of the follow ing statement is false as far as different type of statements is concern in 4 N U 2 D)Interim Statement
JDBC.
567 W hich of the follow ing statement is false as Type 4 driver is concern: 4 N U 2 Type 4 drivers can not be used w ith
568 w hich of the follow ing statement is true in case security consideration for JDBC. A)normal unsigned applets 4 N A 2 all of the above
569 w hich of the follow ing statement is used to scroll databse forw ard and backw ard 4 N A 2 Statement si=con.createStatement(
570 W hich of the follow ing statement should be inserted to display contents of last record and w here that 4 N A 2 After line no 13 rs.las
statement should be inserted 1.import java.sql.*; 2.public class JDBCExample { 3. public static void
main(String[] args) { 4. Connection conn = null; 5. Statement stmt = null; 6.
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver"); 7. System.out.println("Connecting to database..."); 8.conn
= DriverManager.getConnection(jdbc:odbc:stud”);
9.System.out.println("Creating table in given database..."); 10.System.out.println("Creating statement...");
11. stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
12.String sql = "SELECT id, age FROM Registration"; 13. ResultSet rs = stmt.executeQuery(sql); 14. int id
= rs.getInt("id"); 15. int age = rs.getInt("age"); 16. System.out.print("ID: " + id); 17. System.out.print(",
Age: " + age); } 18. rs.close(); 19. System.out.println("Goodbye!");}}
571 W hich of the follow ing statements are true about Tw o tier client server model. a)it is simple in design b)clie4 N U 2 a and b
573 W hich of the follow ing statements is a true statement concerning the open database connectivity standard ( 4 N U 2 All of the above.
574 W hich of the follow ing statements is true concerning JDBC? 4 N U 2 It is similar concept to ODBC.
575 W hich of the follw ing method is used for sending SQL statements 4 N U 2 Statement
576 W hich of the missing code need to be inserted in a given code to delete second row in ResultSet. import 4 N A 2 rs.absolute(2); rs.dele
java.sql.*; import java.sql.ResultSet.*; class delrset {public static void main(String args[]) {try
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con
=DriverManager.getConnection("jdbc:odbc:stud"); Statement s =
con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); ResultSet
rs=s.executeQuery("select * from stud"); w hile(rs.next()) System.out.println(rs.getInt(1)+"
"+rs.getString(2)+" "+rs.getInt(3)); System.out.println("After deleting row :"); rs.first();
System.out.println(rs.getInt(1)+" "+rs.getString(2)+"
"+rs.getInt(3)); w hile(rs.next()) {System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3)); }
con.close(); } catch(Exception e){ } } }
577 W hich ONE of the follow ing is missing statement in the program below ? import java.sql.*; class 4 N A 2 results.next()
ExecuteQueryTest { public static void main(String args[]) { try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Driver loaded"); String
url="jdbc:odbc:aditya"; Connection con = DriverManager.getConnection(url);
System.out.println("connection to database created"); Statement st = con.createStatement();
System.out.println("Statement object created"); String sql="select Name,Age from tanni"; ResultSet
results = state.executeQuery(sql); String text=" "; w hile() { text
+=results.getString(1)+ "" +results .getInt (2)+ '\n'; } System.out.println(text); } catch(SQLException e)
{ System.out.println("SQL error"); } catch(Exception e) { System.out.println("error"); } } }
578 W hich one of the follow ing methods is used to execute INSERT, UPDATE, and DELETE 4 N U 2 executeUpdate()
statements in a Java application?
579 W hich statement create an error import java.sql.*; class data { public static void main(String a[]) throw s 4 N A 2 w hile creating Driver
Exception { Driver d= new Driver(); DriverManager.registerDriver(d); Connection con
=DriverManager.getConnection("Jdbc:Odbc:XXX"); Statement s=con.createStatement(); }
}
580 W hich statement is correct after firing delete statement of SQL? import java.sql.*; class DeleteD { public 4 N A 2 stmt.executeUpdate(q
static void main(String a[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded"); String url="jdbc:odbc:if"; Connection
con=DriverManager.getConnection(url); System.out.println(" Connection to DataBase created"); Statement
stmt = con.createStatement(); String querySel
= "Select * from student"; ResultSet rs = stmt.executeQuery(querySel); System.out.println("Before
Delete"); w hile(rs.next()) { System.out.println(" Roll number : "+ rs.getInt(1)); System.out.println("
Student Name : "+ rs.getString(2)); System.out.println(" Student Marks : "+ rs.getInt(3));
System.out.println(); } String querydel = "delete from student w here stud_name='Sanjay'";
__________________________________________ rs
= stmt.executeQuery(querySel); System.out.println("After Delete"); w hile(rs.next()) {
System.out.println(" Roll no : "+ rs.getInt(1)); System.out.println(" Student Name : "+ rs.getString(2));
System.out.println(" Student marks : "+ rs.getInt(3)); System.out.println(); }
} catch(SQLException e) { e.printStackTrace(); } catch(Exception e) { e.printStackTrace(); } }
}
581 W hich statement is correct in case of Type 1 JDBC driver a) Type I driver is slow driver. b)Type I Driver is no4 N U 2 all of above
582 W hich Statement is given the error in the follow ing code import java.sql.*; class dataI { public static void 4 N A 2 Sql Query Statement
main(String a[]) { try { Driver d= new sun.jdbc.odbc.JdbcOdbcDriver(); DriverManager.registerDriver(d);
Connection con
=DriverManager.getConnection("Jdbc:Odbc:xxx"); Statement s=con.createStatement();
s.executeUpdate("Insert into Table1 values('hhh',12)"); if(n==1) { System.out.println("Record inserted ");
con.close(); } } catch(Exception e) { System.out.println("not Inserted"+e); } } }
585 W hich statement required for getting proper output import java.sql.*; public class updatevalues1 { public sta4 N A 2 ps.executeUpdate()
586 W hich statement should be correct for displaying the correct out put? import javax.sw ing.*; 4 N A 2 Import Package and c
import java.io.*; class dataM { public static void main(String a[]) { String type[]=
{“TABLE”,”View ”}; try { Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); Connection con
=DriverManager.getConnection("Jdbc:Odbc:xxx"); Statement s=con.createStatement(); DatabaseMetaData
md=rs.getMetaData(); System.out.println("Database is:”+md.getDatabaseProductName() );
System.out.println("SQL Keyw ords is:”+md.getSQLKeyw ords()); ResultSet
rs=md.getTables(null,null,null,types); W hile(rs.next()) { String to=rs.getString(2); String
tn=rs.getString(3); String tt=rs.getString(4); System.out.println(to+” ”+tn+” ” +tt+” ”); } con.close(); }
catch() { System.out.println(e); } }
}
587 W hich statements about JDBC are true? 4 N A 2 JDBC stands for Java DataBase Conn
589 W hich statements are required in follow ing program to insert one record in table import java.sql.*; public 4 N A 2 String sql = "IN
class JDBCExample { public static void main(String[] args) { Connection conn 18)"; stmt.exec
= null; Statement stmt = null; Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Connecting to database..."); conn = DriverManager.getConnection(jdbc:odbc:stud”);
System.out.println("Inserting records into the table..."); stmt = conn.createStatement();
______________________________________________________
__________________________________________________________________
System.out.println("Inserted records into the table..."); System.out.println("Goodbye!"); }}
590 W hich statements are used to display the contents of table? import java.sql.*; public class jdbcResultSet { p 4 N A 2 getString,getInt meth
591 W hich statements are w rong in bellow program import java.sql.*; class stud5 { public static void main(Strin4 N A 2 Class.forName("
con=DriverManager.g
592 W hich type of driver converts JDBC calls into the netw ork protocol used by the database management syste 4 N U 2 Type 4 driver
594 w hile(rs.next()) { String n=rs.getString("name"); System.out.println("name:"+n); String n1=rs.getString("r 4 N A 2 D. none of the above
595 W rite a java code to access id, age, first from table given below Employees : l id l first l last l age l 4 N A 2 A. sql = "SELEC
596 W rite the missing statement? import java.sql.*; class Rsmd{ public static void main(String args[]){ try{ 4 N A 2 ResultSetMetaData rs
Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","oracle"); PreparedStatement
ps=con.prepareStatement("select * from emp"); ResultSet rs=ps.executeQuery(); ----------------------------
----------------------- System.out.println("Total columns: "+rsmd.getColumnCount());
System.out.println("Column Name of 1st column: "+rsmd.getColumnName(1));
System.out.println("Column Type Name of 1st column: "+rsmd.getColumnTypeName(1)); con.close();
}catch(Exception e){ System.out.println(e);} }
}
597 W rite the missing statements? import java.sql.*; class InsertPrepared{ public static void main(String args[])4 N A 2 con.close();
598 W rite w hich method is used for follow ing program execution in blank space: import java.sql.*; class exp11_4 N A 2 executeQuery()
599 ____type of driver is very flexible and need not code installation on the client machine 4 N U 2 Type 3-JDBC-Net Pure java
600 ______moves the cursor to the specified row 4 N A 2 public boolean absolute(int row )
601 ________ is an open source DBMS product that runs on UNIX, Linux and W indow s. 4 N U 2 MySQL
603 ___________Calls get converted into native c or c++ API calls 4 N A 2 JDBC API
605 ________________ method of Connection interface is used to create the Statement object. 4 N U 2 createStatement()
606 ________________ method of DriverManager is used to establish connection w ith the database. 4 N U 2 getConnection()
607 ____________________ Returns the current row number, w ith the first row starting at 1 4 N U 2 getRow ()
609 …………………… can not directly communicate w ith database to submit data & retrive the result. 4 N U 2 JDBC
610 W hich of the follow ing statements loads the JDBC-ODBC driver? 4 N U 2 Class.forName("sun.jdbc.odbc.
30 During Initialization of Servlet, a servlet instance can throw ________. 5 N R 1 Both i) and ii)
33 Follow ing method is not valid life cycle method of JSP 5 N R 1 jspStop()
37 getSession() method w ith true as parameter it w ill return the appropriate session object 5 N R 1 session is existing
39 Give the examples of Application Server from the follow ing? 5 N R 1 All of the above
40 How can w e get context init parameter and run some code before rest of the application c5 N R 1 ServletContextListener
48 Identify correct syntax of service() method of servlet class 5 N R 1 void service(ServletRequest req, ServletResponse res)
49 If an expiration date is not explicitly assigred to a cookie __________ 5 N R 1 it is deleted w hen the current brow ser session ends
50 If you w ant to track active session or how many users are there? 5 N R 1 HttpSessionListener
w hich listener you should use.
51 in a w eb application, running in a w ebserver, w ho is responsible for 5 N R 1 Servlet
creating request and response object
53 In HTTP Request W hich Asks for the loopback of the request message, for testing or troub5 N R 1 TRACE
54 In JSP a Canvas object provides access to a Graphics object via one of its methd called___5 N R 1 paint()
59 In w hich phase of JSP life cycle ,JSP page turns into servlet? 5 N R 1 JSP Compilation
60 init() ,service(),destroy() methods are defined in ____________ 5 N R 1 javax.servlet.Servlet interface
61 Java servlets are an efficient and pow erful solution for creating ………….. for the w eb. 5 N R 1 Dynamic content
62 javax.servlet package does not contain follow ing class or interface. 5 N R 1 HttpServlet
65 JSP containers are required to support ..................... different formats of JSP syntax 5 N R 1 Tw o
68 JSP includes a mechanism for defining ............................... or custom tags 5 N R 1 dynamic attributes
69 JSP is not governed by the syntax and semantics defined by the 5 N R 1 Java 2
................... specifications.
74 Life cycle of a JSP page consist of follow ing steps. 5 N R 1 Translation,compilation,Loading and initialization,Request H
76 Name a class that includes the getSession() method that is used to get the HttpSession 5 N R 1 HttpServletRequest
77 Name the class that can be used to get the cookies from the client brow ser 5 N R 1 HttpServletRequest
78 Name the http method that sends the same response as the request. 5 N R 1 TRACE method
79 Name the http method used to send resources to the server 5 N R 1 PUT method
Name the interface w hich is used to get initialization parameters for
80 5 N R 1 ServletConfig
Servlet
81 Name the location of compiled class files w ithin a jar file? 5 N R 1 /W EB-INF/classes
82 Name the method defined in the HttpServletResponse class that may 5 N R 1 setContentType
be used to set the content type.
83 On typing a URL on the address bar, w hich HTTP request gets generated? Select the one c5 N R 1 GET method
85 Servlet are w ebpages generated by the w eb server In response to the requests send by t5 N R 1 client
State true or false for the follow ing statements in Java. i) Java beans
88 slow dow n softw are development process. ii) Java Servlets do not 5 N R 1 i-false, ii-false
have built in multithreading feature.
89 The doGet() Extracts values of the parameter type and number by using ___________ 5 N R 1 request.getParameter()
90 The GET and POST methods are specified in _________. 5 N R 1 an HTML form
91 The getSession() method w ith its parameter [getSession(true)]. It w ill return the approp 5 N R 1 the session is existing
96 The javax.servlet.jsp package has tw o interfaces find in the follow ing? 5 N R 1 JspPage & HttpJspPage
99 The major difference betw een servlet and CGI is 5 N R 1 Servlets are thread based and CGI is process based
100 The maximum size of data can be sent by doGet() of HTTP request is 5 N R 1 240 bytes
101 The parameters can be passed to an applet by using <PARAM> tag in 5 N R 1 <PARAMNAME=parameter_name VAL
the follow ing w ay:
105 5 N R 1 init
not called again as long as the servlet is not destroyed.
110 To compile a Java servlet program, the ___________ file must be in the classpath. 5 N R 1 TomcatRootDir\common\lib\servlet.jar
114 W hat are the correct statements about filter? 5 N R 1 All of these
115 W hat are the true sentences about Session-Id? 5 N R 1 All of these
118 W hat is invoked via HTTP on the W eb server computer w hen it 5 N R 1 Java Servlet
responds to requests from a user's W eb brow ser?
120 W hat is servlet? 5 N R 1 Servlets are small program used for developing and executi
124 W hat programming language(s) or scripting language(s) does Java 5 N R 1 Java only
Server Pages (JSP) support?
125 W hat servlet processor w as developed by Apache Foundation and 5 N R 1 Apache Tomcat
Sun?
126 W hat value does readLine() returns w hen it has reached the end of a file in JSP? 5 N R 1 Null
130 W hich among the below is the class of javax.servlet package 5 N R 1 GenericServlet
131 W hich are true about tag libraries in w eb applications? 5 N R 1 all of the above
133 W hich cookie it is valid for single session only; it is removed each time 5 N R 1 Non-persistent cookie
w hen user closes the brow ser?
134 W hich HTTP method gets invoked w hen a user clicks on a link? Select 5 N R 1 GET method
the one correct answ er
135 W hich http method send by brow ser that asks the server to get the page only? 5 N R 1 get
140 W hich is not the method in servlet to handle http request 5 N R 1 doShow ()
141 W hich JSP tag is used to transfer processing to another JSP page ? 5 N R 1 <jsp:forw ard>
142 W hich life cycle method is used to process a client's request? 5 N R 1 service()
143 W hich method are central to life cycle of a servlet? 5 N R 1 init(), service() and destroy()
144 W hich method decides w hether doGet() or doPost() method to call? 5 N R 1 service
147 W hich method is used in the servlet class, to retrieve the input values from HTML page? 5 N R 1 request.getParameter()
150 W hich method is used to specify before any lines that use the 5 N R 1 setContentType()
PrintW riter?
153 W hich method of the component class is used to set the position and size of a component5 N R 1 setBounds()
154 W hich methods are available in ServleContext interface? 5 N R 1 getAttribute(),getMimeType(String File),void Log(String s)
155 W hich metod allow s the client to send data of unlimited length to the 5 N R 1 doPost()
w eb pageserver a single time.
156 w hich of follow ing is not true for servlet? 5 N R 1 it is single threaded
158 W hich of the follow ing are examples of JSP directive. 5 N R 1 include
W hich of the follow ing are interface? 1.ServletContext 2.Servlet
159 5 N R 1 1,2
3.GenericServlet 4.HttpServlet
160 W hich of the follow ing are the session tracking techniques? 5 N R 1 URL rew riting, using session object, using cookies, using hi
161 W hich of the follow ing correctly represents the follow ing JSP 5 N R 1 <jsp:expression>x</jsp:express
statement. <%=x%>
162 W hich of the follow ing implicit objects is not available to a JSP page by 5 N R 1 context
default?
163 W hich of the follow ing is an approach for state maintenance in W eb 5 N R 1 All of the above.
applications?
164 W hich of the follow ing is legal JSP syntax to print the value of i. Select the one correct an5 N R 1 <%int i = 1;%>
166 W hich of the follow ing is used to redirect the response from a servlet 5 N R 1 response.sendRedirect()
to a JSP page?
167 W hich of the follow ing JSP variables are not available w ithin a JSP 5 N R 1 httpsession
expression. Select the one correct answ er.
168 W hich of the follow ing method does not exist in HttpServelet class? 5 N R 1 init
169 W hich of the follow ing method is used to destroy the session? 5 N R 1 destroy( )
W hich of the follow ing methods are main methods in life cycle of
170 servlet? 1.init() 2 .service() 3.destroy() 4.w ait() 5 N R 1 1,2 and 3
171 W hich of the follow ing packages are required to create servlets in 5 N R 1 javax.servlet, javax.servlet.http
java?
172 W hich of these is a protocol for breaking and sending packets to an address across a netw5 N R 1 TCIP/IP
174 W hich of these method can be called multiple times in servlet's life 5 N R 1 service()
cycle?
175 W hich of these protocol uses service() method to process the request in servlet? 5 N R 1 HTTP
176 W hich packages represent interfaces and classes for servlet API? 5 N R 1 both a and b
177 W hich servlet processor w as developed by Apache Foundation and sun? 5 N R 1 Apache Tomcat
182 _____ Method returns true if the server created the session and it has not yet been access5 N R 1 isNew ()
183 ______is a small piece of Information that is passed back & forth in 5 N R 1 Cookie
HTTP request & response
188 ______________ class provides functionality that makes it easy to handle requests and re5 N R 1 GenericServlet
189 ______________Defines page-dependent attributes, such as scripting language, error pag5 N R 1 <%@ page ... %>
193 PrintW riter out = res.getW riter(); out.println("<HTML>"); out.println(" 5 N A 2 HttpServletRequest req & HttpServletResponse res
Choose the correct code that displays the output as show n in the figure
Figure:-
Choose the missing statement in the given method syntax public void
doGet(HttpServletRequest request, HttpServletResponse response) 5 N A 2 IOException
throw s ____________
Choose the missing statements in follow ing code from given options. import java.io.*; im
consider below program and print message " hi h r u" . select proper
262 Consider follow ing code. W hat should be correction done in program to get correct 5 N A 2 Error in if statement
output . import java.io.*; import javax.servlet.http.*; import javax.servlet.*; public
class SessionId extends HttpServlet { public
void doGet(HttpServletRequest req, HttpServletResponse res) throw s IOException,
ServletException { res.setContentType("text/html"); PrintW riter pw = res.getW riter();
if(s != null) { pw .println("Your session Id is : "); String sId = s.getId(); pw
.println(sId); } else { pw .println("Your session is not created yet"); } } }
263 Consider follow ing code.Fill _____________statement in follow ing code from option 5 N A 2 request.getParameter("cookieNa
given below import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public
class CookieExample extends HttpServlet { public void doGet(HttpServletRequest
request, HttpServletResponse response) throw s IOException, ServletException
{ response.setContentType("text/html"); PrintW riter out = response.getW riter();
Cookie[] cookies = request.getCookies(); for (int i = 0; i < cookies.length; i++) {
Cookie c = cookies[i]; String name = c.getName(); String value = c.getValue();
out.println(name + " = " +
value); } String name = ______________________ if (name != null && name.length()
> 0) { String value = request.getParameter("cookieValue"); Cookie c = new
Cookie(name, value); response.addCookie(c); } } }
264 Consider follow ing code.find syntax error in code import java.io.*; import java.util.*; 5 N A 2 error in the if statement
import javax.servlet.*; import javax.servlet.http.*; public class SessionExample extends
HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse
response) throw s IOException, ServletException {
response.setContentType("text/html"); PrintW riter out = response.getW riter();
HttpSession session = request.getSession(true); Date created = new
Date(session.getCreationTime()); Date accessed = new
Date(session.getLastAccessedTime()); out.println("ID " + session.getId());
out.println("Created: " + created); out.println("Last Accessed: " + accessed); String
dataName = request.getParameter("dataName"); if (dataName != null &&
dataName.length() > 0) String dataValue = request.getParameter("dataValue");
session.setAttribute(dataName, dataValue); } Enumeration e =
session.getAttributeNames(); w hile
(e.hasMoreElements()) { String name = (String)e.nextElement(); String value =
session.getAttribute(name).toString(); out.println(name + " = "
+ value); } } }
Consider follow ing code.Select proper html code to get correct output. import java.io.*; im <html> <body> <form ac
Consider the follow ing code and find w hich statement has error. <%@ taglib
uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> <%@ taglib
uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html>
<head><title>Using the JSTL functions</title></head> <body>
<h2>Using JSTL functions</h2> <c:set var="string" value="W elcome!
to the site of roseindia.net"/> The length of the String:
268 ${fn:lengthOf(string)}<br> Does the String contain "W elcome"? 5 N A 2 Both A and B
${fn:contains(string,"W elcome")} <br> Converting the String into
upper case using fn:toUpperCase(): ${fn:toUpperCase(string)}<br>
Converting the String into low er case using fn:toLow erCase():
${fn:toLow erCase(string)}<br> Making the substring of
"roseindia.net" : ${fn:substrings("roseindia.net", 0,9)} </body>
</html>
Consider the follow ing code. Select the missing statement in the given
code. import java.io.*; import javax.servlet.http.*; public class
CookieExample extends HttpServlet { public void doGet(
HttpServletRequest request, HttpServletResponse response) throw s
IOException, ServletException {
response.setContentType("text/html"); PrintW riter out =
= cookies[i]; String name = c.getName(); String value = c.getValue(); out.println(name +
270 Consider the follow ing code.Find missing satement import java.io.*; import 5 N A 2 doGet(request, response);
javax.servlet.*; import javax.servlet.http.*; public class RequestInfo extends
HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse
response) throw s IOException, ServletException {
response.setContentType("text/html"); PrintW riter out = response.getW riter();
out.println("<html>"); out.println("<body>"); out.println("<head>");
out.println("<title>Request Information Example</title>"); out.println("</head>");
out.println("<body>"); out.println("<h3>Request Information Example</h3>");
out.println("Method: " + request.getMethod()); out.println("Request URI: " +
request.getRequestURI()); out.println("Protocol: " + request.getProtocol());
out.println("PathInfo: " + request.getPathInfo()); out.println("Remote Address: " +
request.getRemoteAddr()); out.println("</body>"); out.println("
</html>"); } public void doPost(HttpServletRequest request, HttpServletResponse
response) throw s IOException, ServletException
{ doGet(request, response); } }
271 Consider the follow ing code.Find missing statement public class HelloForm extends 5 N A 2 import java.io.*; import javax.servlet.
HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse
response) throw s ServletException, IOException { Cookie firstName = new
Cookie("first_name", request.getParameter("first_name")); Cookie lastName = new
Cookie("last_name", request.getParameter("last_name"));
firstName.setMaxAge(60*60*24); lastName.setMaxAge(60*60*24);
response.addCookie( firstName ); response.addCookie( lastName );
response.setContentType("text/html"); PrintW riter out = response.getW riter(); String
title = "Setting Cookies Example"; String docType = "<!doctype html public \"-//w
3c//dtd html 4.0 " + "transitional//en\">\n"; out.println(docType + "<html>\n" +
"<head>
<title>" + title + "</title></head>\n" + "<body bgcolor=\"#f0f0f0\">\n" + "<h1
align=\"center\">" + title + "</h1>\n"
+ "<ul>\n" + " <li><b>First Name</b>: " + request.getParameter("first_name") +
"\n" + " <li><b>Last Name</b>: " + request.getParameter("last_name") + "\n" +
"</ul>\n"
+ "</body></html>"); } }
272 Consider the follow ing code.Select the missing statement to get proper output. import 5 N A 2 res.addCookie(c);
java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class CookEx
extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse
res)throw s IOException,ServletException { res.setContentType("text/html"); PrintW
riter out=res.getW riter(); String name=req.getParameter("name"); String
value=req.getParameter("age"); Cookie c=new Cookie(name,value); String
p1=c.getName(); String p2=c.getValue(); out.println("Name:"
+p1); out.println("Age:"+p2); out.println(" "); } }
Consider the follow ing code.W hat should be added to the program to get correct output..
275 Consider the follow ing program Select the statement that should be added to the program5 N A 2 responce.addCookie(cookie);
276 Consider the follow ing program Select the statement that should be added to the program5 N A 2 response.addCookie(c2);
out.println("</HTML>"); }
277 Consider the follow ing program and identify the class at bank space import java.io.*; imp5 N A 2 HttpServlet
278 Consider the follow ing program and identify the error statement. import java.io.*; import 5 N A 2 String e[]=request.getParameterName
279 Consider the follow ing program and identify the missing method attribute ***** if you 5 N A 2 post
w ant to implement HTTP POST. <html> <body>
<center> <form name="Form1" method=*****
action="http://localhost:8080/examples/servlet/ColorPostServlet">
<B>Color:</B> <select name="color" size="1"> <option value="Red">Red</option>
<option value="Green">Green</option>FTW ARE DEVELOPMENT USING JAVA
<option value="Blue">Blue</option> </select> <br><br> <input type=submit
value="Submit"> </form> </body> </html>
280 Consider the follow ing program and identify the missing method name 5 N A 2 doGet()
****** if you w ant to implement HTTP GET. import java.io.*; import javax.servlet.*;
import javax.servlet.http.*; public class ColorGetServlet extends HttpServlet { public
void ****** (HttpServletRequest request, HttpServletResponse response) throw s
ServletException, IOException { String color =
request.getParameter("color"); response.setContentType("text/html"); PrintW riter pw =
response.getW riter(); pw .println("<B>The selected color is: "); pw .println(color); pw
.close(); } }
281 Consider the follow ing program and identify the missing statement. class URLDemo { 5 N A 2 Missing package statement
public static void main(String args[]) throw s MalformedURLException { URL
netAddress= new URL("http://w w w .sun.com:/index.html");
System.out.println("Protocol
:"+netAddress.getProtocol()); System.out.println("Port
:"+netAddress.getPort()); System.out.println("Host
:"+netAddress.getHost()); System.out.println("File
:"+netAddress.getFile()); } }
282 Consider the follow ing program and identify the missing statement. import java.io.*; imp 5 N A 2 PrintW riter pw ;
Consider the follow ing program and identify the missing statement. public class Hellot ex
Consider the follow ing program and identify the missing statement.
288 name="mybean" property="*" /> <html> <head><title>Hello, User</title></head> 5 N A 2 Closing Table tag is missing
<body bgcolor="#ffffff" background="background.gif"> <%@ include
file="dukebanner.html"
%> <table border="0" w idth="700"> <tr> <td w idth="150"> </td>
<td w idth="550"> <h1>My name is Duke. W hat’s yours?</h1> </td>
</tr> <tr> <td w idth="150" </td> <td w idth="550"> <form method="get"> <input
type="text" name="username" size="25">
<br> <input type="submit" value="Submit"> <input type="reset" value="Reset">
</td> </tr> </form> <% if ( request.getParameter("username") != null ) { %> <%@
include file="response.jsp" %> <% } %> </body> </html>
289 Consider the follow ing program. W hat should be the correction done in the program to 5 N A 2 Missing }
get correct output? import java.io.*; import java.util.*; import javax.servlet.*; import
javax.servlet.http.*; public class DateServlet extends HttpServlet { public void
doGet(HttpServletRequest request,HttpServletResponse response) throw s
ServletException ,IOException { HttpSession hs=request.getSession(true);
response.setContentType("text/html"); PrintW riter pw =response.getW riter(); pw
.print("<B>"; Date date= (Date)hs.getAttribute("date"); if(date!=null) { pw .print("Last
access: "
+ date +"<br>"); } date=new Date(); hs.setAttribute("date", date);
pw .println("Current date:" + date); }
290 Consider the follow ing program. Identify the exception that might be throw n import java 5 N A 2 MalformedURLException
291 Consider the follow ing program. Identify the exception that might be throw n import java 5 N A 2 ServletException,IOException
292 Consider the follow ing program. Identify w hich statement contains error. import javax.se5 N A 2 Error in getParameter() method return
Consider the follow ing program. Fill the missing(*******) statement. import java.io.*; im
294 Consider the follow ing program. Identify the missing statement import java.io.*; import j5 N A 2 import javax.servlet.http.*;
295 Consider the follow ing program. Identify the missing statement from the output. import ja5 N A 2 Port: -1
296 Consider the follow ing program. Identify the missing statement in the program. import 5 N A 2 response.getW riter();
java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class Exp extends
HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse
response) throw s ServletException, IOException {
response.setContentType("text/html;charset=UTF-8"); PrintW riter out
= ___________________ out.println("the server name:
"+request.getServerName()+"<br>"); out.println("the server port:
"+request.getServerPort()+"<br>"); out.println("the server protocol:
"+request.getProtocol()+"<br>"); out.println("the server scheme:
"+request.getScheme()+"<br>"); out.close(); } }
297 Consider the follow ing program. Identify the missing statement to get correct output. imp5 N A 2 response.addCookie(cookie);
298 Consider the follow ing program. Identify the missing w ord ****. 5 N A 2 localhost:8080
<html> <body> <center> <form name="Form1"
action="http://****/examples/servlet/ColorGetServlet"> <B>Color:
</B> <select name="color" size="1"> <option value="Red">Red</option> <option
value="Green">Green</option>
314 Fill in the missing statements import javax.servlet.*; import javax.servlet.http.*; import 5 N A 2 new Cookie("MyCookie", da
java.io.*; public class AddCookieServlet extends HttpServlet { public void
doPost(HttpServletRequest request, HttpServletResponse response) throw
sServletException, IOException { String data = request.getParameter("data"); Cookie
cookie = -----------
------------------- response.addCookie(cookie); response.setContentType("----------------
--l"); PrintW riter pw = response.getW riter(); pw .println("<B>MyCookie has been set
to"); pw .println(data); pw .close(); } }
315 Find correct output of follow ing code HTML FILE <html> <body> <form 5 N A 2 Firstly input username & passw o
action=”pass1”> name:<input type=”text” name=”t1”> passw ord: page"
<input type = “passw ord” name=”t2”> <input type=”submit” value=”login”> </form>
</body> </html> // Servlet file import java.io.*; import javax.servlet.*; public class
pass1 extends GenericServlet { public void service(ServletRequest req,ServletResponse
res)throw s ServletException, IOException { res.setContentType(“text/html”); PrintW
riter pw = res.getW riter();
String un=”abc”; String pw d=”xyz”; String p1=req.getParameter(“t1”); String
p2=req.getParameter(“t2”); if((p1.equals(un)) && (p2.equals(pw d))) { pw
.println(“<h1>w elcome to home page</h>”);
}else{ pw .println(“invalid”); } pw .close(); } }
316 Find error in follow ing code from given options. import java.io.*; import javax.servlet.*; i5 N A 2 Error in doPost() method
317 Find errors in follow ing code. import java.io.*; import javax.servlet.*; public class MyServ5 N A 2 Error in service() method declaration
318 Find out error in the follow ing program import javax.servlet.*; import javax.servlet.http.*5 N A 2 statement w here http servlet class is
319 Find out the error in the follow ing code. import java.io.*; import javax.servlet.*; public cl5 N A 2 Mismatch servlet
Find out the missing statement <html> <head> <title>Reading Cookies</title> </head>
null; // Get an array of Cookies associated w ith this domain if( cookies
320 != null ){ out.println("<h2> Found Cookies Name and Value</h2>"); 5 N A 2 cookies = request.getCookies();
for (int i = 0; i < cookies.length; i++){ cookie = cookies[i];
out.print("Name : " + cookie.getName( ) + ", "); out.print("Value: " + cookie.getValue(
)+" <br/>"); } }else{ out.println("<h2>No cookies founds</h2>"); } %> </body>
</html>
Find out the missing statement in follow ing program import java.io.*; import javax.servle
Find out the missing statement to get the correct output in bellow program import java.io.
Find the w rong statement in given program: import java.io.*; import javax.servlet.*; imp
Figure:-
334 For given figure w hich method of ReuestDispatcher is applicable 5 Y1 U 2 forw ard
(S1Q41) Figure:-
335 For the below html code: <input type="text" name="username”> The servlet code to retr 5 N U 2 String str=req.getParameter("us
HttpServletRequest object
336 For the follow ing code identify the correct syntax of service () method of servlet class. 5 N A 2 void service(ServletRequest req,Servle
import java.io.*; import javax.servlet.*; public class HelloServlet extends
GenericServlet { public void service(___________________)throw s ServletException,
IOException
{ response.setContentType("text/html"); PrintW riter pw =
response.getW riter(); pw .println("<B>Hello"); pw .close(); } }
337 For the follow ing code select the missing statement that can be used . import java.io.*; im
5 N A 2 String name=request.getParameter(&q
338 For the follow ing output, w hat is the html <form> tag code? Figure:- 5 Y1 A 2 <FORM METHOD="GET"
339 Generic servlet implements the _________&_______ interface. 5 N U 2 Servlet & servlet config
341 getSession(true) method w ill return appropriate session object if…… 5 N U 2 the session is existing
343 ShoppingCart/customer/ show Cart.jsp w hich of the follow ing code are 5 N A 2 request.getRequestDispatcher("/s
response: 41. HttpSession session = null; 42. / / insert code here 43. if
344 (session = = null) { 44. / / do something if session does not exist 45. } 5 N U 2 session = request.getSession (false);
else { 46. / / do something if session exists 47. } To implement the
design intent, w hich statement must be inserted at line 42?
Given an HttpServletRequest request and HttpServletResponse
345 response, w hich sets a cookie "username" w ith the value "joe" in a 5 N U 2 response.addCookie(new Cookie("username", &q
servlet?
348 Given: <%-- insert code here --%> <html> <body> Today is: <%= new 5 N A 2 <%@ page import='java.util.Date' %
Date() %> </body> </html> W hat needs to go on line 1?
Given: 1. public void service(ServletRequest request, 2.
349 ServletResponse response) { 3. ServletInputStream sis = 4. // insert 5 N A 2 request.getInputStream();
code here 5. } W hich retrieves the binary input stream on line 4 ?
How is the form data stored as a cookie on client machine? Pick out the
353 only in W indow s Operating System iv) allow s developers to customize 5 N U 2 i, ii & iv are true
356 Identify correct syntax of doPost() method used in servlets. 5 N U 2 void doPost(HttpServletRequest req,HttpServletResponse re
357 Identify correct syntax of service() method of servlet class 5 N U 2 void service(ServletRequest req, ServletResponse res)
360 Identify the correct sequence in Lifecycle of JSP 5 N U 2 Compile, Initialize, Execute, Destroy
java and html file for servlet A) Create a directory structure under
361 5 N U 2 ABCDEF
import the B)Javax.servlet package and the javax.servlet.http package
in your source file. C)Compile your source code. D)Create a deployment
descriptor. E)Run Tomcat. F)Call your servlet from a w eb brow ser.
362 identify the correct signature of setContextLenght() method of 5 N U 2 void setContextLength(int size)
ServletResponse interface.
363 If you w ant to override a JSP file's initialization method, w ithin w hat 5 N A 2 <%!%>
type of tags must you declare the method?
364 If your servlet class file does not have a package statement, the 5 N A 2 TomcatRootDir\w ebapps\examples\W E
servlet .class file must be placed in ________ by default.
365 PrintW riter pw = response.getW riter(); pw .print("<B>"); Date date = 5 N A 2 Both A and B
368 In follow ing Java program fill statement show ing *** . Select any one option from given 5 N A 2 request.getSession(true);
369 In follow ing Java program fill statement show ing ******.Select any one option from give5 N A 2 request.getParameterNames();
370 In follow ing Java program fill statement show ing ***.Select any one option fro given opt5 N A 2 GenericServlet
371 In follow ing Java program fill statement show ing ***.Select any one option fro given 5 N A 2 HttpServlet
options import javax.servlet.*; import javax.servlet.http.*; public class
AddCookieServlet extends *********
{ public void doPost(HttpServletRequest request, HttpServletResponse response) throw
sServletException, IOException { String data = request.getParameter("data"); Cookie
cookie = new Cookie("MyCookie", data); response.addCookie(cookie);
response.setContentType("text/html"); PrintW riter pw = response.getW riter(); pw
.println("<B>MyCookie has been set to"); pw .println(data); pw .close(); } }
372 In follow ing Java program fill statement show ing ***.Select any one option fro given 5 N A 2 addCookie(cookie);
options import javax.servlet.*; import javax.servlet.http.*; public class
AddCookieServlet extends HttpServlet
{ public void doPost(HttpServletRequest request, HttpServletResponse response) throw
sServletException, IOException { String data = request.getParameter("data"); Cookie
cookie = new Cookie("My Cookie",data); response.*********;
response.setContentType("text/html"); PrintW riter pw = response.getW riter(); pw
.println("<B>MyCookie has been set to"); pw .println(data); pw .close(); } }
379 In follow ing Java program fill statement show ing __________. import java.io.*; import 5 N A 2 service
javax.servlet.*; public class HelloServlet extends GenericServlet { public void
__________(ServletRequest request,ServletResponse response) throw s
ServletException, IOException { response.setContentType("text/html"); PrintW riter out
= response.getW riter(); out.println("<h1> W elcome to Servlet</h1>"); }
}
380 In follow ing Java program w hich package is used public class HellosServlet extends 5 N A 2 import java.io.*; import javax.servlet.
HttpSevlet { public void doPost(HttptReuest request,httpResponse response) trow s
ServletException,IOException { string color=request.getParameter("color")
responce.setConteType("text/html"); PrintW riter pw =responce.getW riter(); pw
.println("<B>The selected color is:"); pw .println(color); pw .close(); } } <html>
<body> <form name="Form1" method="post"
action:""http://localhost:8080/examples/servlet/HelloServlet">
<B>Color:</B> <select name="color"size="1"> <option value="Red">Red</option>
</select> <br><br> <input type=submit value="submit"> </form> </body> </html>
381 In follow ing Java program w hich package needs to be imported for Enumeration? import 5 N A 2 import java.util.*;
382 In follow ing program fill statement show ing ***** Select any one option from given opti 5 N A 2 doGet
423 out.print("W elcome "+n); Cookie ck=new Cookie("uname",n); 5 N A 2 Run the servlet2
response.addCookie(ck); out.print("<form action='servlet'>");
out.print("<input type='submit' value='go'>"); out.print("</form>");
out.close(); }catch(Exception e){System.out.println(e);} } } Output w ill
have messgae W elcome w ith user name and go button. On click of Go
public class ServletX extends HttpServlet { public void
Select the missing code to print sevletconfig object initialization parameter in the follow in
439 Select the valid program w hich show s all life cycle methods of 5 N A 2 GenericServlet { public void init() { // i
GenericServlet.
440 Seperation of business logic from JSP this is the advantage of? 5 N A 2 Custom Tags in JSP
441 service mthod of servelet is use 5 N U 2 to send request and to get response
443 Servlet offer follow ing advantage over CGI 5 N U 2 CGI is not platform independent but servlet are platform ind
445 Servlets becomes thread safe by implementing the javax. Sevlet. Sigle 5 N U 2 as every request is handled by separate
ThreadModelinterface ___________
446 Servlets only needs be loaded once, w hile CGI programs needs to be load for every reque5 N U 2 True
State true or false for the follow ing statements in Java i) Java beans
448 slow dow n softw are development process. Ii) Java servlets do not 5 N U 2 i-false,ii-false
have built in multithreading feature.
450 Suppose the servlet class named Test does not have the package statement, by default, y 5 N A 2 http://localhost:8080/examples/servlet
451 Suppose the tw o parameters in the doGet or doPost method are request and response. 5 N A 2 You have to use request.getCookies() to
To retrieve a cookie from a client, use
____________.
Suppose the tw o parameters in the doGet or doPost method are
452 request and response. To specify HTML content type sent to the client, 5 N U 2 response.setContentType("text/html")
invoke ___________.
453 Suppose you w ant to know each time request comes in, so that you can log it. W hich list5 N U 2 ServletRequestListener
456 The authentication mechanism in the servlet specification uses a technique called? 5 N A 2 Role Based Authentication
457 The correct sequence of JSP life Cycle is 5 N U 2 init(), Service(), destroy()
458 The difference betw een servelets and JSP is the 5 N U 2 Syntax
459 The doGet() method extract values of the parameters type and number by using_____. 5 N U 2 request.getParameter()
460 The follow ing method of HttpServlet is invoked in response to HTTP 5 N U 2 doPost()
POST request.
461 The follow ing methods belongs to the life cycle methods of the servlet. 5 N U 2 All Of Above
The follow ing program contains tw o errors. Identify them from the follow ing- import
java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class SessionDemo
extends GenericServlet
{ public void doGet(HttpServletRequest request, HttpServletResponse
interface for communication betw een the W eb server and the 5 N A 2 Servlet
application program.
503 W hat is the difference betw een cookies and Httpsession? 5 N U 2 Cookies w orks at clientside w hereas HttpSession w orks at
504 W hat is the difference betw een GenericServlet and HttpServlet? 5 N U 2 all of the above
W hat is the diffrence betw een servlet and applet? 1. Servlet execute
519 w hat w ill be the correct output of the follow ing program? import java.io.*; import 5 N A 2 Hello message is printed w ith H1 style
javax.servlet.*; public class H extends GenericServlet
{ public void service(ServletRequest req, ServletResponse res)throw s ServletException,
IOException { res.setContentType("text/html"); PrintW riter pw = res.getW riter(); pw
.println("<H1>Hello!!"); pw .close(); } }
520 w hat w ill be the final output after Enter the valute for First & Second and also click on 5 Y3 U 2 o1
Clac Button? import javax.servlet.*; import javax.servlet.http.*; import java.io.PrintW
riter; import java.io.IOException; public class calcServlet extends HttpServlet { public
void doGet(HttpServletRequest req,HttpServletResponse res)throw s
ServletException,IOException { PrintW riter pw =res.getW riter();
res.setContentType("text/html"); pw .println("
<html><head><title>CALCULATOR</title></head>"); pw .println("
<body>"); pw .println("<form method=post action=calcServlet>");
pw .println("Enter first No.:"); pw .println("<input type=text name=nm>
<br>"); pw .println("Enter Second No.:"); pw .println("<input type=text name=r>");
pw .println("<input type=submit value=calc>"); pw .println("
</form></body></html>"); pw .close(); } public void doPost(HttpServletRequest
req,HttpServletResponse res)throw s ServletException,IOException { String
a=req.getParameter("nm"); String b=req.getParameter("r"); int c=Integer.parseInt(a);
int d=Integer.parseInt(b); int e=c+d; int f=c-d; int g=c*d; PrintW riter pw =res.getW
riter(); res.setContentType("text/html"); pw .println("
<html><head><title>CALCULATOR</title></head>"); pw .println("
<body>"); pw .println(a+"+"+b+"="+e+"<br>"); pw .println(a+"-
"+b+"="+f+"<br>"); pw .println(a+"*"+b+"="+g+"<br>"); int h=c/d; pw
.println(a+"/"+b+"="+b+"<br>"); pw .println("</body></html>"); pw .close(); }
public void destroy() {} }
Figure:-
523 request.getSession(true); response.setContentType("text/html"); 5 N A 2 Display the Last Session Date and the Current Date
525 W hat w ill be the output of the follow ing code snippet? <% int a=5; %> 5 N A 2 a = 15 :: 10
<%! int a=10; %> a = <%=a + this.a%> :: <%= this.a%>
526 static w eb pages, w here as Applets creates dynamic w eb pages 5 N U 2 1,2 are correct
528 W hen using HTML forms w hich of the folow ing is true for POST method 5 N U 2 POST method sends data in the body of the request
529 W hich Action element Includes file at time the page is requested in JSP. 5 N A 2 jsp:include
530 W hich among the below is not a method of Servlet Interface 5 N U 2 All are methods above are of Servlet Interface
532 W hich are useful methods w hich you can use w hile manipulating cookies in servlet? 5 N A 2 All of above
533 W hich authentication mechanism employs a base64 encoding scheme to protect user pass5 N A 2 HTTP Basic Authentication
534 W hich class provides stream to read binary data such as image etc. from the request obje5 N U 2 ServltInputStream
538 W hich cookie it is valid for single session only; it is removed each time 5 N U 2 Non-persistent
w hen user closes the brow ser?
W hich import statement required for follow ing program. public class
542 W hich is least visibility scope for java beans In JSP 5 N U 2 Page
544 W hich is the Microsoft solution for providing dynamic W eb content? 5 N A 2 ASP
W hich is the missing statement in follow ing code to get proper output:
546 W hich JDBC driver types can be used in either applet or servlet code 5 N U 2 type 3 and 4
547 W hich JSTL code snippet can be used to perform URL rew riting? 5 N A 2 <a href='<c:url value="foo.jsp"/>' />
548 W hich mechanism is included by jsp for defining custom tags? 5 N U 2 dynamic attributes
549 W hich method is called by the servlet container to allow the servlet to respond to a reque5 N U 2 service()
550 W hich method is used to get HttpSession object and it belongs to w hich object? 5 N U 2 getSession method and HttpServletRequ
551 W hich method of the request object is used to extract values of the input fields in a form 5 N A 2 getParameter()
552 W hich method of the servlet is/are called several times in its life? 5 N U 2 doPost()
553 W hich method returns a servletConfig object that contains any initialization parameters? 5 N U 2 servletConfig getServletConfig()
554 W hich method returns the current session associated w ith this request, or if the request 5 N A 2 getSession()
559 W hich of the follow ing are examples of JSP directive. 5 N U 2 include
560 W hich of the follow ing are the session tracking techniques? 5 N A 2 URL rew riting,using session object,using cookies,using hidd
5 Y1 A 2 request.getMethod().equals("GET")
579 i=Integer.parseInt(request.getParameter("t1")); int 5 N A 2 request.getParameter("a1");
j=Integer.parseInt(request.getParameter("t2")); int k=0; String str=****** ; if(str.equal
W hich statements should be w ritten in the place of dotted lines to display output "Hello W
585 import java.io.*; public class ServletDemo extends GenericServlet { 5 N A 2 PrintW riter pw =response.getW riter(); pw .println("H
public void service(ServletRequest request,ServletResponse response)
{ try { ................................ ................................ } catch(Exception e) {
System.out.println(e); } } }
W hich statemnet of servlet counts and displays the number of times it has been accessed
Figure:-
Your w eb page includes a Java SE v1.5 applet w ith the follow ing declaration: <object cla
598 _____________ method of the request object is used to extract values of the input fields 5 N U 2 getParameter()
599 ______________ are JSP code fragments embedded w ithin <% ...%> 5 N A 2 Scriptlets
tags.
602 Apache Tomcat is a ________. 5 N U 2 W eb server that is capable of running Java programs.
heck boxes, Choice lists.
BorderLayout(3,4);
fontstyle,int pointsize)
t, String boxName)
ardlayout(int hor, int ver) //second
quot;);
umns of text.
the JDialog.
n I, Boolean State)
ean multipleSelect)
w ing() { JLabel l1 = ne w JLabel("User
quot;Passw ord" ;); JTextField t1 = new ew
ield(); JButton b1 = n
ated
eated
nd b.
created
eated
ject
is invoked
er class
w Label("tw o& quot;); b1=new
s Frame { Button b; GridLayoutDemo3() { setLayout(new
String.valueOf(i))); }
ow s Exception { new
va
ageIcon(“India.gif”); JButton Jb= new JButton(“ok”,ii);
*;public class Demo e b1,b2; xtends JApplet{ JButton
Container c=g etContentPane(); Red",
ew JCheckBox(" true);
false); b1=new
;c.add(cb2);c.add(b1 );c.add(b2);} }
ckboxGroup
mo extends Frame { mbr = MenuDemo() { MenuBar
u f = new Men Menu e = new u("File");
Menu MenuItem f1=new ("View ");
x MenuItem f2=new
true); f.add(f1); f.ad d(f2); mbr.add(f);
void main(String args []) { MenuDemo m = new
Size(400,400); } }
ge java.aw t
el,fig(d)-List,fig(e)-Ch eckBoxGroup,fig(f)-
o row s and three col vertical umns w ith horizontal and
rderLayout.SOUTH);
e platform independent.
ew BorderLayout())
nt height,int w idth)
kground(Color.RED); N);
kground(Color.GREE ;
kground(Color.BLUE)
N, 48)
yout
", Font.BOLD,24);
Constants related to s crollbars
tem
,JTextArea
olumns
e w orking of Application
GHT)
();
ends Frame { public s argv[]) tatic void main(String
etLayout(new Flow ton("Hello");
elloBut=new But Button ); add(ByeBut);
; add(HelloBut
n
nswer
va.aw t package;
l mentioned above
emStateChanged()
ouseMotionListener
ouseMotionListener
ventObject(Object src)
EXT_VALUE_CHANGED
ctionEvent,TextEvent
xtChanged(TextEvent obj)
l of the mentioned
etActionCommand()
OUSE_W HEELMOVE
utton,List,MenuItem
method.
ddMouseMotionListener()
ousePressed(MouseEvent e){}
heckBoxMenuItem
va.util.EventObject
ddActionListener(ActionListener o bj)
d()
etAdjustmentType()
ddMouseMotionListener().
l of the mentioned
OMPONENT_SIZED
correct
(ItemEvent ie)
.jpg
ntentPane();
uot;NO")
er(AdapterDemo (this));
ror is in the statement String s= (String)ie.getItem();
tatement
er(this);
er()
nt e)
ssed(KeyEvent k e)
add(jtp);
s);
istener class
void valueChan ged(TextEvent e) is w rong it shoul t
anged(TextEven e)
tement
leared in code
Color.yellow );
vent.*; is missin g
mport java.aw t.* ; import java.aw t.event.*; import ve
ic class choicee extends Applet implements uot;;
ng m=" &q Choice os; public void init() W indow
; os.add(" s 98");
dow s XP") ; os.add("W ind
ner,actionEvent(ActionEvent ae)
,addActionListe
Listener
ener(this);
(ItemEvent ie)
d()
ctionEvent e)
(ItemEvent ev)
nt ke)
hanged
ctionEvent ae)
Event e)
ctionEvent ae)
ctionEvent ae)
vent ke)
ed(ItemEvent ie )
(ItemEvent ie)
(ItemEvent e)
ionPerformed(Ac tionEvent e)
ousepressedListener
eyListener interface
er(this);b2.add ActionListener(this);
eyDragged(KeyEvent ke)
hanged(Adjust mentEvent e)
ionPerformed
l mentioned above
ouseExited,mouseEntered,mous ePressed,mouseClicked,mouseRele
onListener
addActionListener(this);
tfield
tItem();
lse
ditable(true);
m1.addActionLis tener(this);
his);
this);
B
s);
r(this);
tener
ctionEvent ae)
; brow ser = new Choice();
g.*;
w ImageIcon(&q uot;star.gif"));
er(this)
r(new mouse() );
u);
u);
u);
B
ner(this);
er(this);
w JScrollPane(jp ,v,h);
emStateChanged(ItemEvent ie)
(ItemEvent ie)
ActionListener,a ctionPerformed(ActionEvent e)
); b1.addActionL istener(this);
; add(maybe);
bodemo11.java
d()
ctionEvent a)
oid mouseMoved(MouseEvent me )
onperfomed()
play vertical and sb2 display horizontally
method
ActionEvent
s KeyListener ke yPressed(KeyEvent ke)
bove
on
abstract and doe s not override abstract method
hanged(Adjust class mentEvent) in AdjustmentListener p
s Applet i mplements AdjustmentListener
ed
me
va.util.eventObject
ouput
emStateChanged()
ed in Checkbox Constructor
hanged
programming
splay the string & quot;Advanced Java
t; in appletview er w indow . The size of the string w
oints w ith every mouse click.
be displayed in t extfield
em from list1 is added to list2
ects
y A is pressed
t w as added as listener
utton,List,MenuItem
a , Button
r
vent.*; import ja va.aw t.*; import java.applet.*;
er(this);
r()
emStatechanged(ItemEvent e)
onPerformed (Act ionEvent event )
etIcon(ImageIcon i)
ect
l of the mentioned
ner(p)
l of the mentioned
LL of the mentioned
EXT_VALUE_CHANGED
l of the mentioned
ddMouseMotionListener()
()
mouseDragged()
er(this);
AdjustmentList ener(this);
e
class
vent.ItemListene r;
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
or Edit Dele
et Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
. Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
eam in = s.getInputStream(); Edit Dele
Edit Dele
Edit Dele
Edit Dele
n Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
n Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
ess class does not contain any visible constructor. Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
n Edit Dele
); Edit Dele
() Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
n Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
ot correct Edit Dele
Edit Dele
Edit Dele
rver socket bound to the specified p An exceptort. Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
ct containing data from inputstream object Edit Dele
ml Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
in method Edit Dele
Edit Dele
Edit Dele
rt java.io.*; class tcpip_client { publi static c Edit Dele
) throw s IOException { Socket s=null;
try { s=new
LocalHost(),98); b=new
putStreamReader(s.getInputStream( )));
ception u) { System.err.println(" don't }I
em.exit(0); } String inp; w
!=null) { System.out.println(inp); }
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
; Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
); Edit Dele
() Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
n Edit Dele
Edit Dele
Edit Dele
Edit Dele
Edit Dele
Answer
C w ritten in C language
ermines w hether the ResultSet c ursor points to the last row of the
ion getConnecti on(String url, String name, String p
jdbc.odbc.JdbcOdbcDriver
sNotFoundException
eparedStatement object
xecuteQuery();
databases
sNotFoundException
Datbase Connectivity
Database Connectivity
n database connectivity
ompile Statement
jdbc.odbc.JdbcOdbcDriver
E_FORW ARD_ONLY
a driver
s.forName("sun.jdbc.odbc. JdbcOdbcDriver")
rt into department values(?,?,?)
s.forName("sun.jdbc.odbc. JdbcOdbcDriver")
cution statemen t
ation statement
aredStatement interface
dbc.odbc.JdbcO dbcDriver”);
ry)
qry)
d values(?,?,?)& quot;;
ement.
dbcDriver
eStatement();
verManager.get Connection("jdbc:odbc:mcm
ble
te();
eateStatement( );
reateStatement ();
ement
block
ck
nnection()
d
statement.
eManager.getC onnection(url);
ent
ement
me
lay All the Records of StudTable
ed
d}
tatement
teStatement();
of * symbol
red
=c.createState ment();
t mentioned
erManager.getC onnection(url);
ment();
ement
name is incorre ct
mp; SetString is i ncorrect
ame is incorrect
missing
ry);
getConnection(u rl);
ultSet.TYPE_BACKW ORD_ONLY
an CEO
ving id=33
alues(11,'rames h')
nnection(url);
x of Question mark
LETE
ENSITIVE
sNotFoundException
a driver
gisterDriver(Driver driver)
date()
md = rs.getMeta Data();
sert all values int o emp table until user press 'n' .
.security.permission
x.sql.ConnectionEvent
tSet
tement (" SELECT COF_NAME, PRICE FROM C
ecuteQuery();
erManager.getC onnection(url);
reateStatement ();
ITIVE
uteQuery(s1);
;sun.jdbc.odbc. JdbcOdbcDriver");
tSet
n = DriverManager.g ;jdbc:mysql://localhost/test"
Stock}");cs.executeQuery();
Statement(ResultSet.TYPE_S
tSet.CONCUR_UPDATABLE);
nect()
g url="jdbc:odbc:abc";
table is created .
rror
row you are positioned on is del eted form the ResultSet and from t
undException: s un.jdbc.odbc.JdbcodbcDriver
se
n.createStateme nt();
Suresh
ement.
tatement
L w arning
ed
ption ii
ation error
ecuteUpdate Q uery
UserName(). ,isReadonly()
va driver
-java driver
ed above
ocol,subprotocol,datasource na me
cuteQuery(String sql)
st()
eteRow ();
r object
querydel);
catch() Stateme nt
hods
;jdbc:odbc:stud dsn"); Connection
getConnection(& quot;sun.jdbc.odbc.JdbcOdbcDrive
smd=rs.getMeta Data();
alization,persistence
s.forName("sun.jdbc.odbc. JdbcOdbcDriver")
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
, init() , destroy() Ed
Ed
Ed
LUE=parameter_value> Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
sion> Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
ame"); E
tion="CheckPass "
E
E
E
es(); E
E
E
E
uest.getSession(true); E
E
E
ata); text/html E
E
E
extended E
Ed
Ed
Ed
Ed
er(); replace this statement w ith response.getW riter(); Ed
E
etResponse res) E
quot;name"); E
ACTION="/servle t/Hello"> E
Ed
Ed
Ed
Ed
show Cart.jsp"); Ed
Ed
ew Cookie("username", "joe")); Ed
Ed
secureapp/do/Login?name="bob" Ed
%> Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
EB-INF\classes Ed
); response.addCookie(c);
E
E
Ed
Ed
initialization goes here } public void service(ServletRequest reqEd
Ed
Ed
Ed
Ed
Ed
Ed
Ed
t/Test Ed
ype("text/html") Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
yle E
e E
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
Ed
rt javax.servlet.*; Ed
Ed
Ed
Ed
Ed
Ed
Ed
alue="foo.jsp"/>' /> Ed
Ed
Ed
uest Ed
Ed
Ed
Ed
Ed
erValues() Ed
Ed
Ed
Ed
"a1");
Ed
Ed
Ed
Ed
Ed
Ed
Ed