Professional Documents
Culture Documents
Q. QUESTION
1. ________ layout is a group of containers that are displayed one at time with each container in the
group.
A. grid layout
B. card layout
C. box layout
D. border layout
Answer: B
4. ______________ automatically arranges your controls within a window using some type of
algorithm.
A. JVM
B. Layout Manager
C. Java Tools
D. none of these
Answer: B
6. _________is used to represent GUI application window ,which is optionally resizable and an have
a title bar , icon, and menus.
A. Panel
B. Frame
C. Dialog
D. Window
Answer: B
7. …………………is container that contains title bar and can have Menu bars.It can also have other
components like button,checkbox etc.
A. Panel
B. Window
C. Frame
D. Container
Answer: C
11. add() method which used to add component to window which is defined by_______class.
A. Frame
B. Component
C. Window
D. Container
Answer: B
12. An Applet has its Layout Manager set to the default of FlowLayout. What code would be the
correct to change to another Layout Manager?
A. setLayoutManager(new GridLayout());
B. setLayout(new GridLayout(2,2));
C. setGridLayout(2,2,))
D. setBorderLayout();
Answer: B
13. AWT is used for creating a GUI in Java. AWT stands for
A. Advanced Web Technology
B. Abvanced Window Toolkit
C. Abstract Web Toolkit
D. Abstract Window Toolkit
Answer: D
14. Checkable menu items are created using object of ……………………. class.
A. CheckboxMenuItem
B. CheckBoxMenuItem
C. CheckboxGroupMenuItem
D. CheckableMenuItem
Answer: A
24. How do you change the current layout managers for a container?
A. Use the setLayout method
B. Once created you can not change the current layout manager
C. Use the setLayoutManager method
D. Use the UpdateLayout method
Answer: A
25. How many components are used for form validation i.e input username and password
A. 2 Label,2 Button,2 List
B. 2 Label,2 Button,2 TextField.
C. 2 Label,1 Button,2 Textfield
D. 2 Label,2 Button,5 Textfield
Answer: C
27. How would you set the color of a graphics context called g to cyan?
A. g.setColor("cyan’);
B. g.setCurrentColor(cyan);
C. g.setColor("Color.cyan");
D. g.setColor(Color.cyan);
Answer: D
33. Multiple layouts in the single conainer can be created with the help of _______________
A. Frame
B. Panel
C. Window
D. Container
Answer: B
34. Name the class used to represent a GUI application window, which is optionally resizable and can
have a title bar, an icon,
A. Window
B. Panel
C. Dialog
D. Frame
Answer: D
36. Which layout manager can be used to get the following output?
A. FlowLayout
B. GridLayout
C. BorderLayout
D. CardLayout
Answer: C
37. Which of the following statement is used to create GridLayout in the output shown below?
39. Choose the correct missing statement from the given code
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.applet.*;
class Myframe extends Frame
{
Myframe(String title)
{
super(title);
}
public void paint(Graphics g)
{
g.drawString("This is frame window",120,150);
}
}
public class Myframeapplet extends Applet //implements windowListener
{
public void init()
{
f1=new Myframe("Frame window");
f1.setSize(350,350);
//f1.setLocation(450,450);
f1.setVisible(true);
//f1.addwindowListener(this);
}
public void start()
{
f1.setVisible(true);
}
public void stop()
{
f1.setVisible(false);
}
public void paint(Graphics g)
{
g.drawString("This ia a applet window",10,50);
} }
/* <applet code="Myframeapplet" width=1000 height=1000> </applet> */
A. Myframeapplet f1;
B. Myframe f1;
C. myframe f1;
D. frame f1;
Answer: B
C. D.
import java.awt.*; import java.awt.*;
import java.applet.*; import java.applet.*;
public class expe2 extends Applet public class expe2 extends Applet
{ {
Button lbl; Button lbl;
Button lbl1; Button lbl1;
Button lbl2; Button lbl2;
public void init() public void init()
{ {
setLayout(new setLayout(new FlowLayout(FlowLayout.LEFT));
FlowLayout(FlowLayout.RIGHT)); lbl=new Button("OK");
lbl=new Button("OK"); lbl2=new Button("Exit");
lbl1=new Button("Cancle"); add(lbl);
lbl2=new Button("Exit"); add(lbl1);
}} add(lbl2);
}}
Answer: A
41. Choose the correct sequence for the following output
A. B.
import java.awt.*; import java.awt.*;
import java.applet.*; import java.applet.*;
/* <applet code="LabelDemo" width=300 /* <applet code="LabelDemo" width=300
height=200> </applet> */ height=200> </applet> */
public class LabelDemo extends Applet { public class LabelDemo extends Applet {
public void init() { public void init() {
Label one = new Label("One"); Label one = new Label("One");
Label two = new Label("Two"); Label two = new Label("Two");
Label three = new Label("Three"); Label three = new Label("Three");
add(one);add(two);add(three); } }
}}
C. D.
import java.awt.*; import java.awt.*;
import java.applet.*; import java.applet.*;
/* <applet code="LabelDemo" width=300 /* <applet code="LabelDemo" width=300
height=200> </applet> */ height=300></applet> */
public class LabelDemo extends Applet { public class LabelDemo extends Applet {
public void init() { public void init() {
add(one); add(two); add(three); Label one = new Label("One");
Label one = new Label("One"); Label two = new Label("Two");
Label two = new Label("Two"); Label three = new Label("Three");
Label three = new Label("Three"); add(three);add(two);add(one);
}} }}
Answer: A
42. Choose the correct source code to display the following output
A. B.
import java.awt.*; import java.awt.*;
class DemoFrame extends Frame class DemoFrame extends Frame
{ {
MenuBar mbar; MenuBar mbar;
Menu file, edit; Menu file, edit, exit;
MenuItem cut, copy, paste; MenuItem cut, copy, paste;
public DemoFrame() public DemoFrame()
{ {
mbar = new MenuBar(); mbar = new MenuBar();
file=new Menu("File"); file=new Menu("File");
edit=new Menu("Edit"); edit=new Menu("Edit");
cut=new MenuItem("Cut"); exit=new Menu("Exit");
copy=new MenuItem("Copy"); cut=new MenuItem("Cut");
paste=new MenuItem("Paste"); copy=new MenuItem("Copy");
file.add(cut); paste=new MenuItem("Paste");
file.add(copy); edit.add(cut);
file.add(paste); edit.add(copy);
mbar.add(file); edit.add(paste);
mbar.add(edit); mbar.add(file);
this.setMenuBar(mbar); mbar.add(edit);
} mbar.add(exit);
public static void main(String args[]) this.setMenuBar(mbar);
{ }
DemoFrame f = new DemoFrame(); public static void main(String args[])
f.setBounds(50,50,600,400); {
f.setVisible(true); DemoFrame f = new DemoFrame();
} f.setBounds(50,50,600,400);
} f.setVisible(true);
} }
C. D.
import java.awt.*; import java.awt.*;
class DemoFrame extends Frame class DemoFrame extends Frame
{ {
MenuBar mbar; MenuBar mbar;
Menu file, edit, exit; Menu file, edit;
MenuItem cut, copy, paste; MenuItem cut, copy, paste;
public DemoFrame() public DemoFrame()
{ {
mbar = new MenuBar(); mbar = new MenuBar();
file=new Menu("File"); file=new Menu("File");
edit=new Menu("Edit"); edit=new Menu("Edit");
exit=new Menu("Exit"); cut=new MenuItem("Cut");
cut=new MenuItem("Cut"); copy=new MenuItem("Copy");
copy=new MenuItem("Copy"); paste=new MenuItem("Paste");
paste=new MenuItem("Paste"); edit.add(cut);
file.add(cut); edit.add(copy);
file.add(copy); edit.add(paste);
file.add(paste); mbar.add(file);
mbar.add(file); mbar.add(edit);
mbar.add(edit); this.setMenuBar(mbar);
mbar.add(exit); }
this.setMenuBar(mbar); public static void main(String args[])
} {
public static void main(String args[]) DemoFrame f = new DemoFrame();
{ f.setBounds(50,50,600,400);
DemoFrame f = new DemoFrame(); f.setVisible(true);
f.setBounds(50,50,600,400); }}
f.setVisible(true);
} }
Answer: B
43. Consider following program and state how meny main menu and sub menu displayed in output:
import java.awt.*;
public class MenuDemo
{
public static void main(String args[])
{
Frame f=new Frame("My Frame");
f.setVisible(true);
MenuBar mbr= new MenuBar();
f.setMenuBar(mbr);
Menu filemenu=new Menu("File");
Menu editmenu=new Menu("Edit");
Menu viewmenu=new Menu("View");
mbr.add(filemenu);
mbr.add(editmenu);
mbr.add(viewmenu);
MenuItem new1=new MenuItem("New");
MenuItem open1=new MenuItem("Open");
filemenu.add(new1);
filemenu.add(open1);
new1.setEnabled(false);
CheckboxMenuItem wordwrap=new CheckboxMenuItem("WordWrap");
editmenu.add(wordwrap);
}
A. 3 Main,3 Sub menu
B. 3 Main,2 Sub menu
C. 3 Main,1 Sub menu
D. 2 Main,3 Sub menu
Answer: A
46. Debug the following code and idntify statements containing error.
import java.awt.*;
import java.applet.*;
public class BorderDemo extends Applet
{
BorderLayout b;
Button b1,b2,b3,b4,b5;
public void init()
{
b=new BorderLayout();
setLayout(b);
b1=new Button("TOP");
b2=new Button("LEFT");
b3=new Button("BOTTOM");
b4=new Button("RIGHT");
b5=new Button("CENTER");
add(b1,BorderLayout.TOP);
add(b3,BorderLayout.BOTTOM);
add(b4,BorderLayout.EAST);
add(b2,BorderLayout.WEST);
add(b5,BorderLayout.CENTER);
}}
/*<applet code=BorderDemo.class width=500 height=500></applet>*/
A. Statements where buttons b1 and b3 are added to the applet
B. Statements where buttons b2 and b4 are added to the applet
C. Statements where buttons b2 and b5 are added to the applet
D. Statements where buttons b4 and b5 are added to the applet
Answer: A
CHAPTER 2: SWING
Q. QUESTION
1. _________ are the properties in JTable.
A. gridColor
B. rowCount
C. columnCount
D. All Above
Answer: D
2. __________ is a Swing class that allows the user to enter a single line of text.
A. TextField
B. JTextField
C. EditTextField
D. TextArea
Answer: B
9. A JFrame supports three operations when the user closes the window. Which of the choices below is
not one of the three:
A. DISPOSE_ON_CLOSE
B. DO_NOTHING_ON_CLOSE
C. LOWER_ON_CLOSE
D. HIDE_ON_CLOSE
Answer: C
10. A ______ is component that presents a rectangular area in which a component may be viewed
A. Tabbed Pane
B. Scroll Pane
C. Glass Pane
D. All of above
Answer: B
17. In Swing ____________is a component that displays rows and columns of data.
A. card
B. tree
C. table
D. tabbed Pane
Answer: C
24. Swing is not a part of JFC (Java Foundation Classes) that is used to create GUI application?
A. True
B. False
Answer: B
25. The ________ class is a container that allows multiple components to be added but only displays
one component at a time.
A. JFrame
B. JTabbedPane
C. JPanel
D. Japplet
Answer: B
27. Which method specifies that the text and icon are horizontally aligned to the right in the button jbt.
A. jbt.setVerticalTextPosition(JButton.LEFT)
B. jbt.setHorizontalTextPosition(JButton.LEFT)
C. jbt.setHorizontalTextPosition(JButton.RIGHT)
D. jbt.setHorizontalAlignment(JButton.RIGHT)
Answer: C
34. Which two parameters are required for JTabel constructor to create Table?
A. Data Array and row headings
B. Data Array and Column Headings
C. Single Data element and column headings
D. Single Data element and row Headings
Answer: B
C. D.
Answer: A
A. B.
import java.awt.*; import java.awt.*;
import javax.swing.*; import javax.swing.*;
public class Demo extends JApplet { public class Demo extends JApplet {
JButton b1,b2; JButton b1,b2;
JCheckBox cb1,cb2; JCheckBox cb1,cb2;
public void init() { public void init() {
Container c=getContentPane(); Container c=getContentPane();
c.setLayout(new FlowLayout()); c.setLayout(new FlowLayout());
cb1=new JCheckBox("Red"); cb1=new JCheckBox("Red",true);
cb2=new JCheckBox("Blue"); cb2=new JCheckBox("Green",false);
b1=new JButton("Submit"); b1=new JButton("Submit");
b2=new JButton("Reset"); b2=new JButton("Reset");
c.add(cb1); c.add(cb2); c.add(b1); c.add(b2); c.add(b1); c.add(b2); c.add(cb1); c.add(cb2);
} } } }
C. D. None of these
import java.awt.*;
import javax.swing.*;
public class Demo extends JApplet {
JButton b1,b2;
JCheckBox cb1,cb2;
public void init() {
Container c=getContentPane();
c.setLayout(new FlowLayout());
cb1=new JCheckBox("Red", true);
cb2=new JCheckBox("Blue", false);
b1=new JButton("Submit");
b2=new JButton("Reset");
c.add(cb1); c.add(cb2); c.add(b1); c.add(b2);
} }
Answer: C
39. Identify the error
import java.awt.*;
import javax.swing.*;
/*<applet code="JTableDemo" width=400 height=200></applet>*/
public class JTableDemo extends JApplet
{
public void init()
{
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
final String[] colHeads = { "Roll No", "Name", "Branch" };
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);
} }
A. Error in statement in which JTable is created
B. Error in statement in which JScrollPane is created
C. Error in statement in which applet tag is declared
D. None of these
Answer: A
41. Select the correct code for display the given output
A. B.
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
public class ShowLayout extends JFrame public class ShowLayout extends JFrame
{ {
public ShowLayout (String s) public ShowLayout (String s)
{ {
Container c = f.getContentPane(); Container c = f.getContentPane();
c.setLayout (new FlowLayout()); c.setLayout (new FlowLayout());
c.add (new Button("NO"); for (int i = 0; i < 5; i++)
c.add (new Button("Batter"); {
c.add(new Label("Swing")); c.add (new Button("NO");
} }
public static void main (String args[]) c.add (new Button("Batter");
{ c.add(new Label("Swing"));
JFrame f = new }
ShowLayout("JFrameExample"); public static void main (String args[])
f.setVisible(true); {
} } JFrame f = new
ShowLayout("JFrameExample");
f.setVisible(true);
} }
C. D.
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
public class ShowLayout extends JFrame public class ShowLayout extends JFrame
{ {
public ShowLayout (String s) public ShowLayout (String s)
{ {
Container c = f.getContentPane(); Container c = f.getContentPane();
c.setLayout (new FlowLayout()); c.setLayout (new FlowLayout());
for (int i = 0; i < 5; i++) for (int i = 0; i < 4; i++)
{ {
c.add (new Button("NO"); c.add (new Button("NO");
c.add (new Button("Batter"); c.add (new Button("Batter");
} }
c.add(new Label("Swing")); c.add(new Label("Swing"));
} }
public static void main (String args[]) public static void main (String args[])
{ {
JFrame f = new JFrame f = new
ShowLayout("JFrameExample"); ShowLayout("JFrameExample");
f.setVisible(true); f.setVisible(true);
} } } }
Answer: C
A. B.
JTable it=new JTable(data,s); JTable it=new JTable(data,s);
int v = JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED; int v = JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED; int h = JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane p=new JScrollPane(it,v,h);
C. D.
JTable it=new JTable(data,s); JTable it=new JTable(data,s);
int v = JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane p = new JScrollPane(it,v,h);
addWindowListener(new MyAdapter());
addMpouseListener(new MyAdapter());
Answer: D
44. Select the missing statement in the following code
import java.awt.FlowLayout;
public class HelloWorldSwing1 extends JFrame {
public static void main(String[] args) {
JFrame frame = new JFrame("HelloWorldSwing");
JLabel label = new JLabel("Hello World");
JButton b1=new JButton("submit");
JTextField t1=new JTextField(10);
frame.getContentPane().add(label);
frame.getContentPane().add(t1);
frame.getContentPane().add(b1);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
frame.getContentPane().setLayout(new FlowLayout());
} }
A. import javax.swing.*;
B. import javax.Swing.io.*;
C. import javax.Swing.awt.*;
D .import java.Swing.*;
Answer: A
45. Select the missing statement in the program to get the following output
import java.awt.*;
import javax.swing.*;
/* <applet code="JComboBoxdemo" width=300 height=200> */
public class JComboBoxdemo extends JApplet
{
public void init()
{
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
JComboBox jc = new JComboBox();
jc.addItem("France");
jc.addItem("Germany");
jc.addItem("Italy");
jc.addItem("Japan");
contentPane.add(jc);
}}
A. </applet>
B. import java.awt.event.*;
C. }
D. {
Answer: A
46. Select the missing statement in the program to get the following output
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
/* <applet code="JTreeEvents" width=400 height=200> </applet> */
public class JTreeEvents extends JApplet
{
JTree tree;
JTextField jtf;
public void init()
{
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");
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 h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
int v=ScrollPaneConstants.VERTICAL_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("");
} }
A. a.add(a2);
B. top.add(a2);
C. a1.add(a2);
D. a.add(a1);
Answer: A
48. Which of the following statement is missing from the program to be correct?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Jprogress extends JPanel
{
JProgressBar pb;
static final int min=50;
static final int max=100;
public Jprogress()
{
pb=new JProgressBar();
pb.setMinimum(min);
pb.setMaximum(max);
add(pb);
}
public void update(int value)
{
pb.setValue(value);
}
public static void main(String a[])
{
final Jprogress p1=new Jprogress();
JFrame f=new JFrame("Demo");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(300,300);
f.setVisible(true);
for (int i=min;i<=max;i++)
{
final int percent=i;
try
{
p1.update(percent);
java.lang.Thread.sleep(100);
}
catch(Exception e){ }
}}}
A. f.setContentPane(p1);
B. add(min);
C. pb.setSize();
D. None of the above
Answer: A
A. f=new JFrame();
f.setLayout(new FlowLayout(FlowLayout.RIGHT));
B. f.setLayout(new FlowLayout(FlowLayout.RIGHT));
C. f=new JFrame();
D new JFrame();
setLayout(new FlowLayout(FlowLayout.RIGHT));
Answer: A
CHAPTER 3: Event Handling
Q. QUESTION
1. An event is generated when internal state of event source is________
A. Not change
B. changed
C. Either change or not
D. None of these
Answer: B
4. Select proper sequence of following classes used for writing menudriven program:
1. Menu 2. MenuBar 3. MenuItem
A. 2,1,3
B. 1,2,3
C. 3,2,1
D. None Of The Above
Answer: A
6. To handle all the events related to ScrollBar, the following method of AdjustmentListener needs
to be overriden.
A. public void adjustmentValueChanged(AdjustmentEvent obj)
B. public void adjustmentChanged(AdjustmentEvent obj)
C. public void actionPerformedActionEvent obj)
D. None of the above
Answer: A
11. Which of the following are valid return types, for listener methods?
A. Boolean.
B. Void.
C. the type of event handled.
D.Component.
Answer: B
13. Which of the following statements about anonymous inner classes is false?
A. They are declared without name
B. They typically appears in method declartion
C. They are declared with annonymous keyword
D. They can access their top level members
Answer: C
15. Which of these methods are used to register a mouse motion listener?
A. addMouseMotion()
B. addMouseListener()
C. addMouseMotionListener()
D. addMotionListener()
Answer: C
17. You have created a simple Frame and overridden the paint method as follows
public void paint(Graphics g)
{ g.drawString("Dolly",50,10);
}
What will be the result when you attempt to compile and run the program?
A. The string "Dolly" will be displayed at the centre of the frame
B. The string "Dolly" will be shown at the Right of the form.
C. The word "Dolly" will be seen at the top-left of the form.
D. The string "Dolly" will be shown at the bottom of the form.
Answer: C
23. ______________method returns a reference to the component that was added to or removed
from the container.
A. getContainer()
B. getChild()
C. getValue()
D. None of these
Answer: B
24. _____________method returns a Point object that contains both X and Y coordinates.
A. getLocationOnScreen()
B. getXOnScreen()
C. getYOnScreen()
D. None of the above
Answer: A
25. ___________method returns a value that indicates which modifier keys were pressed when the
event was generated.
A. getModifiers()
B. setModifiers()
C. getActionCommand()
D. none of the above
Answer: A
27. Clicking the closing button on the upper-right corner of a frame generates a(n) __________ event.
A. ItemEvent
B. WindowEvent
C. MouseMotionEvent
D. ComponentEvent
Answer: B
31. Pick the correct statement to register a button b for event handling
A. b.addActionListener(this);
B. b.addItemListener(this);
C. b.addMouseListener(this);
D. b.addFocusListener(this);
Answer: A
32. Suppose that you want to have an object 'eh' to handle the TextEvent of a TextArea object.How
should you add eh as the event handler to it.
A. t.addTextListener(eh)
B. eh.addTextListener(t)
C. addTextListener(eh,t)
D. addTextListener(t,eh)
Answer: A
35. To listen to mouse clicked events, the listener must implement the __________ interface or
extend the _______ adapter.
A. mouselistner / mouseadapter
B. mousemotionlistner / mousemotionadapter
C. WindowListener/WindowAdapter
D. ComponentListener/ComponentAdapter
Answer: A
C. D.
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.applet.*; import java.applet.*;
public class Fifth5 extends Applet implements public class Fifth5 extends Applet implements
ItemListener ItemListener
{ {
Checkbox cb1,cb2,cb3; Checkbox cb1,cb2,cb3;
CheckboxGroup cbg; CheckboxGroup cbg;
Label l1; Label l1;
public void init() public void init()
{ {
cbg=new CheckboxGroup(); cbg=new CheckboxGroup();
cb1=new Checkbox("C cb1=new Checkbox("C
programming",cbg,false); programming",cbg,false);
cb2=new Checkbox("C++ cb2=new Checkbox("C++
programming",cbg,false); programming",cbg,true);
cb3=new Checkbox("Java cb3=new Checkbox("Java
programming",cbg,false); programming",cbg,false);
l1=new Label("Before ItemSelection"); l1=new Label("Before ItemSelection");
add(cb1); add(cb1);
add(cb2); add(cb2);
add(cb3); add(cb3);
add(l1); add(l1);
} } } }
Answer: D
37. Complete the code to display the selected item of the list.
/* <applet code="MyControl11" width=300 height=300> </applet> */
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class MyControl11 extends Applet implements ItemListener
{
List list;
Label l;
public void init()
{
list=new List();
l=new Label();
list.add("one");
list.add("two");
list.add("three");
setLayout(null);
list.setBounds(20,20,100,20);
l.setBounds(20,150,100,20);
add(list);
add(l);
list.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
________________________
} }
A. List.getSelectedObjects();
B. l.setText(list.getSelectedItem());
C. label.setText(list.getSelectedItem());
D. list.getItem();
Answer: B
38. Consider following output. Find missing statement from following code.
import java.awt.*;
import java.applet.*;
import java.awt.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)
{
showStatus("key pressed");
int kl=k.getKeyCode();
switch(kl)
{
case KeyEvent.VK_LEFT:
msg+="<left arrow>";
break;
case KeyEvent.VK_RIGHT:
msg+="<right arrow>";
break;
}
repaint();
}
public void keyReleased(KeyEvent k)
{
showStatus("key up");
}
public void keyTyped(KeyEvent l)
public void paint(Graphics g)
{
g.drawString(msg,x,y);
} }
A. Missing }
B. Missing ;
C. Missing ( )
D. Missing{}
Answer: D
40. Consider the following output. Find the missing statement in the program.
import java.awt.Frame;
import java.awt.event.*;
public class HandleMouseListenerInWindowExample extends Frame implements MouseListener{
int x=0, y=0;
String strEvent = "";
HandleMouseListenerInWindowExample(String title){
super(title);
addWindowListener(new MyWindowAdapter(this));
addMouseListener(this);
setSize(300,300);
setVisible(true); }
public void mouseClicked(MouseEvent e) {
strEvent = "MouseClicked";
x = e.getX();
y = getY();
repaint(); }
public void mouseReleased(MouseEvent e) {
strEvent = "MouseReleased";
x = e.getX();
y = getY();
repaint(); }
public void paint(Graphics g){
g.drawString(strEvent + " at " + x + "," + y, 50,50); }
public static void main(String[] args) {
HandleMouseListenerInWindowExample myWindow =
new HandleMouseListenerInWindowExample("Window With Mouse Events Example");
} }
class MyWindowAdapter extends WindowAdapter{
HandleMouseListenerInWindowExample myWindow = null;
MyWindowAdapter(HandleMouseListenerInWindowExample myWindow){
this.myWindow = myWindow;
}
public void windowClosing(WindowEvent we){
myWindow.setVisible(false);
}
A. B.
public void mouseExited(MouseEvent e) { public void mouseEntered(MouseEvent e) {
strEvent = "MouseExited"; strEvent = "MouseEntered";
x = e.getX(); x = e.getX();
y = getY(); y = getY();
repaint(); } repaint(); }
C. D.
public void mousePressed(MouseEvent e) { All of the Above
strEvent = "MousePressed";
x = e.getX();
y = getY();
repaint(); }
Answer: D
41. Consider the following output. Find the missing statement in the program.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
/* <applet code="SimpleKey1" width=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)
{
showStatus("Key Down"); }
public void keyReleased(KeyEvent ke)
{
showStatus("Key Up"); }
public void keyTyped(KeyEvent ke)
{
msg += ke.getKeyChar(); }
public void paint(Graphics g)
{
g.drawString(msg, X, Y); }
}
A. paint();
B. paintGraphics()
C. repaint();
D. None of these
Answer: C
42. Consider the following program. What correction should be done in the program to get correct
output?
import java.applet.*;
import java.awt.event.*;
/* <APPLET Code="SimpleKey" Width=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)
{
showStatus("Key Down");
}
public void keyReleased(KeyEvent ke)
{
showStatus("Key Up");
}
public void keyTyped(KeyEvent ke)
{
msg +=ke.getKeyChar();
repaint();
}
public void paint (Graphics g)
{
}
A. Missing {
B. Missing }
C. Missing statement
D. Missing semicolon
Answer: B
43. Consider the following program. Choose the missing statements to get correct output.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
{
List year, branch;
public void init()
{
add(new Label("Select year and branch:"));
year=new List(3);
branch=new List(5);
year.add("First Year");
year.add("Second Year");
year.add("Third Year");
add(year);
branch.add("AE");
branch.add("CO");
branch.add("EE");
branch.add("EJ");
branch.add("IF");
branch.add("ME");
add(branch);
}
public void paint(Graphics g)
{
g.drawString("You selected: "+year.getSelectedItem()+" "+branch.getSelectedItem(),10, 160);
}}
A. B.
public class Sample extends Applet implements public class Sample extends Applet implements
ItemListener ActionListener
year.addItemListener(this); year.addActionListener(this);
branch.addItemListener(this); branch.addActionListener(this);
public void itemStateChanged(ItemEvent ie) public void actionPerformed(ActionEvent ae)
{ {
repaint(); repaint();
} }
C. D.
public class Sample extends Applet implements public class Sample extends Applet implements
AdjustmentListener WindowListener
year.addAdjustmentListener(this); year.addWindowListener(this);
branch.addAdjustmentListener(this); branch.addWindowListener(this);
public void itemStateChanged(AdjustmentEvent public void windowActivated(WindowEvent we)
ae) {
{ repaint();
repaint(); }
}
Answer: A
44. Consider the following program. Find which statement contains error.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*<applet code = "PasswordAL.java" width = 600 height=600></applet>*/
public class PasswordAL extends Applet implements ActionListener
{
Button b1; String msg;
TextField t1;
public void init()
{
b1 = new Button("Click ME");
b1.addActionListener(this);
add(b1);
msg ="Wait";
t1 = new TextField(10);
t1.setEchoChar('#');
add(t1); }
public void actionPerformed()
{
String t;
t = ae.getActionCommand();
if(t.equals("Click ME") )
{
t = t1.getText();
if(t.equals("java") )
msg = "Correct";
else
msg="Wrong";
repaint();
} }
public void paint(Graphics g)
{
g.drawString(msg,200,200);
} }
A. error in the statement where ActionListener is implemented
B. error in the statement where getActionCommand is called
C. error in the statement where public void actionPerformed() method is called
D. None of the above
Answer: C
C. public class TestDemo extends JApplet D public class TestDemo extends JApplet
{ {
public void init() public void init()
{ {
JButton b = new JButton("Button"); JButton b = new JButton("Button");
Container c = getContentPane(); c.setLayout(new FlowLayout());
c.setLayout(new FlowLayout()); c.add(b);
} }
} }
Answer: A
47. Debug the following code and find which statement contains error.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class DemoAdjustmentEvent extends Applet
implements AdjustmentListener
{
Scrollbar sbRed,sbGreen,sbBlue;
public void init()
{
sbRed=new Scrollbar(Scrollbar.VERTICAL,20,10,0,255);
sbGreen=new Scrollbar(Scrollbar.VERTICAL,20,10,0,255);
sbBlue=new Scrollbar(Scrollbar.VERTICAL,20,10,0,255);
add(sbRed);add(sbGreen);add(sbBlue);
sbRed.addAdjustmentListener(this);
sbGreen.addAdjustmentListener(this);
sbBlue.addAdjustmentListener(this);
}
public void itemStateChanged(AdjustmentEvent ae)
{
int r=sbRed.getValue();
int g=sbGreen.getValue();
int b=sbBlue.getValue();
Color c=new Color(r,g,b);
setBackground(c);
}}
/*<applet codebase="DemoAdjustmentEvent.class" width=300 height=300></applet>*/
A. Error in statement were itemStateChanged( ) method is defined
B. Error in <applet> tag
C. Error in statement were Scrollbar sbRed is created
D. Both A and B
Answer: A
50. For the following code select the listener implemented by class
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/* <applet code="JRadioEvent" width=300 height=100> </applet> */
public class JRadioEvent extends JApplet implements ______________
{
ButtonGroup grp;
JRadioButton red,pioonk,green;
JTextArea ta;
public void init()
{
setLayout(new FlowLayout());
ta=new JTextArea(5,10);
setupButtons();
addListeners();
add(red);
add(pink);
add(green);
add(ta);
}
public void setupButtons()
{
red=new JRadioButton("Red");
pink=new JRadioButton("Pink");
green=new JRadioButton("Green");
grp=new ButtonGroup();
grp.add(red);
grp.add(pink);
grp.add(green);
}
public void addListeners()
{
red.addItemListener(this);
pink.addItemListener(this);
green.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
Object src=ie.getSource();
if(ie.getStateChange()==ItemEvent.SELECTED)
{
if(src==red)
ta.append("We like Redn");
else if(src==pink)
ta.append("We like Pink n");
else
ta.append("We like Green n");
} } }
A. ActionListener
B. ComponentListener
C. ItemListener
D. MouseListener
Answer: A
CHAPTER 4: Networking
Q. QUESTION
1. -------is protocol
A. netnews
B. finger
C. e-mail
D. all of the above
Answer: D
7. getAllByName() method returns an array of_____________ that represents all of the addresses
that specific host name has
A. host names
B. InetAddresses
C. ipaddresses
D. objects
Answer: B
11. If server socket is created using serversocket () constructer then which method should we use to
bind the serve socket ?
A. isbind()
B. bind()
C. bind To()
D. bind ( socketAddress host , int backlog)
Answer: D
13. In Uniform Resource Locator (URL), path is pathname of file where information is
A. Stored
B. Located
C. to be transferred
D. Transferred
Answer: A
20. Unlike User Datagram Protocol (UDP), Transmission Control Protocol (TCP) has Services which is
A. Connection Oriented
B. Connectionless
C. Connection Available
D. Connection Origin
Answer: A
23. What happens if server socket is not able to listen on specified port ?
A. The system exits gracefully with
appropriate message
B. The system will wait till port is free.
C. IOExeption is thrown when opening the
socket
D. PortOccupiedException is thrown.
Answer: C
25. When you will use this ServerSocket(int port, int que) constructor to create server socket
A. to create ServerSocket with port number
B. to create ServerSocket with port number & Ip address
C. to create ServerSocket with port number and number of incoming client queue
D. B&C
Answer: C
26. If port number is not specified in the URL, getPort() method returns _______
A. -1
B. 8080
C. 80
D. 25
Answer: A
27. If server socket is created using serversocket() constructer then which method should we use to
bind the serve socket?
A. isbind()
B. bind()
C. bindTo()
D. bind(socketAddress host , int backlog)
Answer: D
28. If you use either Telnet or FTP, which is the highest layer you are using to transmit data?
A. Application
B. Presentation
C. Session
D. Transport
Answer: A
30. In Uniform Resource Locator (URL), path is pathname of file where information is
A. Stored
B. Located
C. to be transferred
D. Transferred
Answer: A
36. For the following client side code of TCP implementation of sockets, what should be the server
side code in order to establish connection between both the machines?
import java.io.IOException;
import java.net.*;
public class Client
{
public static void main(String[] args) throws UnknownHostException, IOException
{
Socket sock=new Socket("127.0.0.1",2000);
}
}
A. B.
import java.io.IOException; import java.io.IOException;
import java.net.*; import java.net.*;
public class Server public class Server
{ {
public static void main(String[] args) public static void main(String[] args)
throws IOException throws IOException
{ {
ServerSocket ss=new ServerSocket(2000); ServerSocket ss=new ServerSocket();
Socket sock=ss.accept(); Socket sock=new Socket(2000);
System.out.println("Connection System.out.println("Connection
Established"); Established");
} }
} }
C. D.
import java.io.IOException; import java.io.IOException;
import java.net.*; import java.net.*;
public class Server public class Server
{ {
public static void main(String[] args) public static void main(String[] args)
throws IOException throws IOException
{ {
ServerSocket ss=new ServerSocket(2000); ServerSocket ss=new ServerSocket(2000);
System.out.println("Connection Socket sock=ssop.accept();
Established"); System.out.println("Connection
} Established");
} }
}
Answer: A
C. D.
URL url; None of the above
try
{
url = new URL("...");
conection = url.openConnection();
}
catch (MalFormedURLException e)
{}
Answer: A
C. D.
static InetAddress getLocalHost( ) throws All of the mentioned
UnknownHostException
Answer: D
41. In following Java program fill statement showing ***. Select any one option from given options.
class URLDemo
{
public static void main(String args[]) throws MalformedURLException
{
******************
System.out.println(""Protocol :""+netAddress.getProtocol());
System.out.println(""Port :""+netAddress.getPort());
System.out.println(""Host :""+netAddress.getHost());
System.out.println(""File :""+netAddress.getFile());
}
}
A. URL netAddress=new URL(http://www.sun.com.8080//index.html);
B. URL netAddress=new URL(http://www.sun.com.//index.html);
C. URL netAddress=new URL(http://www.sun.com//*.html);
D. URL net=new URL(http://www.sun.com.8080//index.html)
Answer: B
42. In following java program fill statement showing *****. Select any one option 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);
}
}
}
A. getByName();
B. getByName("www.msbte.com");
C. getName( );
D. getName("www.msbte.com");
Answer: B
43. In the following code, what type of protocol is Socket object "skt" uses?
import java.io.*;
import java.net.*;
public class NetClient
{
public static void main(String args[]) throws Exception
{
Socket skt = new Socket("host",88);
}
}
A. Connectionless
B. FTP
C. UDP
D. TCP
Answer: D
44. In the following program choose the correct strings from given options to pass in URL constructor
to get an output without any exception.
import java.net.*;
class URLDemo
{
public static void main(String args[]) throws 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://www.msbte.com/mainsite/index.php
b) http://www.msbte.com:80/mainsite/index.php
c) www.msbte.com/
d) www.msbte.com/mainsite/index.php
A. Only a
B. Only b
C. Either a or b
D. All
Answer: C
C. D.
Protocol: https Protocol: https
Port: -1 Port: -1
Host: www.google.com Host: www.google.com
File: /downloads File: google
Ext: https://www.google.com
Answer: B
B.
C.
D.
Answer: C
48. Select the source code to display following output.
A. B.
import java.net.*; import java.net.*;
class NetworkDemo class NetworkDemo
{ {
public static void main(String args[]) public static void main(String args[]) throws
{ UnknownHostException
InetAddress ip[]=InetAddress.getAllByName {
("www.yahoo.com"); InetAddress ip[]=InetAddress.getAllByName
for(int i=0;i<ip.length;i++) ("www.yahoo.com");
{ for(int i=0;i<ip.length;i++)
System.out.println(ip[i].getHostAddress()); {
} System.out.println(ip[i].getHostAddress());
} }
} }
}
C. D.
import java.net.*; import java.net.*;
class NetworkDemo class NetworkDemo
{ {
public static void main(String args[]) throws public static void main(String args[]) throws
UnknownHostException UnknownHostException
{ {
InetAddress ip[]=InetAddress.getByName InetAddress ip=InetAddress.getByName
("www.yahoo.com"); ("www.yahoo.com");
for(int i=0;i<ip.length;i++) System.out.println(ip[i].getHostAddress());
{ }
System.out.println(ip[i].getHostAddress()); }
}
}
}
Answer: B
50. What correction should be done in the program to get correct output?
import java.net.*;
import java.io.*;
public class URLTest
{
public static void main(String args[]) throws MalformedURLException
{
URL url = new URL("http://www.msbte.com/download");
System.out.println("Protocol:"+ url1.getProtocol());
System.out.println("Port:"+ url1.getPort());
System.out.println("Host:"+ url1.getHost());
System.out.println("File:"+ url1.getFile());
}
}
A. Exception type is wrong.
B. Class should not be public.
C. Creation of object is not correct.
D. Use of created object not correct
Answer: D
CHAPTER 5: Databases
Q. QUESTION
1. Can we retrieve a whole row of data at once, instead of calling an individual ResultSet.getXXX
method for each column ?
A. No
B. Yes
C. Statement is incorrect
D. None of the above
Answer: A
5. Identify Correct Syntax for following method of ResultSet ______ absolute (______);
A. boolean, int
B. boolean, void
C. void, int
D. void, void
Answer: A
11. Type of server in two-tier architectures which provides data to client stored on disk pages is called
A. transaction server
B. functional server
C. disk server
D. data server
Answer: D
12. What happens if you call the method close() on a ResultSet object?
A. the method close() does not exist for a
ResultSet. Only Connections can be
closed.
B. the database and JDBC resources are
released
C. you will get a SQLException, because only
Statement objects can close ResultSets
D. the ResultSet, together with the
Statement which created it and the
Connection from which the Statement
was retrieved, will be closed and release
all database and JDBC resources
Answer: B
18. Which of the Following is NOT a valid Syntax for getConnection() Method
A. public static Connection
getConnection(String url)
B. public static Connection
getConnection (String url, String
userID, String password)
C. public static Connection
getConnection(jdbc:<subprotocol>:
<subname>, String userID, String
password)
D. None of the Above
Answer: C
21. Which type of Driver communicate using a network protocol to a middleware server
A. Type 1 Driver
B. Type 2 Driver
C. Type 3 Driver
D. Type 4 Driver
Answer: C
22. ________ is an open source DBMS product that runs on UNIX, Linux and Windows.
A. MySQL
B. JSP/SQL
C. JDBC/SQL
D. Sun ACCESS
Answer: A
24. Application program interface in two tier architecture database management system is provided
by the
A. close module connectivity
B. open module connectivity
C. close database connectivity
D. open database connectivity
Answer: D
25. The _____________ method executes an SQL statement that may return multiple results.
A. executeUpdate()
B. executeQuery()
C. execute()
D. noexecute()
Answer: C
28. How will JDBC help the programmers to write java applications that manage programming
activities:
A. It helps us to connect to a data source, like a database.
B. It helps us in sending queries and updating statements to the database
C. Retrieving and processing the results received from the database in terms of answering to your
query.
D. All of Above
Answer: D
30. In DriverManager class which method is used to establish the connection with specified url
A. public static void deregisterDriver(Driver driver)
B. public static void registerDriver(Driver driver)
C. public static Connection getConnection(String url)
D. public static Connection getConnection (String url,String userName,String password)
Answer: C
31. In setXXX() methods used for Prepared-Statement the first argument specifies which value?
A. index of column
B. index of row
C. index of Question mark
D. index of Resultset
Answer: C
32. In the following JDBC drivers which is known as partially java driver?
A. JDBC-ODBC bridge driver
B. Native-API driver
C. Network Protocol driver
D. Thin driver
Answer: B
33. In three tier model, middle tier of the services acts as a mediator between _____ and _____.
A. Java applet and DBMS
B. Java application and databases
C. Data source and Application server
D. DBMS and user
Answer: B
34. In the three-tier model, commands are sent to a middle tier of services, which then send SQL
statements to the _______________
A. Client
B. Server
C. Database
D. JDBC
Answer: C
38. To execute a SELECT statement "select * from Address" on a Statement object stmt, use
A. stmt.execute("select * from Address");
B. stmt.executeQuery("select * from Address");
C. stmt.executeUpdate("select * from Address");
D. stmt.query("select * from Address");
Answer: B
41. Using JDBC you can send SQL, PL/SQL statements ___________________
A. to almost any relational database.
B. to MySQL database
C. to MSAccess
D. to Oracle
Answer: A
44. What contains object specific to database, and used to create Connection object from the
options?
A. Driver Interface / Connect()
B. ResultSet
C. Statement
D. Driver Manager
Answer: A
}
}
CHAPTER 6: Servlet
Q. QUESTION
1. _____ is the first phase of servlet life cycle
A. service
B. initialization
C. destroy
D. both ii and iii
Answer: B
3. _________ class provides functionality that makes it easy to handle requests and responses.
A. ServetRequest
B. ServletResponse
C. GenericServlet
D. None of these
Answer: C
8. A user types the URL http://www.msbte.com/result. php. Which HTTP request gets generated? Select the one
correct answer
A. GET method
B. POST method
C. HEAD method
D. PUT method
Answer: A
10. An image file representing a company's logo has to be uploaded to the server. Which of the following HTTP methods
can be used in this situation?
A. doGet()
B. doPost()
C. doTrace()
D. doPut()
Answer: D
16. For a given ServletResponse response, which retrieve an object for writing text data?
A. response.getOutputWriter()
B. response.getWriter()
C. response.getWriter().getOutputStream()
D. response.getWriter(Writer.OUTPUT_TEXT)
Answer: B
19. Given an HttpServletRequest request and HttpServletResponse response, which sets a cookie "username" with the
value "joe" in a servlet?
A. request.addCookie(new Cookie("username", "joe"));
B. response.addCookie(new Cookie("username", "joe"));
C. response.addCookie("username", "joe");
D. request.addCookie("username", "joe");
Answer: A
24. Identify the correct sequence of Steps for creation and execution of java and html file for servlet
A) Create a directory structure under Tomcat for your application. Write the servlet source code. You need to 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 web browser.
A. ABCDEF
B. ACBDEF
C. BCADEF
D. none of the above
Answer: A
25. In Session tracking which method is used in a bit of information that is sent by a web server to a browser and which
can later be read back from that browser?
A. HttpSession
B. URL rewriting
C. Cookies
D. Hidden from Fields
Answer: C
26. Which method is used to get HttpSession object and it belongs to which object?
A. getSession method and HttpServletRequest
B. getSession method and HttpServletResponse
C. getHttpSession and HttpServletResponse
D. getHttpSession and HttpServletRequest
Answer: A
28. Which method returns a servletConfig object that contains any initialization parameters?
A. servletConfig getServletConfig()
B. ServiceConfig getServlet()
C. ServiceConfig getServletConfig()
D. ServiceConfig getConfig()
Answer: B
29. Which methods are used to Extract all names and value pairs from the Http request
A. getParameter() and getParameterValues()
B. getParameter() and getParameterNames()
C. getParameterNames() and getParameterValues()
D. getParameterNameValues() and getParameter()
Answer: C
30. Which of following is not true for servlet?
A. it is persitent
B. platform independence
C. high performance
D. it is single threaded
Answer: D
31. Which of the following are class? 1.ServletContext 2.Servlet 3.GenericServlet 4.HttpServlet
A. 1,2,3,4
B. 1,2
C. 3,4
D. 1,4
Answer: C
33. Which of the following methods are main methods in life cycle of servlet?
1. init()
2. service()
3. destroy()
4.stop()
5.wait()
A. 1,2,3,4,5
B. 1,2,3
C. 3,4,5
D. 1,4,5
Answer: B
34. Sessions is a part of the session tracking and it is for maintaining the client state at server side?
(a) True
(b) False
ANSWER: A
35. In session tracking which method is used in a bit of information that is sent by a web server to a browser
and which can later be read back from that browser?
(a) HttpSession
(b) URL rewriting
(c) Cookies
(d) Hidden form fields
ANSWER: C
B.
import javax.servlet.http.*;
import java.util.*;
C.
import javax.servlet.*;
import java.util.*;
D.
import javax.servlet.http.*;
import java.io.*;
Answer: A
45. Consider the following code.Select the missing statement to get proper output.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CookEx extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
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(" ");
} }
A. req.addCookie(c);
B. res.addCookie(c);
C. addCookie(c);
D. res.addCookie();
Answer: B
responce.setContentType("text/html");
PrintWriter pw = responce.getWriter();
pw.println("<B>MyCookie has been set to");
pw.println(data);
pw.close();
}
}
A. responce.cookie(cookie);
B. responce.add(cookie);
C. responce.addCookie(cookie);
D. none of the above
Answer: C
48. Consider the following program and find out the missing statement
import javax.servlet.*;
import java.io.*;
public class image extends GenericServlet
{
public void service(ServletRequest req,ServletResponse res)throws ServletException,IOException
{
res.setContentType("image/jpeg");
pw.println("<html>");
pw.println("<img src='Sunset.jpg' width=600 height=800>");
pw.println("</html>");
}}
A. PrintWriter pw=res.getWriter();
B. Cookie pw=res.getCookies();
C. InputStream pw=res.getInputStream();
D. String pw;
Answer: A
49. In following Java program fill statement showing ***.Select any one option fro given options
import javax.servlet.*;
import javax.servlet.http.*;
public class AddCookieServlet extends HttpServlet
{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throwsServletException, IOException
{
String data = request.getParameter("data");
Cookie cookie = ***************
response.addCookie(cookie);
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B>MyCookie has been set to");
pw.println(data);
pw.close();
} }
A. new Cookie("MyCookie", dat;
B. new Cookie("MyCookie", data);
C. new Cookie("MyCookie", data2);
D. new Cookie("MyCookie", database);
Answer: B
50. In following Java program fill statement showing ******.Select any one option from given options.
import java.io.*;
import java.util.*;
import javax.servlet.*;
public class PostParametersServlet extends GenericServlet {
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
PrintWriter pw = response.getWriter();
Enumeration e = ******;
// Display parameter names and values.
while(e.hasMoreElements()) {
String pname = (String)e.nextElement();
pw.print(pname + " = ");
String pvalue = request.getParameter(pname);
pw.println(pvalue);
}
pw.close();
} }
A. request.getParameterNames();
B. request.getparameterNames();
C. Request.getParameterNames();
D. request.getParameterName();
Answer: A