UNIT 01 - Abstract Windowing Toolkit (AWT)
UNIT 01 - Abstract Windowing Toolkit (AWT)
Q. 2 Which is the container that contain title bar and can have MenuBars. It can have
other components like button, textfield etc.?
(a) Panel
(b) Frame
(c) Window
(d) Container
Answer: b
Q. 3 Which is a component in AWT that can contain another components like buttons,
textfields, labels etc.?
(a) Window
(b) Container
(c) Panel
(d) Frame
Answer:b
Q. 8 How many types of controls does AWT supports these controls are subclasses of
component?
(a) 7
(b) 6
(c) 5
(d) 8
Answer:a
Q. 9 Which are passive controls that do not support any interaction with the user?
(a) Choice
(b) List
(c) Labels
(d) Checkbox
Answer:c
Q. 11 Which class is used to create a pop‐ up list of items from which the user may
choose?
(a) List
(b) Choice
(c) Labels
(d) Checkbox
Answer:b
Q. 12 Which object can be constructed to show any number of choices in the visible
window?
(a) Labels
(b) Choice
(c) List
(d) Checkbox
Answer:c
Q. 13 Which is used to store data and partial results, as well as to perform dynamic
linking, return values for methods, and dispatch exceptions?
(a) Window
(b) Panel
(c) Frame
(d) Container
Answer:c
Q. 14 The following way is used to create a frame is by creating the object of Frame class?
(a) inheritance
(b) association
(c) Both A & B
(d) None of the above
Answer: c
Q. 15 AWT more powerful components like tables, lists, scroll panes, color chooser, tabbed
pane etc.?
(a) True
(b) False
Answer: a
Q. 17 In Graphics class which method is used to draws a rectangle with the specified width and
height?
(a) public void drawRect(int x, int y, int width, int height)
(b) public abstract void fillRect(int x, int y, int width, int height)
(c) public abstract void drawLine(int x1, int y1, int x2, int y2)
(d) public abstract void drawOval(int x, int y, int width, int height)
Answer: b
Q. 18 Implement the Listener interface and overrides its methods is required to perform in event
handling?
(a) True
(b) False
Answer: a
Q. 19 Public class MenuBar extends .
(a) MenuComponent
(b) MenuContainer
(c) ComponentMenu
(d) MenuBar
Answer: a
Q. 20. Which of the following is true about AWT and Swing components?
(a) AWT components creates a process where as swing components creates a thread
(b) AWT components creates a thread whereas swing components creates a process
(c) Both AWT and Swing components creates a process
(d) Both AWT and swing components creates a thread
Answer: c
Q. 21 Panel is defined as .
(a) The Panel class is a concrete subclass of Container.
(b) A Panel is a window that does not contain titlebar, menubar and border.
(c) Panel is a superclass of Applet.
(d) All of the above.
Answer: d
Q. 29 Which class is used to represent a single line textbox with password character
facility?
(a) TextField
(b) TextArea
(c) Label
(d) Checkbox
Answer: a
Q. 34 positions are the components into 5 regions east, west, south, north, center.
(a) CardLayout
(b) BorderLayout
(c) GridLayout
(d) FlowLayout
Answer: b
Q. 43 Which Text Component method is used to set a TextComponent to the read‐ only
state?
(a) Editable
(b) NonEditable
(c) setEchoChar
(d) setEditable
Answer:d
Q. 44 How would you set the color of 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
Q. 45 What is use of second parameter in given constructor Lable(String,int)
(a) specifies height of label
(b) specifies width of label in terms of pixel
(c) specifies the alignment of text in label in terms of pixel
(d) specifies width of label
Answer: c
Q. 47 What does the following line of code do? TextField tf = new TextField(10);
(a) will set 10 to TextField as its initial text.
(b) Will set the character capacity to 10
(c) Both A & B
(d) None of These
Answer: b
Q. 54 Which of the following does not have its default layout as BorderLayout.
(a) Frame
(b) Dialog
(c) JApplet
(d) All of Above
Answer: d
Q. 63 Which of these classes can be added to any Container class, using the add method
defined in Container class?
(a) Button
(b) CheckboxMenuItem
(c) Menu
(d) MenuBar
Answer: a
Q. 64 What is the use of setEchoChar( ) method?
(a) to set echo in symbol form
(b) to set char in symbol form
(c) Both A & B
(d) to create password in symbol form
Answer: c
Q. 70. Which of the following is a valid HTML file to run an applet program store in
MyApplet.java file?
a) <APPLET CODE = "MyApplet.class"></APPLET>
b) <APPLET CODE="MyApplet.java" WIDTH=250 HEIGHT=200>
c) <applet code="MyApplet.class" width=250 height=200></applet>
d) <applet code="MyApplet" height =”250” width =”200”></applet>
Answer: c
Q. 71. Which of the following sets the frame, say frame to 300 pixels wide by 200 high?
a)frame.setSize( 300, 200 );
b) frame.setSize( 300, 200 );
c) frame.paint( 300, 200);
d)frame.setVisible(300, 200 );
Answer: a
Q. 73. What is the length of the application box made by this program?
Import java.awt.*;
Import java.applet.*;
public class myapplet extends Applet
{
public void paint(Graphics g)
{
g.drawString("A Simple Applet", 20, 20);
}
}
a)20
b) 50
c)100
d)System Dependent
Answer: a
Chapter 02 – Swings
Q. 2 Swing is not a part of JFC (Java Foundation Classes) that is used to create GUI
application?
(a) True
(b) False
Answer:b
Q. 3 The Swing Component classes that are used in Encapsulates a mutually exclusive set of
buttons?
(a) AbstractButton
(b) ButtonGroup
(c) JButton
(d) ImageIcon
Answer: b
Q. 4 The Java Foundation Classes (JF(c) is a set of GUI components which simplify the
development of desktop applications?
(a) True
(b) False
Answer: a
Q. 25. The scroll bar constants for scroll pane are defined in
a) Scrollbar class
b) ScrollPane class
c) ScrollPaneConstants interface
d) Component class
Answer: c
Q. 26. Which of the following constants shows scroll bars always?
a) HORIZONTAL_SCROLLBAR_ALWAYS
b) HORIZONTAL_SCROLLBAR_AS_NEEDED
c) HORIZONTAL_SCROLLBARS
d) HORIZONTAL_ALWAYS
Answer: a
Q. 32. Which two parameters are required for JTree constructor to create a tree?
a) Data array and Row Headings
b) Data array and Column Headings
c) Single data element and Column heading
d) Single data element and Row heading
Answer: b
Q. 33. How to create for Vector elements?
a) Pass vector as parameter for JTree
b) Use method addElements( ) for JTree class.
c) Use method addVector( ) method of JComponent class
d) It is not possible
03 – Event Handling
Q. 1. The Following steps are required to perform Implement the Listener interface and
overrides its methods Register the component with the Listener
(a) Exception Handling
(b) String Handling
(c) Event Handling
(d) None of the above
Answer: c
Q. 3 Which package provides many event classes and Listener interfaces for event
handling?
(a) java.awt
(b) java.awt.Graphics
(c) java.awt.event
(d) None of the above
Answer: c
Q. 6 The ActionListener interface is used for handling action events, For example, it's
used by a
(a) JButton
(b) JCheckbox
(c) All of these
(d) JMenuItem
Answer: c
Q. 7 Which class is used for this Processing Method processActionEvent( )?
(a) Button,List,MenuItem
(b) Button,Checkbox,Choice
(c) Scrollbar,Component,Button
(d) None of the above
Answer: a
Q. 8 In Graphics class Which method is used to set the graphics current color to the
specified color?
(a) public abstract void setFont(Font font)
(b) public abstract void setColor(Color c)
(c) public abstract void drawString(String str, int x, int y)
(d) None of the above
Answer: b
Q. 9 Which of the following method is used to determine the type of adjustment event?
(a) getType( )
(b) getEventType( )
(c) getAdjustmentType( )
(d) getEventObjectType( )
Answer: c
Q. 16 Name the method defined in EventObject class that returns the object generated
from the event.
(a) getEvent( )
(b) getObject( )
(c) getId( )
(d) getSource( )
Answer: d
Q. 18 ActionEvent is applied on
(a) Frame
(b) Checkbox, Choice, List
(c) Scrollbar
(d) Button, TextField, List, Menu
Answer: d
Q. 25 When we need to use Checkbox or Item from the list or use a checkable Menu an is
generated.
(a) ActionEvent
(b) ItemEvent
(c) MenuEvent
(d) ClickEvent
Answer: b
Q. 30 Which of this package contains all the classes and methods required for event
handling in Java.
(a) java.applet
(b) java.awt
(c) java.event
(d) java.awt.event
Answer: d
Q. 34 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
Q. 35 Which of the following method must be overridden in the order to handle KeyEvent.
(a) keyPressed(KeyEvent obj)
(b) KeyReleased(KeyEvent obj)
(c) KeyTyped(KeyEvent obj)
(d) All of these
Answer: d
Q. 36 Which of these methods can be used to know the degree of adjustment made by
the user?
(a) getValue( )
(b) getAdjustmentType( )
(c) getAdjustmentValue( )
(d) getAdjustmentAmount( )
Answer: c
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*<applet code="combodemo" width=300 height=100>
</applet> */
public class combodemo extends JApplet implements itemListener
{
JLabel jl;
Image Iconfrance, germany, italy, japan;
public void init(){
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
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 + ".gif"));
}
}
Q. 45. Select the missing statement in the program for following output
import java.awt.*;
public class MenuDemo 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 viewmenu = new Menu("View");
mbr.add(filemenu); mbr.add(editmenu);
MenuItem new1 = new MenuItem("New");
MenuItem open1 = new MenuItem("Open");
filemenu.add(new1);
filemenu.add(open1);
}
}
A. mbr.add(view);
B. mbr.add(menu);
C. mbr.add(vieweditmenu);
D. mbr.add(viewmenu);
Q.46. 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();
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg, X, Y);
}
}
a) Missing Semicolon
b) }
c) {
d) ()
Q.47.For the following code select the method that can be used to handle event.
importjava.awt.event.*;
import java.awt.*;
importjava.applet.*;
public class checkbackg extends Applet implements ItemListener
{
Checkbox m1,m2,m3;
public void init()
{
m1=new Checkbox("A");
m2=new Checkbox("B");
m3=new
Checkbox("C");
add(m1);
add(m2);
add(m3);
m1.addItemListener(this);
m2.addItemListener(this);
}
public void (ItemEvent ie)
{
if(ie.getSource()==m1)
setBackground(Color.red);
if(ie.getSource()==m2)
setBackground(Color.green);
}
}
/*<applet code=checkbackg.class height=150 width=150>
</applet>*/
a) actionPerformed(ActionEvent ae)
b) itemStateChanged(ActionEvent ie)
c) itemStateChanged(ItemEvent ie)
d) adjustmentPerformed(AdjustmentEvent ae)
UNIT 4 NETWORKING
Q. 1 UDP stands for
(a) User Data Port
(b) User Datagram Protocol
(c) Used Data Provider
(d) User Data Protocol
Answer: b
Q. 2 Name the class which is used to create a port where the server will listen.
(a) Server
(b) Socket
(c) ServerSocket
(d) SocketServer
Answer: b
Q. 12 The class which encapsulates both the numerical IP address and the domain name
for that address is .
(a) DatagramPacket
(b) DatagramSocket
(c) InetAddress
(d) ServerSocket
Answer: c
Q. 13 int getServerPort( ) method
(a) returns the port number on which this request was received.
(b) returns the port name on which the request was received.
(c) returns the server number on which this request was received.
(d) returns the port number on which this response/request was received.
Answer: d
Q. 14 In this constructor ServerSocket(int port, int max_queue) what is the default value
for max_queue?
(a) 100
(b) 50
(c) 75
(d) 80
Answer: b
Answer: a
Q. 19 What value is returned by the readLine( ) method when it reach at End of File?
(a) EOF
(b) null
(c) 0
(d) END
Answer: b
Q. 21 Which method of ServerSocket will wait for a client to initiate communication and
then communication with the client?
(a) wait( )
(b) connect( )
(c) waitForClient( )
(d) WaitForConnect( )
Answer: b
Q. 29 If a program consists of three classes, then after compilation how many class files
will be created by the compiler?
(a) one
(b) three
(c) uncountable
(d) zero
Answer: b
Q. 34 Name the class which is used to create a port where the server will listen?
(a) Server
(b) Socket
(c) ServerSocket
(d) SocketServer
Answer: b
Q. 37 Which is the proper method to retrieve the host name of local machine?
(a) static InetAddress getLocalHost( ) throws UnknownHostException
(b) static InetAddress getByName(String host_name ) throws UnknownHostException
(c) static InetAddress getAllByName(String host_name ) throws UnknownHostException
(d) String getHostAddress( )
Answer: a
In JDBC imports all Java classes that are concern with Database connectivity.
(a) javax.sql
(b) java.mysql
(c) java.sql
(d) com.sql
Answer: c
In the below statement, which type of query can be used with executeUpdate( ) method.
statement.executeUpdate(query here)
(a) Insert, Update, Delete
(b) Insert, Select, Delete
(c) Only Select
(d) Any Query
Answer: a
How many steps are used to connect any java application with the database using JDBC
?
(a) 5
(b) 4
(c) 3
(d) 6
Answer: a
Which method executes an SQL statement that may return multiple results?
(a) executeUpdate( )
(b) executeQuery( )
(c) execute( )
(d) noExecute( )
Answer: b
Which of the following function is used to find the column count of the particular
ResultSet.
(a) getMetadata( )
(b) metadata( )
(c) getColumnCount( )
(d) getCount( )
Answer: c
The JDBC‐ ODBC bridge supports how many concurrent open statements per
connection ?
(a) 1
(b) 0
(c) Does not support connection
(d) None of these
Answer: a
Which of the following is used generally for reading the content of the database?
(a) DabaseData
(b) DabaseData
(c) ResultSet
(d) DatabaseResult
Answer: c
Q. 11 is a small piece of information that is passed back & forth in HTTP request &
response.
(a) Servlet
(b) Applet
(c) Cookie
(d) Session
Answer: c
Q. 14 Apache Tomcat is .
(a) Servlet
(b) Java Program
(c) API
(d) Web server capable of running Java programs
Answer: d
Q. 21 Which method is used to specify before any lines that used the PrintWriter?
(a) setPageType( )
(b) setContextType( )
(c) setContentType( )
(d) setResponseType( )
Answer: c
Q. 23 The following methods belongs to the life cycle methods of the servlet.
(a) init( )
(b) service( )
(c) destroy( )
(d) All of the above
Answer: d
Q. 24 Java servlet
(i) is a key component of the server side java development.
(ii) is a small pluggable extension to a server that enhances functionality
(iii) runs only in windows OS
(iv) allows developers to customize any java enabled server
(a) i, ii and iii are true
(b) i,iii and iv are true
(c) ii,iii and iv are true
(d) i,ii and iv are true
Answer: d
Q. 31 Which class provides stream to read binary data such as image et(c) from the
request object?
(a) ServletInputStream
(b) ServletOutputStream
(c) Both a & b
(d) None of the above
Answer: a
Q. 34 Difference between doGet() and doPost() methods is . Select any of given options
A. In doGet() the parameters are appended to the URL and sent along with header information.
B. In doPost(),will send the information through a socket back to the webserver and it won't show
up in the URL bar.
C. doGet () is a request for information;
D. doPost() provides information (such as placing an order) that the server is expected to
remember
(a) All above are valid differences
(b) Only A and B
(c) Only C and D
(d) A, B, C are valid differences.
Q. 36. 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", data);
B. new Cookie("MyCookie", data1);
C. new Cookie("MyCookie", data2);
D. new Cookie("MyCookie", database);
Q. 37.Consider the following program. Identify the exception that might be thrown
import java.net.*;
class URLDemo
{
public static void main(String args[]) throws
{
URL netAddress= new URL(“http://www.sun.com:8080//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());
}
}
A. IoException
B. MalformedURLException
C. Arithmetic Exception
D. UnknownHostException
Q. 38. Consider the following program. Identify the missing statement from the output.
import java.net.*; class URLDemo
{
public static void main(String args[]) throws MalformedURLException
{
URL netAddress= new URL(“http://www.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());
}
}
Output of the Program
Protocol :http
Host :www.sun.com File :/index.html
A. Port :8080
B. Port :1024
C. Port: -1
D. None of the above
Q. 39. Consider the following program and identify the missing statement.
class URLDemo
{
public static void main(String args[]) throws MalformedURLException
{
URL netAddress= new URL("http://www.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());
}
}
A. Missing semicolon
B. Missing package statement
C. Missing initialization
D. None of the above