0% found this document useful (0 votes)
9 views

AJP MCQ Question Bank

Uploaded by

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

AJP MCQ Question Bank

Uploaded by

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

12/4/2019 https://localhost/dashboard/ques_ans_22517.

php

Java Question
Question) Which package is required for an adapter classes?

A) java.awt.event B) java.lang C) java.util D) java.swing Answer - java.awt.event

Question) An adapter class provides an empty implementation of all methods in an __________________ .

A) inheritance B) class C) Class ,Object D) event listener interface Answer - event listener
interface

Question) Which one of the following is adapter class?

A) WindowAdapter B) KeyAdapter C) MouseAdapter D) All the above Answer - All the above

Question) What is the output of following code? import java.awt.Frame; import


java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class FrameClosing2 extends
Frame { public FrameClosing2() { CloseMe cm = new CloseMe(); addWindowListener(cm); setTitle("Frame
closing Style 2"); setSize(300, 300); setVisible(true); } public static void main(String args[]) { new
FrameClosing2(); } } class CloseMe extends WindowAdapter { public void windowClosing(WindowEvent e) {
System.exit(0); } }

A) B) C) D) Answer -

Question) _________ class have the KeyListerner interface.

A) KeyListernerAdapter B) KeyAdapter C) Adapter D) None Answer - KeyAdapter

Question) Write correct word at blank spaces. f.addWindowListener(new _____________ { public void
windowClosing(WindowEvent e) { System.exit(0); } ________

A) } and ); B) WindowAdapter() and }); C) KeyAdapter() and }); D) Window and ; Answer -
WindowAdapter() and });

Question) Identify the correct adapter name and event name. public class MyFocusListener extends
_______________ { public void focusGained(_________________ fe) { Button button = (Button)
fe.getSource(); label.setText(button.getLabel()); } }

A) Focusevent, Focusadapter B) FocusAdapter, Event C) FocusAdapter, FocusEvent D) Adapter,


FocusEvent Answer - FocusAdapter, FocusEvent

Question) Adapter classes are an ____________class for receiving various events.

A) Abstract B) Inner C) Inline D) Inherited Answer - Abstract

Question) Adapter classes are used to create _________objects.

A) Class B) Method C) Package D) Listener Answer - Listener

Question) Identify the class which is not an adapter class?

A) KeyAdapter B) FocusAdapter C) ItemAdapter D) MouseMotionAdapter Answer - ItemAdapter

https://localhost/dashboard/ques_ans_22517.php 1/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Adapter classes are used to ___________ the process of event handling.

A) solve B) simplify C) avoid D) create Answer - simplify

Question) An _________ class listener interface and Event class Listener interface has same name.

A) adapter B) Static C) Inner D) Super Answer - adapter

Question) ____________is a subclass of ComponentEvent.

A) InputEvent B) ContainerEvent C) TextEvent D) WindowEvent Answer - ContainerEvent

Question) An adapter class provides an _________ implementation of all methods in an event listener
interface.

A) pluggable B) simple C) empty D) Interface Answer - empty

Question) Which of the following method does not belongs to WindowListerner interface?

A) windowActivated B) windowClosed C) windowClosing D) windowReactivated Answer -


windowReactivated

Question) Which of the following method is invoked when a window is changed from a normal to a
minimized state?

A) windowActivated() B) windowClosed() C) windowClosing() D) windowIconified() Answer -


windowIconified()

Question) What is adapter class for component listener interface?

A) Component B) ComponentAdapter C) ComponentListenerAdapter D) None Answer -


ComponentAdapter

Question) Whether adapter classes use the methods of event classes?

A) Yes B) No C) Sometimes D) Depends on some requirement Answer - Yes

Question) Which of these methods is defined in MouseMotionAdapter class?

A) mouseDragged() B) mousePressed() C) mouseReleased() D) mouseClicked() Answer -


mouseDragged()

Question) Which of these is a superclass of all Adapter classes?

A) Applet B) ComponentEvent C) Event D) InputEvent Answer - Applet

Question) If an adapter class is inherited , there is no need of implementing all the methods of listener
interfaces .

A) Sometimes B) Never C) always D) None Answer - always

Question) Adapter class can be also used for incorporating ___________property of JAVA.

A) Inheritance B) Polymorphism C) Encapsulation D) All of the above Answer - Encapsulation

https://localhost/dashboard/ques_ans_22517.php 2/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) In Adapter class it is sufficient to include only the methods required to override.

A) True B) False C) Sometimes D) Never Answer - True

Question) Adapter class makes programmers task easier .

A) Sometime B) True C) False D) Never Answer - True

Question) Filling the blank. this.addComponentListener(new ______________________ { public void


componentShown(ComponentEvent evt) { System.out.println("componentShown"); } });

A) Component() B) componentadapter() C) ComponentAdapter() D) ContainerAdapter() Answer -


ComponentAdapter()

Question) What is the output of following code? import java.awt.*; import java.awt.event.*; import
java.applet.*; /*<applet code="AdapterDemo" width=300 height=100> </applet> */ public class
AdapterDemo extends Applet { public void init() { addMouseListener(new MyMouseAdapter(this)); } } class
MyMouseAdapter extends MouseAdapter { AdapterDemo adapterDemo; public
MyMouseAdapter(AdapterDemo adapterDemo) { this.adapterDemo = adapterDemo; } // Handle mouse
clicked. public void mouseClicked(MouseEvent me) { adapterDemo.showStatus("Mouse clicked"); } }

A) Mouse moved B) Mouse dragged C) Mouse pressed D) Mouse clicked Answer - Mouse
clicked

Question) _____________is a superclass of ContainerEvent .

A) ComponentEvent B) WindowEvent C) InputEvent D) MouseMotionEvent Answer -


ComponentEvent

Question) In an adapter class program, if it contains 5 methods, how many methods are to be overriden?

A) 1 B) 2 C) 4 D) 5 Answer - 5

Question) Which is the abstract adapter class for receiving keyboard focus events.

A) FocusListener B) FocusAdapter C) AdapterFocus D) AdapterListerner Answer -


FocusAdapter

Question) Adapter Class and interfaces are same.

A) Sometimes B) Never C) True D) False Answer - False

Question) Adapter class saves _________.

A) Time B) Code C) Space D) All of the above Answer - All of the above

Question) Following are the integer constants which does not belong to ComponentEvent class .

A) COMPONENT_HIDDEN B) COMPONENT_ICONIFIED C) COMPONENT_MOVED D)


COMPONENT_SHOWN Answer - COMPONENT_ICONIFIED

Question) __________ is a superclass of all AWT events that are handled by the delegation event model.

A) AWTEvent B) Event C) UtilityEvent D) AWT Answer - AWTEvent

https://localhost/dashboard/ques_ans_22517.php 3/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) A class which adapts methods of another class by giving different names to essentially the same
methods is called as __________.

A) Inner Class B) Simple Class C) Adapter Class D) Inherited Class Answer - Adapter Class

Question) If a class MyWindowAdapter extends WindowAdapter and implements the windowClosing()


method. How to register this class?

A) this.addWindowListener(new MyWindowAdapter()); B) this.addWindow(new MyWindowAdapter()); C)


this.addWindowAdapter(new MyWindowAdapter()); D) this.addWindowWindow(new
MyWindowAdapter()); Answer - this.addWindowListener(new MyWindowAdapter());

Question) Commonly used methods of CardLayout class are____________

A) public void next(Container parent) B) public void previous(Container parent) C) public void
first(Container parent) D) all the above Answer - all the above

Question) Java allows a programmer to write a class within another class,is called as _______________ .

A) Abstract Class B) Inner Class C) Derived Class D) Simple Class Answer - Inner Class

Question) What are the different types of inner classes ?

A) Local B) Anonymous C) Both A & B D) None Answer - Both A & B

Question) Fill the proper name of class. import java.awt.*; import java.awt.event.*; import java.applet.*; /*
<applet code="AdapterDemo" width=300 height=100> </applet> */ public class AdapterDemo extends
Applet { public void init() { addMouseListener(new MyMouseAdapter(this)); } } class MyMouseAdapter
extends MouseAdapter { _________________ adapterDemo; public MyMouseAdapter(AdapterDemo
adapterDemo) { this.adapterDemo = adapterDemo; } // Handle mouse clicked. public void
mouseClicked(MouseEvent me) { adapterDemo.showStatus("Mouse clicked"); } }

A) AdapterDemo B) adapterdemo C) AdapterDemo1 D) Adapter Answer - AdapterDemo

Question) Generates _____________ when the user enters a character.

A) Text Event B) Character Event C) Label Event D) TextField Event Answer - Text Event

Question) MouseWheelEvent defines integer constants.

A) WHEEL_BLOCK_SCROLL,WHEEL_UNIT_SCROLL B) BLOCK_SCROLL,UNIT_SCROLL C)
WHEEL_SCROLL,BLOCK_SCROLL D) WHEEL_PAGE_SCROLL,WHEEL_TRACK_SCROLL
Answer - WHEEL_BLOCK_SCROLL,WHEEL_UNIT_SCROLL

Question) What is the return type of isTemporary( ) method?

A) int B) Long C) String D) boolean Answer - boolean

Question) The abstract class ______________ is a subclass of ComponentEvent and is the superclass for
component input events.

A) FocusEvent B) InputEvent C) WindowEvent D) TextEvent Answer - InputEvent

https://localhost/dashboard/ques_ans_22517.php 4/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Inner class can access all the members of outer class including_________ data members and
methods.

A) Private B) Public C) Protected D) Static Answer - Private

Question) ____________________can be achieved by using Inner Class.

A) Code Extension B) Code Inheritance C) Code Optimization D) Code Development Answer -


Code Optimization

Question) The __________method returns the object that generated the event.

A) Adjustable( ) B) getModifiers( ) C) getAdjustable( ) D) getAdjust( ) Answer - getAdjustable( )

Question) ________ is a class which is declared inside the class or interface.

A) Inner Class B) Inherited Class C) Nested Interfaces D) Static Class Answer - Inner Class

Question) To handle any events of mouse, you must implement following interfaces.

A) MouseListener, MouseMotionListener, MouseWheelListener B) MouseListener, MouseWheelListener


C) MouseMotionListener, MouseWheelListener D) MouseListener Answer - MouseListener,
MouseMotionListener, MouseWheelListener

Question) The _________method returns a reference to the component that was added to or removed from
the container.

A) getParent( ) B) get( ) C) getTime( ) D) getChild( ) Answer - getChild( )

Question) A class that have no name is known as_______________ inner class in java.

A) Anonymous B) Local C) Nested D) Static Answer - Anonymous

Question) Which are two ways to create Java Anonymous inner class ?

A) Class,Interface B) Class,Object C) Interface,Object D) Class,Constructor Answer -


Class,Interface

Question) Which event is generates, when button is pressed?

A) TextEvent B) ItemEvent C) InputEvent D) ActionEvent Answer - ActionEvent

Question) Which event is generates when checkable menu item is selected or deselected?

A) ActionEvent B) InputEvent C) ItemEvent D) TextEvent Answer - ItemEvent

Question) If you compile a file containing inner class how many .class files are created ?

A) 1 B) 4 C) 3 D) 2 Answer - 2

Question) When a component is added to and removed from a container, ____________ event generates.

A) ComponentEvent B) WindowEvent C) FrameEvent D) ContainerEvent Answer -


ContainerEvent

https://localhost/dashboard/ques_ans_22517.php 5/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) What is the output of the following code :- class TestMemberOuter1 { private int data=30; class
Inner{ void msg(){System.out.println("data is "+data);} } void display() { Inner in=new Inner(); in.msg(); }
public static void main(String args[]) { TestMemberOuter1 obj=new TestMemberOuter1(); obj.display(); } }

A) error B) data is Null C) data is 30 D) data is 0 Answer - data is 30

Question) The AdjustmentEvent class defines integer constants.

A) ALT, CTRL, META, and/or SHIFT B) BLOCK_DECREMENT, BLOCK_INCREMENT,TRACK C) ALT,


CTRL, UNIT_INCREMENT,UNIT_DECREMENT D) UNIT_INCREMENT,UNIT_DECREMENT,SHIFT
Answer - BLOCK_DECREMENT, BLOCK_INCREMENT,TRACK

Question) Since Nested class is a member of its enclosing class Outer, you can use __________ notation
to access Nested class and its members.

A) ->(arrow) B) .(dot) C) * (asterisk) D) &(ampersand) Answer - .(dot)

Question) Inner classes provides______________ mechanism in Java.

A) Safety B) Protection C) Security D) Risk Handling Answer - Security

Question) ItemEvent class defines the integer constants.

A) DESELECT,SELECT B) DESELECTED,SELECTED C) ENABLED,NOTENABLED D) CHECKED,


UNCHECKED Answer - DESELECTED,SELECTED

Question) The non-static nested classes are also known as _______________ .

A) event class B) class C) adapter classes D) inner classes Answer - inner classes

Question) Inner class mainly used for _________________ .

A) for Code Optimization B) to access all the members C) to develop more readable and maintainable
code D) all of these Answer - all of these

Question) Can outer Java classes access inner class private members?

A) No B) Sometimes C) Yes D) Never Answer - Yes

Question) What is the output of following? import java.applet.*; import java.awt.event.*; /* <applet
code="InnerClassDemo" width=200 height=100> </applet> */ public class InnerClassDemo extends Applet {
public void init() { addMouseListener(new MyMouseAdapter()); } class MyMouseAdapter extends
MouseAdapter { public void mousePressed(MouseEvent me) { showStatus("Mouse Pressed"); } } }

A) Mouse Clicked B) Mouse Moved C) Mouse Dragged D) Mouse Pressed Answer - Mouse
Pressed

Question) Fill in the blanks. import java.applet.*; import java.awt.event.*; /* <applet code="InnerClassDemo"
width=200 height=100> </applet> */ public class InnerClassDemo extends Applet { public void init() {
__________ (new MyMouseAdapter()); } class MyMouseAdapter extends _________________ { public
void mousePressed(MouseEvent me) { showStatus("Mouse Pressed"); } } }

A) addMouse, Adapter B) addMouseListener, Adapter C) addMouseListener, MouseAdapter D)


addListener, MouseAdapter Answer - addMouseListener, MouseAdapter

https://localhost/dashboard/ques_ans_22517.php 6/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) What is the output of the following java program? class Outer { void outerMethod() {
System.out.println("inside outerMethod"); // Inner class is local to outerMethod() class Inner { void
innerMethod() { System.out.println("inside innerMethod"); } } Inner y = new Inner(); y.innerMethod(); } } class
MethodDemo { public static void main(String[] args) { Outer x = new Outer(); x.outerMethod(); } }

A) inside innerMethod inside outerMethod B) inside outerMethod inside innerMethod C) inside


innerMethod inside innerMethod D) inside outerMethod inside outerMethod Answer - inside
outerMethod inside innerMethod

Question) Identify the correct adapter name and event name. class MyWindowAdapter extends
________________ { public void windowClosing(_____________ e) { System.exit(0); } }

A) Window, WindowEvent B) WindowAdapter, Window C) WindowAdapter, WindowEvent D) Adapter,


Event Answer - WindowAdapter, WindowEvent

Question) In the following code, what is the name of the inner class? Public class Periodical { long ISBN;
public class Book { public long getISBN() { retrun ISBN; } } }

A) getISBN B) Periodical C) ISBN D) Book Answer - Book

Question) Identify the type of class for following code? import java.applet.*; import java.awt.event.*; /*
<applet code="Demo" width=300 height=100> </applet> */ public class Demo extends Applet { public void
init() { addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent me) {
showStatus("Mouse Pressed"); } }); } }

A) Inner Class B) Adapter class C) Anonymous Inner Class D) static class Answer - Anonymous
Inner Class

Question) In case of _______ we can implement only required methods of any interface.

A) interface B) package C) adapter classes D) event classes Answer - adapter classes

Question) The ___________ method returns a value that indicates which modifier keys were pressed when
the event was generated.

A) getModifiers( ) B) getAdjustable( ) C) Modifiers( ) D) Adjustable( ) Answer - getModifiers( )

Question) getLocalHost() method simply returns the InetAddress object which represents______________

A) host name B) machine name C) local host D) remote host Answer - local host

Question) The getByName() method returns an ________________ with host name

A) IP address B) InetAddress Object C) port number D) IPv4 Answer - IP address

Question) 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 - InetAddresses

Question) what is the output of following program import java.net.*; class Demo { public static void
main(String arg[]) throws UnknownHostException { InetAddress ipa=InetAddress.getLocalHost();
System.out.println(ipa); } }

https://localhost/dashboard/ques_ans_22517.php 7/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) host name/IP address B) iPAddress/Host name C) IPAddress D) Host name Answer - host
name/IP address

Question) Which type of Statement can execute parameterized queries?

A) ParameterizedStatement B) PreparedStatement C) ParameterizedStatement and CallableStatement


D) All kinds of Statements Answer - PreparedStatement

Question) How can you retrieve information from a ResultSet?

A) By invoking the method get(String type) on the ResultSet, where type is the database type B) By
invoking the method get(Type type) on the ResultSet, where Type is an object which represents a database
type C) By invoking the method getValue(), and cast the result to the desired Java type D) By invoking
the special getter methods on the ResultSet: getString(), getBoolean(), getClob() Answer - By
invoking the special getter methods on the ResultSet: getString(), getBoolean(), getClob()

Question) Which type of statement can execute parameterized queries ?

A) PreparedStatement B) ParameterizedStatement C) CallableStatement D) All of the Above


Answer - PreparedStatement

Question) What is the meaning of ResultSet.TYPE_SCROLL_INSENSITIVE

A) This means that the ResultSet is insensitive to scrolling B) This means that the Resultset is sensitive to
scrolling, but insensitive to updates, i.e. not updateable C) This means that the ResultSet is sensitive to
scrolling, but insensitive to changes made by others D) The meaning depends on the type of data source,
and the type and version of the driver you use with this data source Answer - This means that the
ResultSet is sensitive to scrolling, but insensitive to changes made by others

Question) What statements are correct about JDBC transactions

A) A transaction is a set of successfully executed statements in the database B) A transaction is finished


when commit() or rollback() is called on the Connection object C) A transaction is finished when commit()
or rollback() is called on the Transaction object D) A transaction is finished when close() is called on the
Connection object Answer - A transaction is finished when close() is called on the Connection
object

Question) 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 - the database and JDBC resources are released

Question) What happens if you call deleteRow() on a ResultSet object?

A) The row you are positioned on is deleted from the ResultSet, but not from the database. B) The row you
are positioned on is deleted from the ResultSet and from the database C) The result depends on whether
the property synchronizeWithDataSource is set to true or false. D) You will get a compile error: the method
does not exist because you can not delete rows from a ResultSet. Answer - The row you are
positioned on is deleted from the ResultSet and from the database

https://localhost/dashboard/ques_ans_22517.php 8/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) What is correct about DDL statements

A) DDL statements are treated as normal SQL statements, and are executed by calling the execute()
method on a Statement B) To execute DDL statements, you have to install additional support files C) DDL
statements can not be executed by making use of JDBC, you should use the native database tools for this
D) Support for DDL statements will be a feature of a future release of JDBC Answer - DDL
statements are treated as normal SQL statements, and are executed by calling the execute() method
on a Statement

Question) Which of the following statements is false as far as different type of statements is concern in
JDBC?

A) Regular Statement B) Prepared Statement C) Callable Statement D) Interim Statement


Answer - Interim Statement

Question) JDBC facilitates to store the java objects by using which of the methods of Prepared Statement 1.
setObject () 2. setBlob() 3. setClob()

A) 1, 2 B) 1, 2,3 C) 1,3 D) 2,3 Answer - 1, 2,3

Question) _______method to establish actual database connection.

A) executeQuery() B) executeUpdate() C) getConnection() D) prepareCall() Answer -


getConnection()

Question) Which of the following describes the correct sequence of the steps involved in making a
connection with a database. 1. Loading the driver 2. Process the results. 3. Making the connection with the
database. 4. Executing the SQL statements.

A) 1,3,4,2 B) 1,2,3,4 C) 2,1,3,4 D) 4,1,2,3 Answer - 1,3,4,2

Question) Which method is used to perform DML statements in JDBC?

A) execute() B) executeQuery() C) executeUpdate() D) executeResult() Answer -


executeUpdate()

Question) 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 - Yes

Question) Are Prepared Statements actually compiled?

A) Yes B) No C) Statement is incorrect D) None of the above Answer - Yes

Question) In order to transfer data between a database and an application written in the Java programming
language, the JDBC API provides which of these methods?

A) Methods on the ResultSet class for retrieving SQL SELECT results as Java types. B) Methods on the
PreparedStatement class for sending Java types as SQL statement parameters. C) Methods on the
CallableStatement class for retrieving SQL OUT parameters as Java types. D) All mentioned above
Answer - All mentioned above

Question) _________calls get converted into native c or c++ API calls.

https://localhost/dashboard/ques_ans_22517.php 9/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) API B) ODBC C) JDBC API D) None of the above. Answer - JDBC API

Question) Which method Drops all changes made since the previous commit/rollback?

A) public void rollback() B) public void commit() C) public void close() D) public Statement
createStatement() Answer - public void rollback()

Question) Which of the following is used to set the maximum number of rows can contain?

A) setMaxRows(int i) B) setMinRows(int i) C) getMaxrows(int i) D) getMinRows(int i) Answer -


setMaxRows(int i)

Question) ____method of ResultSet is used to move the cursor to the row next from the current position.

A) fetch method B) current method C) next method D) access method Answer - next method

Question) Which of the following encapsulates an SQL statement which is passed to the database to be
parsed, compiled, planned and executed?

A) DriverManager B) JDBC driver C) Connection D) Statement Answer - Statement

Question) The interface ResultSet has a method, getMetaData(), that returns a/an

A) Tuple B) Value C) Object D) Result Answer - Object

Question) Which method is used to find the number of column in ResultSet?

A) getNumberOfColumn() B) getMaxColumn() C) getColumnCount() D) getColumns() Answer -


getColumnCount()

Question) commit() method is belongs to which interface?

A) ResultSet B) Statement C) PreparedStatement D) Connection Answer - Connection

Question) Which one is the correct syntax for creating a Statement?

A) Statement stmt = connection.createStatements(); B) Statement stmt = connection.preparedStatement();


C) Statement stmt = connection.createStatement(); D) none of these Answer - Statement stmt =
connection.createStatement();

Question) Which statement is correct?

A) ResultSet rs = stmt.selectQuery("SELECT ROLLNO,STUDNAME FROM STUDENT"); B) ResultSet rs


= stmt.executeSelect("SELECT ROLLNO,STUDNAME FROM STUDENT"); C) ResultSet rs =
stmt.executeUpdate("SELECT ROLLNO,STUDNAME FROM STUDENT"); D) ResultSet rs =
stmt.executeQuery("SELECT ROLLNO,STUDNAME FROM STUDENT"); Answer - ResultSet rs =
stmt.executeQuery("SELECT ROLLNO,STUDNAME FROM STUDENT");

Question) INSERT, DELETE, UPDATE comes under ?

A) Data Modification Language B) Data Definition Language C) Data Control Language D) Data
Manipulation Language Answer - Data Manipulation Language

Question) The return type of execute(String query) is?

https://localhost/dashboard/ques_ans_22517.php 10/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) int B) ResultSet C) boolean D) void Answer - boolean

Question) Consider the following program. Select the missing statement in given code import java.sql.*;
class PreparedExample{ public static void main(String args[]){ try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:snrao","scott","tiger"); PreparedStatement
stmt=con.prepareStatement("select * from student where rollno=?)"); stmt.setInt(1,1); -----------------------------
------------- while(rs.next()) {} con.close(); }catch(Exception e){ System.out.println(e);} } }

A) stmt.setString(2,"Ratan"); B) int i=stmt.executeQuery(); C) ResultSet rs=stmt.executeQuery(); D)


ResultSet rs=stmt.executeQuery("select * from student”); Answer - ResultSet
rs=stmt.executeQuery();

Question) Consider the following code. To execute the query, which of the following code snippet is used?
String sql = "update people set firstname=? , lastname=? where id=?"; PreparedStatement
preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, "Gary");
preparedStatement.setString(2, "Larson"); preparedStatement.setLong (3, 123);

A) int rowsAffected = preparedStatement.executeUpdate(); B) ResultSet


rs=preparedStatement.executeQuery(sql); C) int rowsAffected = preparedStatement.executeQuery(sql);
D) ResultSet rs=preparedStatement.executeUpdate(); Answer - int rowsAffected =
preparedStatement.executeUpdate();

Question) which method is used to insert image in database

A) statement.getImage() B) statement.getDouble() C) statement.getBLOB() D) statement.getIcon()


Answer - statement.getBLOB()

Question) All raw data types (including binary documents or images) should be read and uploaded to the
database as an array of

A) byte B) int C) char D) long Answer - byte

Question) Consider the following code and Select the missing statement in given code import java.sql.*;
class MySQL { public static void main(String args[]){ try{ Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection( "jdbc:mysql://localhost:3306/dsn","root","root");
Statement stmt=con.createStatement(); ------------------------------------------------------------ while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3)); con.close(); }catch(Exception e)
{ System.out.println(e);} } }

A) ResultSet rs=stmt.runQuery("select * from emp"); B) ResultSet rs=stmt.executeQuery("select * from


emp"); C) int n=stmt.executeQuery("select * from emp"); D) int n=stmt.executeUpdate("select * from
emp"); Answer - ResultSet rs=stmt.executeQuery("select * from emp");

https://localhost/dashboard/ques_ans_22517.php 11/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Consider the following program. Find which statement contains 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 = { "Name", "Phone", "Fax" }; final
Object[][] data = { { "Pramod", "4567", "8675" }, { "Tausif", "7566", "5555" }, { "Nitin", "5634", "5887" }, {
"Amol", "7345", "9222" }, { "Vijai", "1237", "3333" }, { "Ranie", "5656", "3144" }, { "Mangesh", "5672", "2176"
}, { "Suhail", "6741", "4244" }, { "Nilofer", "9023", "5159" }, { "Jinnie", "1134", "5332" }, { "Heena", "5689",
"1212" }, { "Saurav", "9030", "1313" }, { "Raman", "6751", "1415" } }; JTable table = new JTable(data,
colHeads); int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h =
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPane jsp = new
JScrollPane(table, v, h); contentPane.add(jsp, BorderL

A) No error B) error C) compile time error D) Run time errror Answer - No error

Question) Consider the following code and write the value of String sql to delete record of an employee.
import java.sql.*; import java.util.*; public class DeleteRecord { public static void main(String args[]) throws
Exception { String sql; Scanner sc=new Scanner(System.in); System.out.println("Please Enter the ID no:");
int num = sc.readInt(); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:EMP","scott","tiger"); Statement stmt=con.createStatement();
int affectedRecords = stmt.executeUpdate(sql); br.close(); stmt.close(); con.close(); } }

A) sql="delete from Employee where empid="+ num B) sql="delete * Employee where empid="+ num C)
sql=" select * from Employee " D) sql="delete from Employee where empid=" Answer - sql="delete
from Employee where empid="+ num

Question) Following four methods belongs to which class? 1) public void add(Component c) 2) public void
setSize(int width,int height) 3) public void setLayout(LayoutManager m) 4) public void setVisible(boolean)

A) Graphics class B) Component class C) Both A & B D) None of the above Answer -
Component class

Question) Which is the container that does not contain title bar and MenuBars but it can have other
components like button, textfield etc?

A) Window B) Menu bar C) Panel D) Output Screen Answer - Panel

Question) Whose object is to be created to show any number of choices in the visible window?

A) JLabel B) JButton C) JList D) JCheckbox Answer - JList

Question) What is used to store partial data results, as well as to perform dynamic linking, return values for
methods, and dispatch exceptions?

A) Window B) Button C) Container D) Frame Answer - Frame

Question) Which class is used for processActionEvent( ) Processing Method ?

A) JButton,JList,JMenuItem B) JButton Only C) JScrollbar D) None of the above Answer -


JButton,JList,JMenuItem

Question) a) It is lightweight. b) It supports pluggable look and feel. c) It follows MVC (Model View
Controller) architecture Above advantages are of _____________

https://localhost/dashboard/ques_ans_22517.php 12/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) Swing B) AWT C) Networking D) Databases Answer - Swing

Question) JFrame myFrame = new JFrame (); Any command (such as the one listed above) which creates
a new object of a specific class (in this case a new JFrame object called myFrame) is generally called a ...

A) Constructor B) Layout manager C) Parameter D) GUI Answer - Constructor

Question) Suppose you are developing a Java Swing application and want to toggle between various views
of the design area. Which of the views given below are present for the users to toggle?

A) Design View B) Requirement View C) Source View D) Toggle View Answer - Requirement
View

Question) The size of a frame on the screen is measured in:

A) Inches B) Centimetres C) Dots D) Pixels Answer - Pixels

Question) The layout of a container can be altered by using which of the following methods

A) setLayout(LayoutManager) B) layoutmanager(LayoutManager) C) addLayout(LayoutManager) D)


setLayoutManager(LayoutManager) Answer - setLayout(LayoutManager)

Question) In JDBC _____ imports all java classes concerned with database connectivity.

A) javax.sql.* B) java.mysql.* C) java.sql.* D) com.* Answer - java.sql.*

Question) Methods of ResultSet throws ...... exception.

A) IOException B) SQLException C) MethodNotFoundException D) ResultSetException Answer -


SQLException

Question) Which of the following is FALSE with reference to JDBC Driver

A) All drivers implements the java.sql.Driver interface. B) driver classes are not supplied by the database
vendor C) Driver class return a java.sql.Connection object. D) None of the Above Answer - driver
classes are not supplied by the database vendor

Question) How do you indicate where a component will be positioned using Flowlayout?

A) North, South, East, West B) Assign a row/column grid reference C) Do nothing, the FlowLayout will
position the component D) Pass a X/Y percentage parameter to the add method Answer - Do
nothing, the FlowLayout will position the component

Question) Match the following i) Type 1 Driver a) Native API, partly Java ii)Type 2 Driver b) Pure Java direct
to database iii)Type 3 Driver c) JDBC-ODBC bridge iv)Type 4 Driver d) Pure Java to database middleware

A) i -> c, ii -> b , iii -> d, iv -> a B) i -> c, ii -> a , iii -> d, iv -> b C) i -> c, ii -> a , iii -> b, iv -> d D) i -> c, ii
-> d , iii -> a, iv -> b Answer - i -> c, ii -> a , iii -> d, iv -> b

Question) PreparedStatements are used for calling........ statements

A) Interpreted Statements B) Exceuted statements C) Resultset statements D) precompile Statement


Answer - precompile Statement

https://localhost/dashboard/ques_ans_22517.php 13/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Which TextComponent method is used to set a TextComponent to the read-only state ?

A) setReadOnly() B) setRead() C) setUpdate() D) setTextReadOnly() Answer - setReadOnly()

Question) 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 - Type 3 Driver

Question) Which method will cause a JFrame to get displayed?

A) show( ) B) setVisible( ) C) showFrame( ) D) displayFrame( ) Answer - setVisible( )

Question) Which of the Following Drivers Sun describes it as being experimental and appropriate for use
only where no other driver is available.

A) Type 1 Driver B) Type 2 Driver C) Type 3 Driver D) Type 4 Driver Answer - Type 1 Driver

Question) ___________ interface allows storing results of query?

A) ResultSet B) Connection C) Statement D) Result Answer - ResultSet

Question) Which of the Following Drivers require native library files to be installed & configured on client
systems.

A) Type 1 Driver B) Type 2 Driver C) Type 3 Driver D) Type 4 Driver Answer - Type 2 Driver

Question) InetAddress also Includes a factory method called____

A) getByAddress() B) getHostName() C) getAddress() D) getIPAddress() Answer -


getByAddress()

Question) Which of the following statements are TRUE in case of Type 2 JDBC Drivers

A) It use native methods to call vendor-specific API functions. B) native library files are to be installed on
client systems. C) Both of the Above D) None of the Above Answer - Both of the Above

Question) in JDBC 2.0 a Connection object is created either by a call to

A) DriverManager.getConnection() B) DataSource.Connection() C) Both of the Above D) None of the


Above Answer - DriverManager.getConnection()

Question) How to create the Tabbed pane in swings?

A) JTab jt=new JTab(); B) JTabPane jt=new JTabPane(); C) JTabP =new JTabP(); D) JTabbedPane
jt=new JTabbedPane (); Answer - JTabbedPane jt=new JTabbedPane ();

Question) In JDBC URL string protocol is always

A) jdbc B) odbc C) Jdbc-odbc D) Any one of the above Answer - jdbc

Question) Choose the correct option to insert rollno and student name into table named student and display
its contents

https://localhost/dashboard/ques_ans_22517.php 14/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) import java.sql.*; class Example1{ public static void main(String args[]){ try{
Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con=DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:xe","system","oracle"); PreparedStatement
stmt=con.prepareStatement("insert into student values(?,?)"); stmt.setInt(1,101); stmt.setString(2,"Ratan");
int i=stmt.executeQuery(); con.close(); }catch(Exception e){ System.out.println(e);} } } B) import java.sql.*;
class Example1{ public static void main(String args[]){ try{ Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection ("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
PreparedStatement stmt=con.preparedStatement("insert into student values(?,?)"); stmt.setInt(1,"Ratan");
stmt.setString(2,101); int i=stmt.executeQuery(); con.close(); }catch(Exception e){ System.out.println(e);} } }
C) import java.sql.*; class Example1{ public static void main(String args[]){ try{
Class.forName("oracle.jdbc.driver.OracleDriver"); PreparedStatement stmt=con.preparedStatement("insert
into student values(?,?)") ; stmt.setInt(1,101); stmt.setString(2,XYZ); int i=stmt.executeQuery(); con.close();
}catch(Exception e){ System.out.println(e);} } } D) import java.sql.*; class Example1{ public static void
main(String args[]){ try{ Class.forName("oracle.jdbc.driver.OracleDriver"); Connection
con=DriverManager.getConnection ("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
PreparedStatement stmt=con.preparedStatement("insert into student values(?,?)"); stmt.setInt(1,101);
stmt.setString(2,"Ratan"); int i=stmt.executeUpdate(); con.close(); }catch(Exception e){
System.out.println(e);} } } Answer - import java.sql.*; class Example1{ public static void
main(String args[]){ try{ Class.forName("oracle.jdbc.driver.OracleDriver"); Connection
con=DriverManager.getConnection ("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
PreparedStatement stmt=con.preparedStatement("insert into student values(?,?)");
stmt.setInt(1,101); stmt.setString(2,"Ratan"); int i=stmt.executeUpdate(); con.close();
}catch(Exception e){ System.out.println(e);} } }

Question) what is the output of following program import java.net.*; class Demo { public static void
main(String arg[]) { InetAddress ip=InetAddress.getByName("www.google.com"); System.out.println(ip) }

A) www.google.com/217.56.216.195 B) www.google.com C) 217.56.216.195 D) All of the above


Answer - www.google.com/217.56.216.195

Question) What does the following line of code do? JTextfield text = new JTextfield(10);

A) Creates text object that can hold 10 columns of text. B) Creates text object that can hold 10 rows of
text. C) Creates the object text and initializes it with 10. D) The code is illegal Answer - Creates
the object text and initializes it with 10.

Question) Which of the following is FALSE with reference to JDBC database URL

A) URL string has three components B) protocol in URL string is always jdbc C) subprotocol in URL string
is always odbc. D) subname identifies the specific database to connect Answer - subprotocol in
URL string is always odbc.

Question) The Swing component classes that are used to encapsulate a mutually exclusive set of buttons ?

A) AbstractButton B) ButtonGroup C) JButton D) Button Answer - ButtonGroup

Question) Which class has strong support of the JDBC architecture?

A) The JDBC driver manager B) JDBC driver test suite C) JDBC ODBC bridge D) All of these
Answer - The JDBC driver manager

Question) Connection object can be initialized using the ____________method of the Driver Manager
Class.

https://localhost/dashboard/ques_ans_22517.php 15/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) putConnection() B) setConnection() C) Connection() D) getConnection() Answer -


getConnection()

Question) In model-view-controller (MVC) architecture of swings, model defines


the_______________________________

A) Data layer B) Presentation layer C) Business-logic layer D) Both A and C Answer - Both A
and C

Question) Which of the following methods are needed for loading a database driver in JDBC?

A) registerDriver() method B) Class.forName () C) Both A and B D) getConnection () Answer -


Class.forName ()

Question) Disadvantages of MVC architecture can be :

A) Navigation control is decentralized B) Time consuming C) both a& b D) UI components are not user
friendly Answer - both a& b

Question) Native API converts ____________into the ________________used by DBMS.

A) JDBC API, network protocol B) JDBC API, Native API calls C) JDBC API, User call D) JDBC API,
ODBC API calls Answer - JDBC API, Native API calls

Question) _______ method of DriverManager class is used to establish connection with the database.

A) openConnection() B) getConnection() C) connect() D) createConnection() Answer -


getConnection()

Question) . . . . . . helps you to maintain data when you move from controller to view.

A) View Bag B) View Data C) . Temp Data D) Both A and B Answer - Both A and B

Question) What is output of following program import java.net.*; class Demo { public static void main(String
arg[]) throws UnKnownHostException { InetAddress ipa[]=InetAddress.getAllByName("www.google.com");
for(int i=0;i<ipa.length;i++){ System.out.println(ipa[i]); } } }

A) array of hostnames B) array of hostname/IPaddress C) array of IPaddress D) IPAddress/Hostname


Answer - array of hostname/IPaddress

Question) Which of the following view file types are supported in MVC?

A) .cshtml B) .vbhtml C) .aspx D) All of the above Answer - All of the above

Question) Can we use view state in MVC?

A) Yes B) No C) Both A & B D) None of the above Answer - No

Question) subname part of JDBC URL string NOT contains

A) Database name B) Username & password C) Port number D) Protocol Answer - Protocol

Question) The code below draws a line. What is the color of the line created?
g.setColor(Color.red.green.yellow.red.cyan); g.drawLine(0, 0, 100,100);

https://localhost/dashboard/ques_ans_22517.php 16/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) Red B) Green C) Yellow D) Cyan Answer - Cyan

Question) What does the following code draw? g.setColor(Color.black); g.drawLine(10, 10, 10,50);
g.setColor(Color.RED); g.drawRect(100, 100, 150, 150);

A) A red vertical line that is 40 pixels long and a red square with sides of 150 pixels. B) A black vertical line
that is 40 pixels long and a red square with sides of 150 pixels. C) A black vertical square that is 50 pixels
long and a red square with sides of 150 pixels. D) A red vertical line that is 50 pixels long and a red
square with sides of 150 pixels. Answer - A black vertical line that is 40 pixels long and a red
square with sides of 150 pixels.

Question) boolean equals(Object other) will return_______

A) Returns true if object has same internet address as other. B) Returns False if object has same internet
address as other. C) Returns true if object has not same internet address as other. D) Returns null if
object has same internet address as other. Answer - Returns true if object has same internet
address as other.

Question) Which method is used to construct a 24-point bold serif font?

A) new Font(Font.SERIF, 24,Font.BOLD); B) new Font("SERIF", 24, BOLD"); C) new Font("BOLD",


24,Font.SERIF); D) new Font("SERIF", Font.BOLD,24); Answer - new Font("SERIF",
Font.BOLD,24);

Question) What is the role of getAddress() method ?

A) returns Ip address of network. B) Returns a byte array that represents the object's Ip address in the
network byte order. C) Returns an array of object's that represents Ip address . D) Returns the a byte
array of Ip address of network host machine . Answer - Returns a byte array that represents the
object's Ip address in the network byte order.

Question) Which of the following type of JDBC driver, is also called Type 3 JDBC driver?

A) JDBC-ODBC Bridge plus ODBC driver B) Native-API, partly Java driver C) JDBC-Net, pure Java
driver D) Native-protocol, pure Java driver Answer - JDBC-Net, pure Java driver

Question) What will be the following code draw on the screen. Where "g" is a graphics instance in the
following code of line g.fillArc(45,90,50,50,90,180);

A) An arc bounded by a box of height 45, width 90 with a centre point of 50,50, starting at an angle of 90
degrees traversing through 180 degrees counter clockwise. B) An arc bounded by a box of height 50,
width 50, with a centre point of 45,90 starting at an angle of 90 degrees traversing through 180 degrees
clockwise. C) An arc bounded by a box of width 50, height 50, with a top left at coordinates of 45, 90,
starting at 90 degrees and traversing through 180 degrees counter clockwise. D) An arc starting at 45
degrees, traversing through 90 degrees clockwise bounded by a box of height 50, width 50 with a centre
point of 90, 180. Answer - An arc bounded by a box of width 50, height 50, with a top left at
coordinates of 45, 90, starting at 90 degrees and traversing through 180 degrees counter clockwise.

https://localhost/dashboard/ques_ans_22517.php 17/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Analyse the following code and fill the appropriate statement in the blanks import java.sql.*; class
Demo { public static void main(String args[])throws Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:stud"); Statement stmt=con.createStatement(); ResultSet
rs=stmt.________________("select * from student where rollno=1"); System.out.println("RollNo Name
Branch"); where(rs.next()) { System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getInt(3)); }
con.close(); } }

A) executeUpdate() B) executeQuery() C) execute() D) All of the Above Answer -


executeQuery()

Question) What will be the output of the following program? The program creates a simple Frame and
override the paint method as follows import java.applet.*; import java.awt.*; public class HelloWorldApplet
extends Applet { public void paint (Graphics g) { g.drawString ("Dolly",50,10); } }

A) The string "Dolly" will be displayed at the centre of the frame. B) An error at compilation complaining at
the signature of the paint method. C) The string "Dolly" will be seen at the top of the form D) The string
"Dolly" will be shown at the bottom of the form. Answer - The string "Dolly" will be seen at the top
of the form

Question) What is the output of the following ? import java.awt.*; import javax.swing.*; public class
FrameTest extends JFrame { public FrameTest() { add (new JButton("First")); add (new JButton("Second"));
add (new JButton("Third")); pack(); setVisible(true); } public static void main(String args []) { new
FrameTest(); } }

A) Three buttons are displayed across a window. B) A runtime exception is generated (no layout manager
specified). C) Only the first button is displayed. D) Only the third button is displayed. Answer -
Only the third button is displayed.

Question) Which of the following type of JDBC driver, is also called Type 1 JDBC driver

A) JDBC-ODBC Bridge Driver B) Native API/ Partly java driver C) All java / Net-protocol driver D)
Native protocol / all-java driver Answer - JDBC-ODBC Bridge Driver

Question) Which of the following type of JDBC driver, is also called Type 2 JDBC driver

A) Native API/ Partly java driver B) JDBC-ODBC Bridge Driver C) Native protocol / all-java driver D) All
java / Net-protocol driver Answer - Native API/ Partly java driver

Question) Suppose a JPanel is added to a JFrame and a JButton is added to the JPanel. If the JFrames
font is set to 12-point TimesRoman, the JPanels font is set to 10-point TimesRoman, and the JButtons font
is not set,what font will be taken to display the JButtons label?

A) 12- point TimesRoman. B) 11- point TimesRoman. C) 10 -point TimesRoman D) 09 -point


TimesRoman. Answer - 10 -point TimesRoman

Question) Which of the following type of JDBC driver, is also called Type 4 JDBC driver

A) All java / Net-protocol driver B) Native protocol / all-java driver C) Native API/ Partly java driver D)
JDBC-ODBC Bridge Driver Answer - Native protocol / all-java driver

https://localhost/dashboard/ques_ans_22517.php 18/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) What is the result of the following applet code ? import java.applet.JApplet; Import javax.swing.*;
public class Sample extends JApplet { private String text = "Hello World"; public void init() { add(new
JLabel(text)); } public Sample (String string) { text = string; } } It is accessed form the following HTML page:
<html> <title>Sample Applet</title> <body> <applet code="Sample.class" width=200 height=200></applet>
</body></html>.

A) Prints "Hello World" B) Generates a runtime error C) . Does nothing D) Generates a compile time
error Answer - Generates a runtime error

Question) import java.applet.JApplet; import javax.swing.*; public class Sample extends JApplet { private
String text = "Hello World"; public void init() { add(new JLabel(text)); } public Sample (String string) { text =
string; } } It is accessed form the following HTML page: <html> <title>Sample Applet</title> <body> <applet
code="Sample.class" width=200 height=200></applet></body></html>. The method setLabel() can be used
with what type of Object?

A) Float B) int C) JTextField D) String. Answer - JTextField

Question) Which Swing Component classes that are used to Encapsulates a mutually exclusive set of
buttons?

A) AbstractButton B) ButtonGroup C) JButton D) Button Answer - ButtonGroup

Question) Which method is used to add tooltip text to almost all components of Java swing?

A) getToolTipText() B) setToolTipText(String s) C) setToolTip (String s) D) getToolTipText(String s)


Answer - setToolTipText(String s)

Question) In Swing the content pane can be obtained by using ________method.

A) getContent() B) getContentPane() C) Both A & B D) getContainedPane() Answer -


getContentPane()

Question) Which one of the following is the correct sequence of activities to perform for database
connectivity in java

A) Register the Driver class - Create statement - Create connection - Execute queries - Close connection
B) Register the Driver class - Create connection - Create statement -Execute queries - Close connection
C) Create connection - Register the Driver class - Create statement -Execute queries - Close connection
D) Create connection - Create statement - Register the Driver class - Execute queries - Close connection
Answer - Register the Driver class - Create connection - Create statement -Execute queries -
Close connection

Question) Model is the _________ in the MVC architecture.

A) top most level B) middle most level C) bottom most level D) None of the above Answer -
bottom most level

Question) Double-buffering built in, tool tips, dockable tool bars, keyboard , accelerators, custom cursors,
etc. are new features of _______?

A) AWT B) Networking C) Swing D) All of the above Answer - Swing

Question) JCheckBox is ___________________Component .

https://localhost/dashboard/ques_ans_22517.php 19/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) heavyweight B) mediumweight C) No weight D) lightweight Answer - lightweight

Question) The default layout manager for the content pane of a swing is :

A) CardLayout B) GridLayout C) BorderLayout D) None of the above Answer - BorderLayout

Question) 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 - data server

Question) 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 - open database connectivity

Question) Database system compiles query when it is

A) prepared B) invoked C) executed D) initialized Answer - prepared

Question) Standard which allows access to DBMS by Java client programs is classified as

A) JCBD standard B) JDBC standard C) BDJC standard D) CJBD standard Answer - JDBC
standard

Question) 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 - None of the Above

Question) In two-tier client/server architecture, running of application programs and user interface programs
is in control of___________

A) modulation side B) client side C) server side D) host side Answer - client side

Question) Which of the following must be closed at end of Java program ?

A) Result B) Connection C) Query D) Both A and B Answer - Connection

Question) A Java application program does not include declarations for

A) Data stored in database B) Data retrieved of database C) Data executed D) Data manipulated
Answer - Data stored in database

Question) A label is a simple control which is used to display _________________on the window

A) button B) Editable Text C) Non-Editable Text D) All of above Answer - Non-Editable Text

https://localhost/dashboard/ques_ans_22517.php 20/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Which statement is true with respect to the following code? import java.awt.*; import
javax.swing.*; public class Test { public static void main(String[] args) { JFrame frame = new JFrame("My
Frame"); frame.getContentPane().add(new JButton("OK")); frame.getContentPane().add(new
JButton("Cancel")); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200);
frame.setVisible(true); } }

A) Only button OK is displayed. B) Only button Cancel is displayed. C) Both button OK and button Cancel
are displayed and button OK is displayed on the left side of button OK. D) Both button OK and button
Cancel are displayed and button OK is displayed on the right side Answer - Only button Cancel is
displayed.

Question) Label is ___________ entity.

A) Active B) Passive C) Both A& B D) None of these Answer - Passive

Question) ___________ method is used to set or change the text in a Label.

A) setText(String strLabel) B) getText() C) getAlignment() D) None of these Answer -


setText(String strLabel)

Question) getAlignment() is the method of ________ class.

A) Button B) List C) Choice D) Label Answer - Label

Question) Label(String str) creates a label that contains the string specified by str which is _________

A) Right-Justified B) Left-Justified C) Center-Justifed D) All of above Answer - Left-Justified

Question) Which of the following Statement is NOT true for Type-2 Drivers

A) Driver needs to be installed separately in individual client machines B) The Vendor client library needs
to be installed on client machine. C) Type-2 driver isn't written in java, that's why it isn't a portable driver
D) None of the Above Answer - None of the Above

Question) Which of the following method is used to set Label for Button B

A) B.setLabel(String S) B) B.getLabel() C) Both A& B D) B.setText(String S) Answer -


B.setLabel(String S)

Question) With respect to Type-3 drivers A)Type-3 drivers are fully written in Java, hence they are portable
drivers. B)No client side library is required because of application server that can perform many tasks like
auditing, load balancing, logging etc.

A) A is True But B is False B) B is True But A is False C) Both are False D) Both are True
Answer - Both are True

Question) The various controls supported by AWT are

A) Buttons,Scrollbar B) Label,TabbedPanes C) Tress,Tables D) All of above Answer -


Buttons,Scrollbar

Question) Which of the following is NOT true for Type - 4 drivers

https://localhost/dashboard/ques_ans_22517.php 21/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) Type-4 driver is also called native protocol driver. B) Different driver is not needed for different
database. C) No client-side or server-side installation required. D) It is fully written in Java language,
hence they are portable drivers. Answer - Different driver is not needed for different database.

Question) Which method does return true value if specified address is a multicast address ?

A) isMulticastHostName() B) isMulticastHostAddress() C) isMulticastAddress() D)


isMulticastIPAddress() Answer - isMulticastAddress()

Question) InetAddress has two subclasses called as:

A) IPV4Address() and IPV6Address() B) IP4VAddress() and IP6VAddress() C) Inet4Address() and


Inet6Address() D) InetAddress4() and InetAddress6() Answer - Inet4Address() and
Inet6Address()

Question) What is output of following code? import java.net.*; class Inet{ public static void main(String arg[])
{ InetAddress ip=InetAddress.getLocalHost(); System.out.println(ip.getHostAddress(); }}

A) 192.168.0.100 B) localhost/192.168.0.100 C) localhost machine D) localhost//8080: Answer -


localhost machine

Question) what is the output of following program import java.net.*; class Demo { public static void
main(String arg[]) throws UnKnownHostException { InetAddress ipa=InetAddress.getLocalHost();
InetAddress ipa1=InetAddress.getLocalHost("www.google.com"); boolean b=ipa.equals(ipa1);
System.out.println(b); } }

A) true B) false C) compile time error D) 0 Answer - compile time error

Question) what is the output of following program import java.net.*; class Demo { public static void
main(String arg[]) throws UnKnownHostException { InetAddress ipa=InetAddress.getLocalHost();
InetAddress ipa1=InetAddress.getLocalHost(); boolean b=ipa.equals(ipa1); System.out.println(b); } }

A) true B) false C) 0 D) 1 Answer - true

Question) InetAddress class is used to encapsulate both numerical IP address and the ______________

A) port number B) host name C) server name D) socket name Answer - host name

Question) what is the output of following program import java.net.*; class Demo { public static void
main(String arg[]) throws UnKnownHostException { InetAddress
ipa=InetAddress.getByName("www.google.com"); System.out.println(ipa.getHostName()); } }

A) www.google.com B) www.google.com/217.196.214.99 C) 217.196.214.99 D) None of the above


Answer - www.google.com

Question) You can simply use InetAddress class when working with IP address because it can
accommodate both ___________ styles.

A) IP4V and IP6V B) IPV4 and IPV6 C) host name and IP D) A and B Answer - IPV4 and IPV6

Question) What does getHostAddress() of InetAddress class terurn?

https://localhost/dashboard/ques_ans_22517.php 22/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) Returns host address with ipaddress. B) Returns a string that represents ipaddresses with hostname.
C) Returns a string that represents a host address associated with the Inetaddress object. D) Returns a
string that represents a host name associated with Inetaddress object. Answer - Returns a string
that represents a host address associated with the Inetaddress object.

Question) getHostName() of InetAddress class is used to_______

A) Return a string that represents host name associated with Inetaddress object. B) Return a string that
represents host address associated with Inetaddress object. C) Return an object that represents Ipaddress
associated with host name . D) Return Ipaddress that is associated with InetAddress object .
Answer - Return a string that represents host name associated with Inetaddress object.

Question) Which of the following statement is correct ?

A) There are two kinds of sockets in java one is for server and other for clients. B) There is only one socket
for server. C) There is only one socket for client. D) There is only one socket for server as well as for
client. Answer - There are two kinds of sockets in java one is for server and other for clients.

Question) Which of the following class is used to create server that listen for clients ?

A) httpserver B) ServerSocket C) DatagramSocket D) Socket Answer - ServerSocket

Question) 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 -
IoExeption is thrown when opening the socket

Question) Which exception will be thrown if client socket does not specify the hostname when it has created
?

A) IOException B) UnknownHostException C) UnknownHostNameException D) UnknownPortException


Answer - UnknownHostException

Question) Which constructor will you use to create client socket using a preexsiting InetAddress object and
a port ?

A) Socket (String hostname, int port ) B) Socket (Inetaddress ipAdd, int port ) C) Socket (Inetaddress ip
Add, string Hostname) D) Socket ( int port, Inetaddress ipAdd ) Answer - Socket (Inetaddress
ipAdd, int port )

Question) __________method returns the local part to which the invoking socket object is bound.

A) int getLocalHost() B) int getLocalPort() C) int getPort() D) int GetLocalHost() Answer - int
getLocalHost()

Question) Which of the following are factory methods of InetAddress class?

A) static InetAddress[] getAllByName(String hostname) B) static InetAddres getLocalHost() C) string


getHostName() D) A and B Answer - A and B

Question) Which of the following methods belong to ServerSocket class

A) accept() B) connect() C) bind() D) A and C Answer - A and C

https://localhost/dashboard/ques_ans_22517.php 23/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) ServerSocket class has one of the following constructor

A) ServerSocket(int port) B) ServerSocket(String host, int port) C) ServerSocket(int port, InetAddress


add) D) ServerSocket(InetAddress add, int port) Answer - ServerSocket(int port)

Question) Socket method called______returns the port number that socket is bound to on local machine

A) int getLocalPortt() B) int getPort() C) InetAddress getInetAddress() D) string getHostAddress()


Answer - int getPort()

Question) What are different factory methods of InetAddress class?

A) getByName() B) GetLocalHost() C) getByAddress() D) both A & C Answer - both A & C

Question) How long is an IPv6 address?

A) 32 bits B) 128 bytes C) 64 bits D) 128 bits Answer - 128 bits

Question) __________________method is needed only when you instantiate the socket using the not
argument constructer.

A) bind() B) connect() C) accept() D) SetHostName() Answer - connect()

Question) InetAddress class having method which returns a string that shows the host name and IP
address.

A) toString() B) getHostAddress() C) getLocalHost() D) none of the above Answer - toString()

Question) 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 - bind (
socketAddress host , int backlog)

Question) accept method is used for _______________________

A) Incoming Client connection B) Incoming Server socket C) Accepting request from server D) Waiting
socket Answer - Incoming Client connection

Question) _____________Class represents the socket that both the client & server use to communicate
with each other

A) java.net.Serversocket B) java.net.Server C) Java.net.socket D) java.net.Clientsocket Answer -


Java.net.socket

Question) Socket s1= Socket ( localhost, 1346), What does it means ?

A) Client socket is waiting for connection B) Client socket is created to connect with specified host name
and port number C) Client socket is name as localhost and Port number is 1346 D) server socket is
connected to local host with port number 1346 Answer - Client socket is created to connect with
specified host name and port number

Question) What is the output of following statements Socket s1=new Socket("localhost",1234); int
a=s1.getPort(); System.out.println(a);

https://localhost/dashboard/ques_ans_22517.php 24/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) localhost B) localhost/1234 C) 1234 D) 1234/localhost Answer - 1234

Question) Correct way of using ServerSocket is___________

A) ServerSocket(int port) B) ServerSocket(int port,int maxQueue) C) ServerSocket(int port,int


maxQueue,InetAddress localAddress) D) All of the above Answer - All of the above

Question) What is the output of following statements? ServerSocket ss=new ServerSocket(1349); Socket
s1=ss.accept(); System.out.println(ss.getLocalPort());

A) port number of client socket B) 1349 C) local port D) None of the above Answer - 1349

Question) public InputStream getInputStream() is method of ____________ class

A) Serversocket B) ClientSocket C) Socket D) All of the above Answer - Socket

Question) getOutputStream() returns the output stream of the ________

A) Socket B) ServerSocket C) ClientSocket D) None of the above Answer - Socket

Question) Which of the following statement is correct?

A) The input stream of socket is connected to the output stream of remote socket B) The output stream of
socket is connected to the input stream of remote socket C) The output stream of socket is connected to
the output stream of remote socket D) A and B Answer - A and B

Question) __________method makes socket object no longer capable of connecting again to any server

A) send() B) wait() C) connect() D) close() Answer - close()

Question) If your application has successfully bound to specified port and is ready for client request
then_________

A) an exception is thrown B) an IOException is thrown C) it does not throw an exception D)


UnknownHostException is thrown Answer - it does not throw an exception

Question) Socket is the combination of ______________ and __________.

A) IP address and port number B) port number and local host C) IPAddress and machine number D) All
of the above Answer - IP address and port number

Question) Which steps occur when establishing a TCP connection between two computers using socket?

A) The server initiates a ServerSocket object denoting port number to be connected B) The server invokes
the accept() method of ServerSocket class. This method waits until a client connects to the server on the
given port C) After the server is waiting, a client instantiates a socket object with specified server name
and port number D) All of the above Answer - All of the above

Question) What is the output of the following statement? ServerSocket ss=new ServerSocket(1234); Socket
s1=ss.accept(); System.out.println(s1.getPort());

A) port number of client socket B) 1234 C) local port D) All of the above Answer - port number
of client socket

https://localhost/dashboard/ques_ans_22517.php 25/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) What is the output of following statement? ServerSocket ss=new ServerSocket(1234); Socket
s1=ss.accept(); System.out.println(s1.getRemoteSocketAddress());

A) 1234 B) iPAddress of serversocket C) IPAddress of client with port number D) IPAddress of server
with port number Answer - IPAddress of client with port number

Question) What is the output of following statement? Socket s1=new Socket("localhost",1234);


System.out.println(s1.getRemoteSocketAddress());

A) IPAddress of client with port number B) host name, IPAddress and port number of Serversocket C)
host name and IPAddress Serversocket D) IPAddress of server with port number Answer - host
name, IPAddress and port number of Serversocket

Question) Connection timed out exception is occurred _________

A) if client socket is not created B) if serversocket does not accept client request C) if port number is not
available which is specified by client socket with host name D) None of the above Answer - if port
number is not available which is specified by client socket with host name

Question) Which method is used to expose the details of establishing connection between server socket &
client socket ?

A) connect() B) receive() C) there is no such method D) None of the above Answer - there is no
such method

Question) You can gain access to the input and output streams associated with socket by use
getInputStream()

A) getOutStream() B) setOutputStream() C) getOutputStream() D) getOutputClass() Answer -


getOutputStream()

Question) Which exception will occur when port is already bound with an application and other application is
requesting for same port?

A) IOException B) PortNotFoundException C) UnknownPortNameException D) ConectException


Answer - IOException

Question) 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 -
to create ServerSocket with port number and number of incoming client queue

Question) Socket(InetAddress host, int port) in this constructor, what does first parameter stands for ?

A) host name B) host name and IPAddress specified by InetAddress object C) IpAddress of host D)
ipaddress and port number Answer - host name and IPAddress specified by InetAddress object

Question) Which constructor will you use to connect to specified host and port by creating a socket on the
local host at specified address & port

A) Socket() B) Socket(String host, int port) C) Socket (Inetaddress ipAdd,int port) D) Socket ( String
host,int port, Inetaddress ipAdd, int localport ) Answer - Socket ( String host,int port, Inetaddress
ipAdd, int localport )
https://localhost/dashboard/ques_ans_22517.php 26/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Which of the following class is used to create client socket

A) httpserver B) Datagram Socket C) Socket D) ClientSocket Answer - Socket

Question) What will be the output of following statements Socket s1=Socket("localhost",1349);


System.out.println(s1.getLocalPort());

A) 1349 B) port number of local machine C) local host D) localhost/1349 Answer - port number
of local machine

Question) Which of the following are Instance method of InetAddress Class

A) byte[] getAddress() B) string getHostName() C) A and B D) static InetAddress getByName(string


hostname) Answer - A and B

Question) Which constructor of DatagramSocket class is used to create a datagram socket and binds it with
the given port number?

A) DatagramSocket(int port) B) DatagramSoclet(int port InetAddress add) C) DatagramSoclet() D)


None of the above Answer - DatagramSocket(int port)

Question) Which class is used for connection-less socket programming ?

A) DatagramSoclet B) DatagramServer C) A and B D) None of the above Answer -


DatagramSoclet

Question) Which exception will occur if specified port number is not available for DatagramSoclet?

A) UnknownException B) SocketException C) UnknownSocketException D) UnknownPortException


Answer - SocketException

Question) Which of the following constructor is used to create datagram socket with port number and host
address

A) DatagramSoclet(int port) B) DatagramSoclet(int port InetAddress add) C) DatagramSoclet() D) A & B


Answer - DatagramSoclet(int port InetAddress add)

Question) Which constructor will you use to send packet?

A) DatagramPacket(byte[] bar, int len) B) DatagramPacket(byte[] bar, int len, int port) C)
DatagramPacket(string s1, int len, InetAddress, int port) D) All of the above Answer -
DatagramPacket(byte[] bar, int len, int port)

Question) Java DatagramSocket and DatagramPacket classes are used for _______________ socket
programming

A) Connection-oriented B) Connection-less C) A & B D) Reliable Answer - Connection-less

Question) Datagram Packet is a message than can be used for _________ messages

A) Connection-oriented or connection less B) send and store C) send and receive D) receive and read
Answer - send and receive

Question) Which constructors are used to receive data from packet?

https://localhost/dashboard/ques_ans_22517.php 27/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) DatagramPacket(byte[] bar, int len) B) DatagramPacket(byte[] bar, int off, int len) C)
DatagramPacket(string s1, int len, InetAddress, int port) D) A and B Answer - A and B

Question) getData() & getLenght() are the methods of ___________ class

A) DatagramSoclet B) ServerSocket C) DatagramPacket D) ClientSocket Answer -


DatagramPacket

Question) What is the output of following code? DatagramPacket dp =new DatagramPacket(byte[] data,
1024); System.out.println(dp.getLength());

A) 1024 B) data, 1024 C) 1024, data D) Null Answer - 1024

Question) Find the correct code from following program for given output

A) import java.awt.*; import javax.swing.*; /* <applet code=" JLabelDemo" width=250 height=150> </applet>
*/ public class JLabelDemo extends JApplet { public void init() { Container contentPane = getContentPane();
ImageIcon ii = new ImageIcon("IC.jpg"); JLabel jl = new JLabel("IC", ii, JLabel.CENTER);
contentPane.add(jl); } } B) import java.awt.*; import javax.swing.*; /* <applet code="JLabelDemo"
width=250 height=150> </applet> */ public class JLabelDemo extends JApplet { public void init() { Container
contentPane = getContentPane(); ImageIcon ii = new ImageIcon("IC.jpg"); JLabel jl = new JLabel("IC", ii,
JLabel.CENTER); } } C) import java.awt.*; import javax.swing.*; /* <applet code="JLabelDemo" width=250
height=150> </applet> */ public class JLabelDemo extends JApplet { public void init() { ImageIcon ii = new
ImageIcon("IC.jpg"); JLabel jl = new JLabel("IC", ii, JLabel.CENTER); contentPane.add(jl); } } D) /* <applet
code="JLabelDemo" width=250 height=150> </applet> */ public class JLabelDemo extends JApplet { public
void init() { Container contentPane = getContentPane(); ImageIcon ii = new ImageIcon("IC.jpg"); JLabel jl =
new JLabel("IC", ii, JLabel.CENTER); contentPane.add(jl); } } Answer - import java.awt.*; import
javax.swing.*; /* <applet code="JLabelDemo" width=250 height=150> </applet> */ public class
JLabelDemo extends JApplet { public void init() { Container contentPane = getContentPane();
ImageIcon ii = new ImageIcon("IC.jpg"); JLabel jl = new JLabel("IC", ii, JLabel.CENTER);
contentPane.add(jl); } }

Question) Consider the following code and state the missing code. import java.sql.*; class Example1{ public
static void main(String args[]){ try{ 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(?,?,?)"); -----------------------------------
----------- int i=stmt.executeUpdate(); con.close(); }catch(Exception e){ System.out.println(e);} } }

A) stmt.setInt(1,101); stmt.setString(2,"Ratan"); stmt.setString(2,50000); B) stmt.setInt(1,101);


stmt.setString(2,"Ratan"); stmt.setInt(3,50000); C) stmt.setInt(1,101); stmt.setString(2,2);
stmt.setInt(3,50000); D) stmt.setInt(101); stmt.setString(2,2); stmt.setInt(3,50000); Answer -
stmt.setInt(1,101); stmt.setString(2,"Ratan"); stmt.setInt(3,50000);

Question) Choose the correct code to display the following output.

https://localhost/dashboard/ques_ans_22517.php 28/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) import javax.swing.*; /* <applet code="JCheckBoxDemo" width=400 height=50> </applet> */ public class


JCheckBoxDemo extends JApplet implements ItemListener { JTextField jtf; public void init() { Container
contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); JCheckBox cb = new
JCheckBox("C", true); cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("C++", false);
cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Java", false);
cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Perl", false);
cb.addItemListener(this); contentPane.add(cb); jtf = new JTextField(15); contentPane.add(jtf); } public void
itemStateChanged(ItemEvent ie) { JCheckBox cb = (JCheckBox)ie.getItem(); jtf.setText(cb.getText()); } } B)
import java.awt.*; import java.awt.event.*; import javax.swing.*; /*class JCheckBoxDemo extends JApplet
implements ItemListener { JTextField jtf; public void init() { Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout()); JCheckBox cb = new JCheckBox("C", true);
cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("C++", false);
cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Java", false);
cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Perl", false);
cb.addItemListener(this); contentPane.add(cb); jtf = new JTextField(15); contentPane.add(jtf); } public void
itemStateChanged(ItemEvent ie) { JCheckBox cb = (JCheckBox)ie.getItem(); jtf.setText(cb.getText()); } } C)
import java.awt.*; import java.awt.event.*; import javax.swing.*; /* <applet code="JCheckBoxDemo"
width=400 height=50> </applet> */ public class JCheckBoxDemo extends JApplet implements ItemListener
{ JTextField jtf; public void init() { Container contentPane = getContentPane(); contentPane.setLayout(new
FlowLayout()); JCheckBox cb = new JCheckBox("C", true); cb.addItemListener(this); contentPane.add(cb);
cb = new JCheckBox("C++", false); cb.addItemListener(this); contentPane.add(cb); cb = new
JCheckBox("Java", false); cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Perl",
false); cb.addItemListener(this); contentPane.add(cb); jtf = new JTextField(15); contentPane.add(jtf); } public
void itemStateChanged(ItemEvent ie) { JCheckBox cb = (JCheckBox)ie.getItem(); jtf.setText(cb.getText()); }
} D) import java.awt.*; import java.awt.event.*; import javax.swing.*; /* <applet code="JCheckBoxDemo"
width=400 height=50> </applet> */ public class JCheckBoxDemo extends JApplet implements ItemListener
{ JTextField jtf; public void init() { contentPane.add(cb); cb = new JCheckBox("C++", false);
cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Java", false);
cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Perl", false);
cb.addItemListener(this); contentPane.add(cb); jtf = new JTextField(15); contentPane.add(jtf); } public void
itemStateChanged(ItemEvent ie) { JCheckBox cb = (JCheckBox)ie.getItem(); jtf.setText(cb.getText()); } }
Answer - import java.awt.*; import java.awt.event.*; import javax.swing.*; /* <applet
code="JCheckBoxDemo" width=400 height=50> </applet> */ public class JCheckBoxDemo extends
JApplet implements ItemListener { JTextField jtf; public void init() { Container contentPane =
getContentPane(); contentPane.setLayout(new FlowLayout()); JCheckBox cb = new JCheckBox("C",
true); cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("C++", false);
cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Java", false);
cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Perl", false);
cb.addItemListener(this); contentPane.add(cb); jtf = new JTextField(15); contentPane.add(jtf); }
public void itemStateChanged(ItemEvent ie) { JCheckBox cb = (JCheckBox)ie.getItem();
jtf.setText(cb.getText()); } }

Question) Choose the correct code to display the following output.

A) import javax.swing.*; /* <applet code="JButtonDemo" width=250 height=300> </applet> */ public class


JButtonDemo extends JApplet implements ActionListener { JTextField jtf; public void init() { Container
contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); ImageIcon france = new
ImageIcon("green.jpg"); JButton jb = new JButton(france); jb.setActionCommand("Green");
jb.addActionListener(this); contentPane.add(jb); ImageIcon germany = new ImageIcon("red.jpg"); jb = new
JButton(germany); jb.setActionCommand("Red"); jb.addActionListener(this); contentPane.add(jb);
ImageIcon italy = new ImageIcon("yellow.jpg"); jb = new JButton(italy); jb.setActionCommand("Yellow");
jb.addActionListener(this); contentPane.add(jb); ImageIcon japan = new ImageIcon("black.jpg"); jb = new
https://localhost/dashboard/ques_ans_22517.php 29/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

JButton(japan); jb.setActionCommand("Black"); jb.addActionListener(this); contentPane.add(jb); jtf = new


JTextField(15); contentPane.add(jtf); } public void actionPerformed(ActionEvent ae) {
jtf.setText(ae.getActionCommand()); } } B) import java.awt.*; import java.awt.event.*; import javax.swing.*;
/* <applet code="JButtonDemo" width=250 height=300> </applet> */ public class JButtonDemo extends
JApplet implements ActionListener { JTextField jtf; public void init() { Container contentPane =
getContentPane(); contentPane.setLayout(new FlowLayout()); ImageIcon france = new
ImageIcon("green.jpg"); JButton jb = new JButton(france); jb.setActionCommand("Green");
jb.addActionListener(this); contentPane.add(jb); ImageIcon germany = new ImageIcon("red.jpg"); jb = new
JButton(germany); jb.setActionCommand("Red"); jb.addActionListener(this); contentPane.add(jb);
ImageIcon italy = new ImageIcon("yellow.jpg"); jb = new JButton(italy); jb.setActionCommand("Yellow");
jb.addActionListener(this); contentPane.add(jb); ImageIcon japan = new ImageIcon("black.jpg"); jb = new
JButton(japan); jb.setActionCommand("Black"); jb.addActionListener(this); contentPane.add(jb); jtf = new
JTextField(15); contentPane.add(jtf); } public void actionPerformed(ActionEvent ae) { } } C) import
java.awt.*; import java.awt.event.*; import javax.swing.*; /* <applet code="JButtonDemo" width=250
height=300> </applet> */ public class JButtonDemo extends JApplet implements ActionListener { JTextField
jtf; public void init() { Container contentPane = getContentPane(); contentPane.setLayout(new
FlowLayout()); ImageIcon france = new ImageIcon("green.jpg"); JButton jb = new JButton(france);
jb.setActionCommand("Green"); jb.addActionListener(this); contentPane.add(jb); ImageIcon germany = new
ImageIcon("red.jpg"); jb = new JButton(germany); jb.setActionCommand("Red"); jb.addActionListener(this);
contentPane.add(jb); ImageIcon italy = new ImageIcon("yellow.jpg"); jb = new JButton(italy);
jb.setActionCommand("Yellow"); jb.addActionListener(this); contentPane.add(jb); ImageIcon japan = new
ImageIcon("black.jpg"); jb = new JButton(japan); jb.setActionCommand("Black"); jb.addActionListener(this);
contentPane.add(jb); jtf = new JTextField(15); contentPane.add(jtf); } public void
actionPerformed(ActionEvent ae) { jtf.setText(ae.getActionCommand()); D) import java.awt.*; import
java.awt.event.*; import javax.swing.*; /* <applet code="JButtonDemo" width=250 height=300> </applet> */
public class JButtonDemo extends JApplet implements ActionListener { JTextField jtf; public void init() {
Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); ImageIcon france =
new ImageIcon("green.jpg"); JButton jb = new JButton(france); jb.setActionCommand("Green");
jb.addActionListener(this); contentPane.add(jb); ImageIcon germany = new ImageIcon("red.jpg"); jb = new
JButton(germany); jb.setActionCommand("Red"); jb.addActionListener(this); contentPane.add(jb);
ImageIcon italy = new ImageIcon("yellow.jpg"); jb = new JButton(italy); jb.setActionCommand("Yellow");
jb.addActionListener(this); contentPane.add(jb); ImageIcon japan = new ImageIcon("black.jpg"); jb = new
JButton(japan); jb.setActionCommand("Black"); jb.addActionListener(this); contentPane.add(jb); jtf = new
JTextField(15); contentPane.add(jtf); } public void actionPerformed(ActionEvent ae) {
jtf.setText(ae.getActionCommand()); } } Answer - import java.awt.*; import java.awt.event.*; import
javax.swing.*; /* <applet code="JButtonDemo" width=250 height=300> </applet> */ public class
JButtonDemo extends JApplet implements ActionListener { JTextField jtf; public void init() {
Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); ImageIcon
france = new ImageIcon("green.jpg"); JButton jb = new JButton(france);
jb.setActionCommand("Green"); jb.addActionListener(this); contentPane.add(jb); ImageIcon
germany = new ImageIcon("red.jpg"); jb = new JButton(germany); jb.setActionCommand("Red");
jb.addActionListener(this); contentPane.add(jb); ImageIcon italy = new ImageIcon("yellow.jpg"); jb =
new JButton(italy); jb.setActionCommand("Yellow"); jb.addActionListener(this);
contentPane.add(jb); ImageIcon japan = new ImageIcon("black.jpg"); jb = new JButton(japan);
jb.setActionCommand("Black"); jb.addActionListener(this); contentPane.add(jb); jtf = new
JTextField(15); contentPane.add(jtf); } public void actionPerformed(ActionEvent ae) {
jtf.setText(ae.getActionCommand()); } }

Question) Choose the correct code to display the following output.

https://localhost/dashboard/ques_ans_22517.php 30/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) import java.awt.*; import java.awt.event.*; import javax.swing.*; /* <applet code="JCheckBoxDemo"


width=400 height=50> </applet> */ public class JCheckBoxDemo extends JApplet implements ItemListener
{ JTextField jtf; public void init() { Container contentPane = getContentPane(); contentPane.setLayout(new
FlowLayout()); JCheckBox cb = new JCheckBox("C", true); cb.addItemListener(this); contentPane.add(cb);
cb = new JCheckBox("C++", false); cb.addItemListener(this); contentPane.add(cb); cb = new
JCheckBox("Java", false); cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Perl",
false); cb.addItemListener(this); contentPane.add(cb); jtf = new JTextField(15); contentPane.add(jtf); } public
void itemStateChanged(ItemEvent ie) { JCheckBox cb = (JCheckBox)ie.getItem(); jtf.setText(cb.getText()); }
} B) import javax.swing.*; /* <applet code="JCheckBoxDemo" width=400 height=50> </applet> */ public
class JCheckBoxDemo extends JApplet implements ItemListener { JTextField jtf; public void init() {
Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); JCheckBox cb =
new JCheckBox("C", true); cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("C++",
false); cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Java", false);
cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Perl", false);
cb.addItemListener(this); contentPane.add(cb); jtf = new JTextField(15); contentPane.add(jtf); } public void
itemStateChanged(ItemEvent ie) { JCheckBox cb = (JCheckBox)ie.getItem(); jtf.setText(cb.getText()); } } C)
import java.awt.*; import java.awt.event.*; import javax.swing.*; /* <applet code="JCheckBoxDemo"
width=400 height=50> </applet> */ public class JCheckBoxDemo extends JApplet implements ItemListener
{ JTextField jtf; public void init() { Container contentPane = getContentPane(); contentPane.setLayout(new
FlowLayout()); JCheckBox cb = new JCheckBox("C", true); cb.addItemListener(this); contentPane.add(cb);
cb = new JCheckBox("C++", false); cb.addItemListener(this); contentPane.add(cb); cb = new
JCheckBox("Java", false); cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Perl",
false); cb.addItemListener(this); contentPane.add(cb); jtf = new JTextField(15); contentPane.add(jtf); } public
void itemStateChanged(ItemEvent ie) { JCheckBox cb = (JCheckBox)ie.getItem(); } } D) import java.awt.*;
import java.awt.event.*; import javax.swing.*; /* <applet code="JCheckBoxDemo" width=400 height=50>
</applet> */ public class JCheckBoxDemo extends JApplet implements ItemListener { JTextField jtf; public
void init() { Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout());
JCheckBox cb = new JCheckBox("C", true); cb.addItemListener(this); contentPane.add(cb); cb = new
JCheckBox("C++", false); cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Java",
false); cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Perl", false);
cb.addItemListener(this); contentPane.add(cb); jtf = new JTextField(15); contentPane.add(jtf); } public void
itemStateChanged(ItemEvent ie) { JCheckBox cb = (JCheckBox)ie.getItem(); jtf.setText(cb.getText());
Answer - import java.awt.*; import java.awt.event.*; import javax.swing.*; /* <applet
code="JCheckBoxDemo" width=400 height=50> </applet> */ public class JCheckBoxDemo extends
JApplet implements ItemListener { JTextField jtf; public void init() { Container contentPane =
getContentPane(); contentPane.setLayout(new FlowLayout()); JCheckBox cb = new JCheckBox("C",
true); cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("C++", false);
cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Java", false);
cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("Perl", false);
cb.addItemListener(this); contentPane.add(cb); jtf = new JTextField(15); contentPane.add(jtf); }
public void itemStateChanged(ItemEvent ie) { JCheckBox cb = (JCheckBox)ie.getItem();
jtf.setText(cb.getText()); } }

Question) Choose the correct code to display the following output.

https://localhost/dashboard/ques_ans_22517.php 31/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) import java.awt.*; import java.awt.event.*; import javax.swing.*; /* <applet code="JComboBoxDemo"


width=300 height=100> </applet> */ public class JComboBoxDemo extends JApplet implements
ItemListener { JLabel jl; ImageIcon green, red, black, yellow; public void init() { Container contentPane =
getContentPane(); contentPane.setLayout(new FlowLayout()); JComboBox jc = new JComboBox();
jc.addItem("Green"); jc.addItem("Red"); jc.addItem("Black"); jc.addItem("Yellow"); jc.addItemListener(this);
contentPane.add(jc); jl = new JLabel(new ImageIcon("green.jpg")); contentPane.add(jl); } public void
itemStateChanged(ItemEvent ie) { String s = (String)ie.getItem(); jl.setIcon(new ImageIcon(s + ".jpg")); } }
B) import javax.swing.*; /* <applet code="JComboBoxDemo" width=300 height=100> </applet> */ public
class JComboBoxDemo extends JApplet implements ItemListener { JLabel jl; ImageIcon green, red, black,
yellow; public void init() { Container contentPane = getContentPane(); contentPane.setLayout(new
FlowLayout()); JComboBox jc = new JComboBox(); jc.addItem("Green"); jc.addItem("Red");
jc.addItem("Black"); jc.addItem("Yellow"); jc.addItemListener(this); contentPane.add(jc); jl = new JLabel(new
ImageIcon("green.jpg")); contentPane.add(jl); } public void itemStateChanged(ItemEvent ie) { String s =
(String)ie.getItem(); jl.setIcon(new ImageIcon(s + ".jpg")); } } C) import java.awt.*; import java.awt.event.*;
import javax.swing.*; /* <applet code="JComboBoxDemo" width=300 height=100> </applet> */ public class
JComboBoxDemo extends JApplet implements ItemListener { JLabel jl; ImageIcon green, red, black,
yellow; public void init() { contentPane.setLayout(new FlowLayout()); JComboBox jc = new JComboBox();
jc.addItem("Green"); jc.addItem("Red"); jc.addItem("Black"); jc.addItem("Yellow"); jc.addItemListener(this);
contentPane.add(jc); jl = new JLabel(new ImageIcon("green.jpg")); contentPane.add(jl); } public void
itemStateChanged(ItemEvent ie) { String s = (String)ie.getItem(); jl.setIcon(new ImageIcon(s + ".jpg")); } }
D) import java.awt.*; import java.awt.event.*; import javax.swing.*; /* <applet code="JComboBoxDemo"
width=300 height=100> </applet> */ public class JComboBoxDemo extends JApplet implements
ItemListener { JLabel jl; ImageIcon green, red, black, yellow; public void init() { Container contentPane =
getContentPane(); contentPane.setLayout(new FlowLayout()); JComboBox jc = new JComboBox();
jc.addItem("Green"); jc.addItem("Red"); jc.addItem("Black"); jc.addItem("Yellow"); jc.addItemListener(this);
contentPane.add(jc); jl = new JLabel(new ImageIcon("green.jpg")); public void
itemStateChanged(ItemEvent ie) { String s = (String)ie.getItem(); jl.setIcon(new ImageIcon(s + ".jpg")); } }
Answer - import java.awt.*; import java.awt.event.*; import javax.swing.*; /* <applet
code="JComboBoxDemo" width=300 height=100> </applet> */ public class JComboBoxDemo
extends JApplet implements ItemListener { JLabel jl; ImageIcon green, red, black, yellow; public
void init() { Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout());
JComboBox jc = new JComboBox(); jc.addItem("Green"); jc.addItem("Red"); jc.addItem("Black");
jc.addItem("Yellow"); jc.addItemListener(this); contentPane.add(jc); jl = new JLabel(new
ImageIcon("green.jpg")); contentPane.add(jl); } public void itemStateChanged(ItemEvent ie) { String
s = (String)ie.getItem(); jl.setIcon(new ImageIcon(s + ".jpg")); } }

Question) Choose the correct code to display the following output.

https://localhost/dashboard/ques_ans_22517.php 32/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) import java.awt.*; import javax.swing.*; /* <applet code="JScrollPaneDemo" width=300 height=250>


</applet> */ 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; JScrollPane jsp = new JScrollPane(jp, v,
h); contentPane.add(jsp, BorderLayout.CENTER); }} B) /* <applet code="JScrollPaneDemo" width=300
height=250> </applet> */ 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; JScrollPane jsp = new JScrollPane(jp, v,
h); contentPane.add(jsp, BorderLayout.CENTER); } C) import java.awt.*; import javax.swing.*; /* <applet
code="JScrollPaneDemo" width=300 height=250> </applet> */ 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++) { } int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPane jsp = new
JScrollPane(jp, v, h); contentPane.add(jsp, BorderLayout.CENTER); } D) import java.awt.*; import
javax.swing/* <applet code="JScrollPaneDemo" width=300 height=250> </applet> */ 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; JScrollPane jsp = new JScrollPane(jp, v,
h); contentPane.add(jsp, BorderLayout.CENTER); } Answer - import java.awt.*; import
javax.swing.*; /* <applet code="JScrollPaneDemo" width=300 height=250> </applet> */ 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; JScrollPane jsp = new
JScrollPane(jp, v, h); contentPane.add(jsp, BorderLayout.CENTER); }}

Question) Which of the following are ways to create a Frame?

A) By creating the object of Frame class (association) B) By extending Frame class (inheritance) C) a
and b D) none of these Answer - a and b

Question) Choose the correct code to display the following output.

A) 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() { // Get content pane Container contentPane = getContentPane();// Set
layout manager contentPane.setLayout(new BorderLayout());// Create top node of tree
DefaultMutableTreeNode top = new DefaultMutableTreeNode("Options");// Create subtree of "A"
DefaultMutableTreeNode a=new DefaultMutableTreeNode("A"); top.add(a); DefaultMutableTreeNode a1 =
new DefaultMutableTreeNode("A1"); a.add(a1); DefaultMutableTreeNode a2 = new
DefaultMutableTreeNode("A2"); a.add(a2);// Create subtree of "B" DefaultMutableTreeNode b=new
DefaultMutableTreeNode("B"); top.add(b); DefaultMutableTreeNode b1 = new

https://localhost/dashboard/ques_ans_22517.php 33/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

DefaultMutableTreeNode("B1"); b1 = new DefaultMutableTreeNode("B1"); b.add(b1);


DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3"); b.add(b3);// Create tree tree = new
JTree(top);// Add tree to a scroll pane int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPane jsp = new
JScrollPane(tree, v, h);// Add scroll pane to the content pane contentPane.add(jsp, BorderLayout.CENTER);
// Add text field to applet jtf = new JTextField("", 20); contentPane.add(jtf, BorderLayout.SOUTH);//
Anonymous inner class to handle mouse clicks 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("");}} B) 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() { // Get content pane Container contentPane =
getContentPane();// Set layout manager contentPane.setLayout(new BorderLayout());// Create top node of
tree DefaultMutableTreeNode top = new DefaultMutableTreeNode("Options");// Create subtree of "A"
DefaultMutableTreeNode a=new DefaultMutableTreeNode("A");top.add(a); DefaultMutableTreeNode a1 =
new DefaultMutableTreeNode("A1"); a.add(a1);DefaultMutableTreeNode a2 = new
DefaultMutableTreeNode("A2"); a.add(a2);// Create subtree of "B" 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);// Create tree tree = new JTree(top);// Add tree to a scroll pane
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h =
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPane jsp = new JScrollPane(tree,
v, h);// Add scroll pane to the content pane contentPane.add(jsp, BorderLayout.CENTER); // Add text field to
applet jtf = new JTextField("", 20); contentPane.add(jtf, BorderLayout.SOUTH);// Anonymous inner class to
handle mouse clicks 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("");}} C)
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() { // Get content pane Container contentPane = getContentPane();// Set
layout manager contentPane.setLayout(new BorderLayout());// Create top node of tree
DefaultMutableTreeNode top = new DefaultMutableTreeNode("Options");// Create subtree of "A"
DefaultMutableTreeNode a=new DefaultMutableTreeNode("A"); top.add(a); DefaultMutableTreeNode a1 =
new DefaultMutableTreeNode("A1"); a.add(a1); // Create subtree of "B" DefaultMutableTreeNode b=new
DefaultMutableTreeNode("B"); top.add(b); DefaultMutableTreeNode b1 = new
DefaultMutableTreeNode("B1"); b1 = new DefaultMutableTreeNode("B1"); b.add(b1);
DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3"); b.add(b3);// Create tree tree = new
JTree(top);// Add tree to a scroll pane int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPane jsp = new
JScrollPane(tree, v, h);// Add scroll pane to the content pane contentPane.add(jsp, BorderLayout.CENTER);
// Add text field to applet jtf = new JTextField("", 20); contentPane.add(jtf, BorderLayout.SOUTH);//
Anonymous inner class to handle mouse clicks 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("");}} D) 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() { // Get content pane Container contentPane =
getContentPane();// Set layout manager contentPane.setLayout(new BorderLayout());// Create top node of
tree DefaultMutableTreeNode top = new DefaultMutableTreeNode("Options");// Create subtree of "A"
DefaultMutableTreeNode a=new DefaultMutableTreeNode("A"); top.add(a); DefaultMutableTreeNode a1 =
new DefaultMutableTreeNode("A1"); a.add(a1); DefaultMutableTreeNode a2 = new
https://localhost/dashboard/ques_ans_22517.php 34/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

DefaultMutableTreeNode("A2"); a.add(a2); // Create subtree of "B" DefaultMutableTreeNode b=new


DefaultMutableTreeNode("B"); top.add(b); DefaultMutableTreeNode b1 = new
DefaultMutableTreeNode("B1"); b1 = new DefaultMutableTreeNode("B1"); b.add(b1); tree = new
JTree(top);// Add tree to a scroll pane int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPane jsp = new
JScrollPane(tree, v, h);// Add scroll pane to the content pane contentPane.add(jsp, BorderLayout.CENTER);
// Add text field to applet jtf = new JTextField("", 20); contentPane.add(jtf, BorderLayout.SOUTH);//
Anonymous inner class to handle mouse clicks 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("");}} Answer - 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() { // Get content pane
Container contentPane = getContentPane();// Set layout manager contentPane.setLayout(new
BorderLayout());// Create top node of tree DefaultMutableTreeNode top = new
DefaultMutableTreeNode("Options");// Create subtree of "A" DefaultMutableTreeNode a=new
DefaultMutableTreeNode("A");top.add(a); DefaultMutableTreeNode a1 = new
DefaultMutableTreeNode("A1"); a.add(a1);DefaultMutableTreeNode a2 = new
DefaultMutableTreeNode("A2"); a.add(a2);// Create subtree of "B" 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);// Create tree tree = new JTree(top);// Add tree to a scroll
pane int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h =
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPane jsp = new
JScrollPane(tree, v, h);// Add scroll pane to the content pane contentPane.add(jsp,
BorderLayout.CENTER); // Add text field to applet jtf = new JTextField("", 20); contentPane.add(jtf,
BorderLayout.SOUTH);// Anonymous inner class to handle mouse clicks
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("");}}

Question) Give the abbreviation of AWT?

A) Applet Windowing Toolkit B) Abstract Windowing Toolkit C) Absolute Windowing Toolkit D) None of
the above Answer - Abstract Windowing Toolkit

Question) Choose the correct code to display the following output.

https://localhost/dashboard/ques_ans_22517.php 35/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) 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 = { "Name", "Phone", "Fax" }; final
Object[][] data = { { "Pramod", "4567", "8675" }, { "Tausif", "7566", "5555" }, { "Nitin", "5634", "5887" }, {
"Amol", "7345", "9222" }, { "Vijai", "1237", "3333" }, { "Ranie", "5656", "3144" }, { "Mangesh", "5672", "2176"
}, { "Suhail", "6741", "4244" }, { "Nilofer", "9023", "5159" }, { "Jinnie", "1134", "5332" }, { "Heena", "5689",
"1212" }, { "Saurav", "9030", "1313" }, { "Raman", "6751", "1415" } }; JTable table = new JTable(data,
colHeads); 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); } } B) 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 = { "Name", "Phone", "Fax" }; final
Object[][] data = { { "Pramod", "4567", "8675" }, { "Tausif", "7566", "5555" }, { "Nitin", "5634", "5887" }, {
"Amol", "7345", "9222" }, { "Vijai", "1237", "3333" }, { "Ranie", "5656", "3144" }, { "Mangesh", "5672", "2176"
}, { "Suhail", "6741", "4244" }, { "Nilofer", "9023", "5159" }, { "Jinnie", "1134", "5332" }, { "Heena", "5689",
"1212" }, { "Saurav", "9030", "1313" }, { "Raman", "6751", "1415" } }; JTable table = new JTable(data,
colHeads); 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); C) <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 = {
"Name", "Phone", "Fax" }; final Object[][] data = { { "Pramod", "4567", "8675" }, { "Tausif", "7566", "5555" }, {
"Nitin", "5634", "5887" }, { "Amol", "7345", "9222" }, { "Vijai", "1237", "3333" }, { "Ranie", "5656", "3144" }, {
"Mangesh", "5672", "2176" }, { "Suhail", "6741", "4244" }, { "Nilofer", "9023", "5159" }, { "Jinnie", "1134",
"5332" }, { "Heena", "5689", "1212" }, { "Saurav", "9030", "1313" }, { "Raman", "6751", "1415" } }; JTable
table = new JTable(data, colHeads); 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); } } D) import java.awt.*; import
javax.swing.*; /* <applet code="JTableDemo" width=400 height=200> </applet> */ public class JTableDemo
extends JApplet { Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout());
final String[] colHeads = { "Name", "Phone", "Fax" }; final Object[][] data = { { "Pramod", "4567", "8675" }, {
"Tausif", "7566", "5555" }, { "Nitin", "5634", "5887" }, { "Amol", "7345", "9222" }, { "Vijai", "1237", "3333" }, {
"Ranie", "5656", "3144" }, { "Mangesh", "5672", "2176" }, { "Suhail", "6741", "4244" }, { "Nilofer", "9023",
"5159" }, { "Jinnie", "1134", "5332" }, { "Heena", "5689", "1212" }, { "Saurav", "9030", "1313" }, { "Raman",
"6751", "1415" } }; JTable table = new JTable(data, colHeads); 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); } } Answer - 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 = { "Name",
"Phone", "Fax" }; final Object[][] data = { { "Pramod", "4567", "8675" }, { "Tausif", "7566", "5555" }, {
"Nitin", "5634", "5887" }, { "Amol", "7345", "9222" }, { "Vijai", "1237", "3333" }, { "Ranie", "5656",
"3144" }, { "Mangesh", "5672", "2176" }, { "Suhail", "6741", "4244" }, { "Nilofer", "9023", "5159" }, {
"Jinnie", "1134", "5332" }, { "Heena", "5689", "1212" }, { "Saurav", "9030", "1313" }, { "Raman",
"6751", "1415" } }; JTable table = new JTable(data, colHeads); 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); } }

https://localhost/dashboard/ques_ans_22517.php 36/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Which of the below are common network protocols?

A) TCP B) UDP C) TCP and UDP D) FTP Answer - TCP and UDP

Question) Choose the following code for following output :

A) // java Program to create a simple JPanel add components to it import java.awt.event.*; import java.awt.*;
import javax.swing.*; class solution extends JFrame { // JFrame static JFrame f; // JButton static JButton b,
b1, b2; // label to diaplay text static JLabel l; // main class public static void main(String[] args) { // create a
new frame to stor text field and button f = new JFrame("panel"); // create a label to display text l = new
JLabel("panel label"); // create a new buttons b = new JButton("button1"); b1 = new JButton("button2"); b2 =
new JButton("button3"); // create a panel to add buttons JPanel p = new JPanel(); // add buttons and
textfield to panel p.add(b); p.add(b1); p.add(b2); p.add(l); // setbackground of panel
p.setBackground(Color.red); // add panel to frame f.add(p); // set the size of frame f.setSize(300, 300);
f.show(); } } B) // java Program to create a simple JPanel add components to it import java.awt.event.*;
import java.awt.*; import javax.swing.*; class solution extends JFrame { // JFrame static JFrame f; // JButton
static JButton b, b1, b2; // label to diaplay text static JLabel l; // main class public static void main(String[]
args) { // create a new frame to stor text field and button f = new JFrame("panel"); // create a label to display
text l = new JLabel("panel label"); // create a new buttons b = new JButton("button1"); b1 = new
JButton("button2"); b2 = new JButton("button3"); // create a panel to add buttons JPanel p = new JPanel(); //
add buttons and textfield to panel p.add(b); p.add(b1); p.add(b2); p.setBackground(Color.red); // add panel
to frame f.add(p); // set the size of frame f.setSize(300, 300); f.show(); } } C) // java Program to create a
simple JPanel add components to it import java.awt.event.*; import java.awt.*; import javax.swing.*; class
solution extends JFrame { // JFrame static JFrame f; // JButton static JButton b, b1, b2; // label to diaplay
text static JLabel l; // main class public static void main(String[] args) { // create a new frame to stor text field
and button f = new JFrame("panel"); // create a label to display text l = new JLabel("panel label"); // create a
new buttons b = new JButton("button1"); b1 = new JButton("button2"); b2 = new JButton("button3"); //
create a panel to add buttons JPanel p = new JPanel(); // add buttons and textfield to panel p.add(b);
p.add(b1); p.add(b2); p.add(l); // setbackground of panel p.setBackground(Color.red); // add panel to frame
f.add(p); // set the size of frame } } D) // java Program to create a simple JPanel add components to it
import java.awt.event.*; import java.awt.*; import javax.swing.*; class solution extends JFrame { // JFrame
static JFrame f; // JButton static JButton b, b1, b2; // label to diaplay text static JLabel l; // main class public
static void main(String[] args) { // create a new frame to stor text field and button f = new JFrame("panel"); //
create a label to display text b1 = new JButton("button2"); b2 = new JButton("button3"); // create a panel to
add buttons JPanel p = new JPanel(); // add buttons and textfield to panel p.add(b); p.add(b1); p.add(b2);
p.add(l); // setbackground of panel p.setBackground(Color.red); // add panel to frame f.add(p); // set the size
of frame f.setSize(300, 300); f.show(); } } Answer - // java Program to create a simple JPanel add
components to it import java.awt.event.*; import java.awt.*; import javax.swing.*; class solution
extends JFrame { // JFrame static JFrame f; // JButton static JButton b, b1, b2; // label to diaplay text
static JLabel l; // main class public static void main(String[] args) { // create a new frame to stor text
field and button f = new JFrame("panel"); // create a label to display text l = new JLabel("panel
label"); // create a new buttons b = new JButton("button1"); b1 = new JButton("button2"); b2 = new
JButton("button3"); // create a panel to add buttons JPanel p = new JPanel(); // add buttons and
textfield to panel p.add(b); p.add(b1); p.add(b2); p.add(l); // setbackground of panel
p.setBackground(Color.red); // add panel to frame f.add(p); // set the size of frame f.setSize(300, 300);
f.show(); } }

Question) Which of the following statement is used to establish connection with mysql database.

https://localhost/dashboard/ques_ans_22517.php 37/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) Connection conn = DriverManager.getConnection(jdbc:mysql://localhost:3306/booksdb,user,password);


B) Connection conn = DriverManager.getConnected(jdbc:mysql://localhost:3306/booksdb,user, password);
C) Connection conn =
DriverManager.getConnection(jdbc:odbc:mysql://localhost:3306/booksdb,user,password); D) Connection
conn = DriverManager.getConnection(localhost:3306/booksdb,user,password); Answer - Connection
conn = DriverManager.getConnection(jdbc:mysql://localhost:3306/booksdb�,user,password);

Question) Which class provides many methods for graphics programming?

A) javax.awt.graphics B) java.Graphics C) java.awt.Graphics D) None of the above Answer -


java.awt.Graphics

Question) How would you set the color of a graphics context called g to cyan?

A) g.setColor(Color.cyan); B) g.setCurrentColor(cyan); C) g.setColor("Color.cyan"); D) g.setColor(new


Color(cyan)); Answer - g.setColor(Color.cyan);

Question) Which of the following are passed as an argument to the paint( ) method?

A) A Canvas object B) A Graphics object C) An Image object D) A paint object Answer - A


Graphics object

Question) Which of the following methods are invoked by the AWT to support paint and repaint operations?

A) paint( ) B) repaint( ) C) draw( ) D) redraw( ) Answer - paint( )

Question) Which of the following classes have a paint( ) method? a.Canvas b.Image c.Frame d.Graphics

A) b and d B) a and c C) a and b D) c and d Answer - a and c

Question) Which of the following are methods of the Graphics class? a.drawRect( ) b. drawImage( )
c.drawPoint( ) d. drawString( )

A) a , b and c B) a , c and d C) b,c and d D) a, b and d Answer - a, b and d

Question) Which of the following are true? a.The AWT automatically causes a window to be repainted when
a portion of a window has been minimized and then maximized. b.The AWT automatically causes a window
to be repainted when a portion of a window has been covered and then uncovered. c.The AWT
automatically causes a window to be repainted when application data is changed. d. The AWT does not
support repainting operations.

A) a and b B) a and d C) b and c D) a and c Answer - a and b

Question) Given the following code import java.awt.*; public class SetF extends Frame { public static void
main(String argv[]) { SetF s = new SetF(); s.setVisible(true); } } How could you set the frame surface color to
pink and set its width to 300 and height to 200 pixels?

A) s.setBackground(Color.pink); s.setSize(300,200); B) s.setColor(PINK); s.setSize(200,300); C)


s.Background(pink); s.setSize(300,200); D) s.color=Color.pink; s.Size(300,200); Answer -
s.setBackground(Color.pink); s.setSize(300,200);

Question) PreparedStatement interface extends which interface?

A) Statement B) CallableStatement C) ResultSet D) None of the above Answer - Statement

https://localhost/dashboard/ques_ans_22517.php 38/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Consider the following program. Find which statement contains error. import java.awt.*; import
javax.swing.*; public class Demo { public static void main(String args[]) { JFrame f =new JFrame("Toggle
Button Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c=f.getContentPane();
c.add(new JToggleButton("North"),BorderLayout.NORTH); c.add(new
JToggleButton("North"),BorderLayout.EAST); c.add(new JToggleButton("North"),BorderLayout.WEST);
c.add(new JToggleButton("North"),BorderLayout.SOUTH); c.add(new
JToggleButton("North"),BorderLayout.CENTER); f.setSize(300,300); f.setVisible(true); } }

A) error B) No Error C) compile time error D) Run time errror Answer - No Error

Question) Which of the following methods can be used to change the size of a java.awt.Component object?
(A) dimension() (B) setSize() (C) size() (D) resize()

A) (A), (B), (C) and (D) B) (A), (B) and (D) C) (B), (C) and (D) D) (B) and (D) Answer - (B) and
(D)

Question) Consider the following program. Find correct output import java.awt.Color; import
java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import
javax.swing.*; public class BgColor extends JFrame implements ActionListener{ private JButton btn; private
JButton red,blue,green; private JLabel label; public BgColor() { red = new JButton("red");
red.addActionListener(this); add(red); green = new JButton("green"); green.addActionListener(this);
add(green); blue = new JButton("blue"); blue.addActionListener(this); add(blue); setLayout(new
FlowLayout()); setSize(700,700); setTitle("Bit Life - Java program Buttons Clicked");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); label = new JLabel("what is
happening ?"); add(label); } public static void main(String[] args) { new BgColor(); } public void
actionPerformed(ActionEvent e) { if(e.getSource() == btn) { label.setText("button clicked"); } if (e.getSource()
== red) { label.setText("red selected"); getContentPane().setBackground(Color.RED);

A) B) C) D) All of the above Answer - All of the above

Question) find out missing line in following code. Import java.awt.*; import javax.swing.*; public class demo2
extends JApplet { ________________________________ JRadioButton b1=new JRadioButton("Button1') ;
JRadioButton b2=new JRadioButton("Button2"); public void init() { cp.add(b1); cp.add(b2); ButtonGroup
bg=new ButtonGroup(); bg.add(b1); bg.add(b2); } }

A) Container cp=getContentPane() B) JRadioButton( C) ButtonGroup bg=new ButtonGroup(); D)


bg.add(b1); Answer - Container cp=getContentPane()

Question) Observe the following code import java.awt.*; import java.applet.*; import java.util.*; /* <applet
code="BorderLayoutDemo" width=400 height=200> </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.WEST); String msg =
"The reasonable man adapts " + "himself to the world; " + "the unreasonable one persists in " + "trying to
adapt the world to himself. " + "Therefore all progress depends " + "on the unreasonable man. " + " -
George Bernard Shaw "; add(new TextArea(msg), BorderLayout.CENTER); } } What will be the output of the
above program?

https://localhost/dashboard/ques_ans_22517.php 39/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) The output is obtained in Applet with BorderLayout placing button on east,west,north B) The output is
obtained in Applet with BorderLayout placing button on east,west,south and TextArea at center C) The
output is obtained in Applet south and TextArea at center D) The output is obtained in Applet with
BorderLayout placing button on east,west,north,south and TextArea at center Answer - The output is
obtained in Applet with BorderLayout placing button on east,west,north,south and TextArea at
center

Question) Observe the following code import java.awt.*; import javax.swing.*; /* <applet
code="JTableDemo.class" width=400 height=500> </applet> */ public class JTableDemo extends JApplet {
public void init() { Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout());
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_ALWAYS; int h =
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS; JScrollPane jsp = new JScrollPane(table, v,
h); contentPane.add(jsp, BorderLayout.CENTER); } }

A) The output is obtained in table with two rows and two columns with horizontal and vertical scrollbar B)
The output is obtained in table with two rows and three columns with horizontal and vertical scrollbar C)
The output is obtained in table with three rows and three columns with horizontal and vertical scrollbar D)
The output is obtained in table with four rows and three columns with horizontal and vertical scrollbar
Answer - The output is obtained in table with two rows and three columns with horizontal and
vertical scrollbar

Question) Which of the following is true about AWT and Swing Component?

A) AWT Components create a process where as Swing Component create a thread B) AWT Components
create a thread where as Swing Component create a process C) Both AWT and Swing Component create
a process D) Both AWT and Swing Component create a thread Answer - AWT Components
create a process where as Swing Component create a thread

Question) Which of the following is not a constructor of JTree Class

A) JTree(Object obj[]) B) JTree(int x) C) JTree(TreeNode tn) D) JTree() Answer - JTree(int x)

Question) Observe the following program and point out which statement contains error. importjava.awt.*;
importjavax.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 = { "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); } }

A) Error in statement in which JScrollPane is created B) statement in which JScrollPane is Not created C)
No Error in statement in which JScrollPane is created D) Error in statement in which JScrollPane is
deleted Answer - Error in statement in which JScrollPane is created

Question) ............. method is used to execute CREATE Table query.

A) executeQuery() B) executeUpdate() C) execute() D) All of the above Answer -


executeUpdate()

https://localhost/dashboard/ques_ans_22517.php 40/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) The setBackground() method is part of the following class in java.awt package:

A) Graphics B) Component C) Applet D) Container Answer - Component

Question) Find the missing statement in the following code import java.awt.*; import javax.swing.*; /*
<applet code="JLabelDemo" width=250 height=150> </applet> */ public class JLabelDemo extends JApplet
{ public void init() { Container contentPane = getContentPane(); ImageIcon ii = new ImageIcon("IC.jpg");
JLabel jl = new JLabel("IC", ii, JLabel.CENTER); -------------------- } }

A) setcontentPane.add(jl); B) getcontentPane.add(jl); C) contentPane.add(jl); D) contentPane.add(j);


Answer - contentPane.add(jl);

Question) Find the missing statement in the following code import java.awt.*; import javax.swing.*; /*
<applet code="JTextFieldDemo" width=300 height=50> </applet> */ public class JTextFieldDemo extends
JApplet { JTextField jtf; public void init() { Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout()); _________________________________ contentPane.add(jtf);
}}

A) jtf = new JTextField(15); B) jtf = JTextField(15); C) Both A & B D) None Of the above Answer -
jtf = new JTextField(15);

Question) Which of the following classes are derived from the Container class. Select the four correct
answers. a. Component b.Panel c.Dialog d.Frame

A) b ,c and d B) a ,b and c C) a and b D) all of above Answer - b ,c and d

Question) Find the missing statement in the following code import java.awt.*; import java.awt.event.*; import
javax.swing.*; /* <applet code="JButtonDemo" width=250 height=300> </applet> */ public class
JButtonDemo extends JApplet implements ActionListener { JTextField jtf; public void init() { Container
contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); ImageIcon france = new
ImageIcon("green.jpg"); JButton jb = new JButton(france); jb.setActionCommand("Green");
jb.addActionListener(this); contentPane.add(jb); ImageIcon germany = new ImageIcon("red.jpg"); jb = new
JButton(germany); jb.setActionCommand("Red"); jb.addActionListener(this); contentPane.add(jb);
ImageIcon italy = new ImageIcon("yellow.jpg"); jb = new JButton(italy); jb.setActionCommand("Yellow");
jb.addActionListener(this); contentPane.add(jb); ImageIcon japan = new ImageIcon("black.jpg"); jb = new
JButton(japan); jb.setActionCommand("Black"); jb.addActionListener(this); contentPane.add(jb); jtf = new
JTextField(15); contentPane.add(jtf); } public void actionPerformed(ActionEvent ae) { ------------------------------
---------- } }

A) jtf.setText(ae.getActionCommand()); B) jtf.setText(ae.setActionCommand()); C)
jtf.setText(ae.ActionCommand()); D) None of the above Answer -
jtf.setText(ae.getActionCommand());

Question) Find the missing statement in the following code import java.awt.*; import java.awt.event.*; import
javax.swing.*; /* <applet code="JCheckBoxDemo" width=400 height=50> </applet> */ public class
JCheckBoxDemo extends JApplet implements ItemListener { JTextField jtf; public void init() { Container
contentPane = getContentPane(); ------------------------------------------------------------ JCheckBox cb = new
JCheckBox("BLUE", true); cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("RED",
false); cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("YELLOW", false);
cb.addItemListener(this); contentPane.add(cb); cb = new JCheckBox("GREEN", false);
cb.addItemListener(this); contentPane.add(cb); jtf = new JTextField(15); contentPane.add(jtf); } public void
itemStateChanged(ItemEvent ie) { JCheckBox cb = (JCheckBox)ie.getItem(); jtf.setText(cb.getText()); } }

https://localhost/dashboard/ques_ans_22517.php 41/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) contentPane.setLayout(FlowLayout()); B) contentPane.Layout(new FlowLayout()); C)


contentPane.getLayout(new FlowLayout()); D) contentPane.setLayout(new FlowLayout()); Answer -
contentPane.setLayout(new FlowLayout());

Question) Find out the correct statement

A) public PreparedStatement prepareStatement(String query)throws IOException{} B) private


PreparedStatement preparedStatement(String query)throws IOException{} C) public PreparedStatement
prepareStatement(String query)throws SQLException{} D) protected PrepareStatement
prepareStatement(String query)throws FileNotFoundException{} Answer - public
PreparedStatement prepareStatement(String query)throws SQLException{}

Question) Which of the following classes are derived from the Container class. Select the correct answers.
a. Panel b Window c Frame d Component e Dialog

A) a,b,d,c B) a, b, c, e C) b, c,d,e D) a, e,c,d Answer - a, b, c, e

Question) Which are the parameters of setString() method?

A) String value,String paramIndex B) String paramIndex, String value C) int paramIndex, int value D) int
paramIndex, String value Answer - int paramIndex, String value

Question) Name the class used to represent a GUI application window, which is optionally resizable and
can have a title bar, an icon, and menus. Select the one correct answer.

A) Window B) Panel C) Dialog D) Frame Answer - Frame

Question) What components will be needed to get following output?

A) . Label, TabbedPane, CheckBox B) Panel, TabbedPane, List C) TabbedPane, List, Applet D) Applet,
TabbedPane, Pane Answer - Panel, TabbedPane, List

Question) What is the return type of executeQuery() method?

A) int B) connection C) ResultSet D) None of the above Answer - ResultSet

Question) Button B1=new Button("Submit");Which method is used to obtain output as "Submit"

A) setText() B) setLabel() C) getText() D) getLabel() Answer - getLabel()

Question) Which of these package contains classes and interfaces for networking?

A) java.io B) java.util C) java.net D) java.network Answer - java.net

Question) Label lb=new Label("Advanced Java");Which method is used to obtain output as "Advanced
Java"

A) setText() B) setLabel() C) getText() D) getLabel() Answer - getText()

Question) By using ___________ control, we can create a set of mutually exclusive checkboxes in which
one and only one checkbox in the group can be checked at a time.

A) Button B) Checkbox C) CheckboxGroup D) List Answer - CheckboxGroup

https://localhost/dashboard/ques_ans_22517.php 42/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Superclass of TextField and TextArea classes that is used to create single Line or Multiple
textfields are

A) TextBox B) TextComponent C) Checkbox D) Choice Answer - TextComponent

Question) Subclass of TextComponent is

A) TextArea B) Button C) Label D) Checkbox Answer - TextArea

Question) Following are constructors of TextArea class

A) TextArea(String str) B) TextArea(int numLines,int numChars) C) TextArea(String str,int numLines,int


numChars,int sBars) D) All of above Answer - All of above

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

A) TCP/IP B) DNS C) Socket D) Proxy Server Answer - TCP/IP

Question) Which of the following is not an AWT class?

A) Label B) CheckboxGroup C) RadioButton D) List Answer - RadioButton

Question) How many ports of TCP/IP are reserved for specific protocols?

A) 10 B) 1024 C) 2048 D) 512 Answer - 1024

Question) Multiple selection of items in List is possible using following Constructor.

A) List() B) List(int numRows) C) List(int numRows,booean multipleSelect) D) None of these


Answer - List(int numRows,booean multipleSelect)

Question) Which object can be constructed to show and select any number of choices in the visible
window?

A) Button B) Choice C) List D) Label Answer - List

Question) Which method of Choice class is used to return index of the selected item ?

A) getSelectedIndex() B) getSelectedIndexes() C) getSelectedItem() D) getSelectedItems()


Answer - getSelectedIndex()

Question) Swing components that don't rely on Native GUI are reffered to as __________

A) GUI component B) heavy weight component C) Ligthweight component D) middle weight component
Answer - Ligthweight component

Question) How many bits are in a single IP address?

A) 8 B) 16 C) 32 D) 64 Answer - 32

Question) Developing GUI is swings does_________

A) uses buttons, menus, icons and all other components B) should be easy for the end user to manipulate
C) stands for Graphic Use Interaction D) Both (a) and (c) Answer - Both (a) and (c)

https://localhost/dashboard/ques_ans_22517.php 43/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Which of these functions is called to display the output of an applet?

A) display() B) paint() C) displayApplet() D) PrintApplet() Answer - paint()

Question) _____AWT Component is used to select only one item from popup list of textual items

A) Button B) Choice C) Checkbox D) All of above Answer - Choice

Question) Choose the correct code to display the following output.

A) import javax.swing.*; import java.awt.*; import java.awt.event.*; public class LabelExample extends
Frame implements ActionListener{ JTextField tf; JLabel l; JButton b; LabelExample(){ tf=new JTextField();
tf.setBounds(50,50, 150,20); l=new JLabel(); l.setBounds(50,100, 250,20); b=new JButton("Find IP");
b.setBounds(50,150,95,30); b.addActionListener(this); add(b);add(tf);add(l); setSize(400,400);
setLayout(null); setVisible(true); } public void actionPerformed(ActionEvent e) { try{ String host=tf.getText();
String ip=java.net.InetAddress.getByName(host).getHostAddress(); l.setText("IP of "+host+" is: "+ip);
}catch(Exception ex){System.out.println(ex);} } public static void main(String[] args) { new LabelExample(); }
} B) import javax.swing.*; import java.awt.*; import java.awt.event.*; public class LabelExample extends
Frame implements ActionListener{ JTextField tf; JLabel l; JButton b; LabelExample(){ tf=new JTextField();
tf.setBounds(50,50, 150,20); b=new JButton("Find IP"); b.setBounds(50,150,95,30);
b.addActionListener(this); add(b);add(tf);add(l); setSize(400,400); setLayout(null); setVisible(true); } public
void actionPerformed(ActionEvent e) { try{ String host=tf.getText(); String
ip=java.net.InetAddress.getByName(host).getHostAddress(); l.setText("IP of "+host+" is: "+ip);
}catch(Exception ex){System.out.println(ex);} } public static void main(String[] args) { new LabelExample(); }
} C) import javax.swing.*; import java.awt.*; import java.awt.event.*; public class LabelExample extends
Frame implements ActionListener{ JTextField tf; JLabel l; JButton b; LabelExample(){ tf=new JTextField();
tf.setBounds(50,50, 150,20); l=new JLabel(); l.setBounds(50,100, 250,20); b=new JButton("Find IP");
b.setBounds(50,150,95,30); b.addActionListener(this); add(b);add(tf);add(l); setSize(400,400);
setLayout(null); setVisible(true); } public static void main(String[] args) { new LabelExample(); } } D)
implements ActionListener{ LabelExample(){ tf=new JTextField(); tf.setBounds(50,50, 150,20); l=new
JLabel(); l.setBounds(50,100, 250,20); b=new JButton("Find IP"); b.setBounds(50,150,95,30);
b.addActionListener(this); add(b);add(tf);add(l); setSize(400,400); setLayout(null); setVisible(true); } public
void actionPerformed(ActionEvent e) { try{ String host=tf.getText(); String
ip=java.net.InetAddress.getByName(host).getHostAddress(); l.setText("IP of "+host+" is: "+ip);
}catch(Exception ex){System.out.println(ex);} } public static void main(String[] args) { new LabelExample(); }
} Answer - import javax.swing.*; import java.awt.*; import java.awt.event.*; public class
LabelExample extends Frame implements ActionListener{ JTextField tf; JLabel l; JButton b;
LabelExample(){ tf=new JTextField(); tf.setBounds(50,50, 150,20); l=new JLabel();
l.setBounds(50,100, 250,20); b=new JButton("Find IP"); b.setBounds(50,150,95,30);
b.addActionListener(this); add(b);add(tf);add(l); setSize(400,400); setLayout(null); setVisible(true); }
public void actionPerformed(ActionEvent e) { try{ String host=tf.getText(); String
ip=java.net.InetAddress.getByName(host).getHostAddress(); l.setText("IP of "+host+" is: "+ip);
}catch(Exception ex){System.out.println(ex);} } public static void main(String[] args) { new
LabelExample(); } }

Question) Which of these methods can be used to output a string in an applet?

A) display() B) print() C) drawString() D) String() Answer - drawString()

Question) Which component cannot be added to a container?

A) JPanel B) JButton C) JFrame D) None of the above Answer - JFrame

https://localhost/dashboard/ques_ans_22517.php 44/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Choose the correct syntax to create a table student with attributes rollno,studname, marks

A) CREATE TABLE STUDENT VALUES (ROLLNO 1, STUDNAME "ABC",MARKS 90); B) CREATE


TABLE STUDENT (ROLLNO INT, STUDNAME VARCHAR(10), MARKS INT); C) CREATE TABLE
STUDENT (ROLLNO NUMBER, STUDNAME STRING, MARKS INT); D) All of the Above Answer -
CREATE TABLE STUDENT (ROLLNO INT, STUDNAME VARCHAR(10), MARKS INT);

Question) Which statement is true with respect to the following code? import java.awt.*; import
javax.swing.*; public class Test { public static void main(String[] args) { JFrame frame = new JFrame("My
Frame"); frame.getContentPane().add(new JButton("OK")); frame.getContentPane().add(new
JButton("Cancel")); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200);
frame.setVisible(true); }}

A) Only button OK is displayed B) Only button Cancel is displayed. C) Both button OK and button Cancel
are displayed and button OK is displayed on the left side of button OK. D) Both button OK and button
Cancel are displayed and button OK is displayed on the right side of button OK. FeedbackYour answer is
correct. Answer - Only button Cancel is displayed.

Question) What is the Message displayed in the applet 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); } } /*<applet code="myapplet.class" width=200 height=200></applet>*/

A) A Simple Applet B) a simple applet C) Compile error D) None of the above Answer - A Simple
Applet

Question) How many bits value does IPv4 and IPv6 uses to represent the address?

A) 32 and 64 B) 64 and 128 C) 32 and 128 D) . 64 and 64 Answer - 32 and 128

Question) What is the length of the application box made by this program? import java.awt.*; import
java.applet.*; public class myapplet extends Applet { Graphic g; g.drawString("A Simple Applet", 20, 20); }

A) 20 B) Default value C) Compilation Error D) Runtime Error Answer - Compilation Error

Question) TCP,FTP,Telnet,SMTP,POP etc. are examples of ?

A) Socket B) IP Address C) Protocol D) MAC Address Answer - Protocol

Question) Which of following is subclass of java.awt.Component?

A) Container B) LayoutManger C) Color D) Font Answer - Container

Question) When should your program call repaint()?

A) Never--that is the system's job. B) Only once when the frame is created. C) Whenever it has made a
change to what should be displayed in the Frame. D) Always---whenever any method finishes
Answer - Whenever it has made a change to what should be displayed in the Frame.

Question) Consider the following code:import java.awt.*;import javax.swing.*;public class Test { public static
void main(String[] args) { Component c = new JButton("OK"); JFrame frame = new JFrame("My Frame");
frame.add(c); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }}

https://localhost/dashboard/ques_ans_22517.php 45/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) You cannot add a Swing component directly to a JFrame. Instead, you have to add it to a JFrame's
contentPane using frame.getContentPane().add(c). B) You cannot assign a JButton to a variable of
java.awt.Component. C) All of the above D) None of the above Answer - You cannot assign a
JButton to a variable of java.awt.Component.

Question) Which packages required for the program. public class DeleteRecord { public static void
main(String args[]) throws Exception { String sql; Scanner sc=new Scanner(System.in);
System.out.println("Please Enter the ID no:"); int num = sc.readInt();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:stud","scott","tiger"); Statement stmt=con.createStatement();
int affectedRecords = stmt.executeQuery("select * from student where rollno="+num); br.close();
stmt.close(); con.close(); } }

A) import java.sql.*; import java.util.*; B) import java.io.*; import java.util.*; C) import java.sql.*; import
java.io.*; D) import java.sql.*; import java.stdio.*; Answer - import java.sql.*; import java.util.*;

Question) A Swing component can be viewed based on what state it's in, how it looks, and what it does.
This is known as the model-view- __________ model

A) Model B) Controller C) View D) None of the above Answer - Controller

Question) Analyse the following code? import javax.swing.*; import java.awt.*; public class Test extends
JFrame { public Test() { setLayout(new FlowLayout()); add(new JButton("Java")); add(new JButton("Java"));
add(new JButton("Java")); add(new JButton("Java")); } public static void main(String [] args) { JFrame frame
= new Test(); frame.setSize(200,100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true); } }

A) Four buttons are displayed with the same text java B) One buttons are displayed with the same text
java C) Three buttons are displayed with the same text java D) Five buttons are displayed with the same
text java Answer - Four buttons are displayed with the same text java

Question) Analyse the following code import javax.swing.*; Import javax.swing.border.*; Import java.awt.*;
Public class Test extends JFrame { Public Test() { Border border=new TitledBorder("My button"); Jbutton
jbt1=new JButton("OK"); Jbutton jbt=new JButton("Cancel"); Jbt1.setBorder(border); Jbt2.setBorder(border);
Add(jbt1,BorderLayout.NORTH); Add(jbt2,BorderLayout.NORTH); } Public static void main(String[] args){
JFrame frame=new Test(); Frame.setSize(200,100);
Frame.setDefaultCloseOperation(JFrame.ExIT_ON_CLOSE); Frame.setVisible(true); } }

A) The program has run time error B) The program has compile error C) No error D) None of the above
Answer - The program has compile error

Question) To get the following output complete the code given below import java.awt.*; import javax.swing.*;
/* <applet code="jscroll" width=300 height=250> </applet> */ public class jscroll extends JApplet { public
void init() { Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); } } int
v = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS; int h =
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPanejsp = new JScrollPane(jp, v,
h); contentPane.add(jsp, BorderLayout.CENTER); } }

https://localhost/dashboard/ques_ans_22517.php 46/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) Container contentPane = getContentPane(); contentPane.setLayout(new GridLayout()); B) JPanel jp =


new JPanel(); jp.setLayout(new GridLayout(20, 20)); C) int b = 0; for(int i = 0; i < 20; i++) { for(int j = 0; j <
20; j++) { jp.add(new JButton( D) JPanel jp = new JPanel(); jp.setLayout(new GridLayout(3,3)); int b = 0;
for(int i = 0; i <3; i++) { for(int j = 0; j <3; j++) { jp.add(new JButton( Answer - JPanel jp = new
JPanel(); jp.setLayout(new GridLayout(3,3)); int b = 0; for(int i = 0; i <3; i++) { for(int j = 0; j <3; j++) {
jp.add(new JButton(

Question) Following code shows given output

A) import java.awt.*; public class ChoiceExampleSimple extends Frame { String msg=" ";
ChoiceExampleSimple(String s){ setLayout(null); setVisible(true); setSize(400,400); setTitle("Frame");
Choice c=new Choice(); c.add("C"); c.add("C++"); c.add("Java"); c.add("PHP"); c.add("Android");
c.setBounds(100,100,100,100); add(c); } public static void main(String args[]) { ChoiceExampleSimple
f=new ChoiceExampleSimple("Frame"); } } B) import java.awt.*; public class ChoiceExampleSimple
extends Frame { String msg=" "; ChoiceExampleSimple(String s){ setLayout(null); setVisible(true);
setSize(400,400); setTitle("Frame"); Choice c=new Choice(); c.add("C"); c.add("C++"); c.add("Java");
c.add("PHP"); c.add("Android"); c.setBounds(100,100,100,100); } public static void main(String args[]) {
ChoiceExampleSimple f=new ChoiceExampleSimple("Frame"); } } C) import java.awt.*; public class
ChoiceExampleSimple extends Frame { String msg=" "; ChoiceExampleSimple(String s){ setLayout(null);
setVisible(true); setSize(400,400); setTitle("Frame"); c.add("C"); c.add("C++"); c.add("Java"); c.add("PHP");
c.add("Android"); c.setBounds(100,100,100,100); add(c); } public static void main(String args[]) {
ChoiceExampleSimple f=new ChoiceExampleSimple("Frame"); } } D) All of above Answer - import
java.awt.*; public class ChoiceExampleSimple extends Frame { String msg=" ";
ChoiceExampleSimple(String s){ setLayout(null); setVisible(true); setSize(400,400);
setTitle("Frame"); Choice c=new Choice(); c.add("C"); c.add("C++"); c.add("Java"); c.add("PHP");
c.add("Android"); c.setBounds(100,100,100,100); add(c); } public static void main(String args[]) {
ChoiceExampleSimple f=new ChoiceExampleSimple("Frame"); } }

Question) For using Swing control one must import______________________________package.

A) import javax.swing.* B) import java.swing.* C) Both A & B D) None of the above Answer -
import javax.swing.*

Question) In Swing Buttons are the subclasses of which class?

A) AbstractButton B) Button C) Both A & B D) None of the above Answer - AbstractButton

Question) Applet class is a subclass of the panel class, which is again a subclass of the__________class

A) object B) Component AW C) awt D) Container Answer - Container

Question) Consider the program given below import java.awt.*; import java.awt.event.*; import
javax.swing.*; import java.applet.*; /* <applet code="test" width=300 height=100> </applet> */ public class
test extends JApplet { public void init() { Container co = getContentPane(); co.setLayout(new FlowLayout());
JComboBox jc=new JComboBox(); jc.addItem("cricket"); jc.addItem("football"); jc.addItem("hockey");
jc.addItem("tennis"); co.add(jc); } } Choose the correct statement to get the following output

A) JComboBox jc=new JComboBox("Applet Viewer:test"); B) JComboBox jc=new JComboBox(cricket,


football, hockey, tennis); C) JComboBox jc=new JComboBox(); D) None of the above. Answer -
JComboBox jc=new JComboBox();

Question) The____________method is called every time the applet receives focus as a result of scrolling in
the active window.

https://localhost/dashboard/ques_ans_22517.php 47/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) init( ) B) start( ) C) stop( ) D) destroy( ) Answer - start( )

Question) Which of the following applet tag is legal to embed an applet class named Test into a webpage?

A) ; B) <applet> code=Test.class width=200 height=100> </applet> C) <applet code="Test.class"


width=200 height=100> </applet> D) <applet param=Test.class width=200 height=100> </applet>
Answer - <applet code="Test.class" width=200 height=100> </applet>

Question) Find the missing statement in the following code import javax.swing.*; class gui{ public static void
main(String args[]){ JFrame frame = new JFrame("My First GUI");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300,300); JButton button1 =
new JButton("Press"); frame.getContentPane().add(button1); ---------------------------------- } }

A) frame.setVisible(true); B) frame.setVisible(False); C) Both A & B D) None of the above Answer


- frame.setVisible(true);

Question) The___________class is an abstract class that represents the display area of the applet.

A) display() B) graphics C) text D) area Answer - graphics

Question) Find the missing statement in the following code import javax.swing.*; /* <applet
code="JTabbedPaneDemo" width=400 height=100> </applet> */ public class JTabbedPaneDemo extends
JApplet { public void init() { JTabbedPane jtp = new JTabbedPane(); jtp.addTab("Languages", new
LangPanel()); jtp.addTab("Colors", new ColorsPanel()); jtp.addTab("Flavors", new FlavorsPanel());
getContentPane().add(jtp); } } class LangPanel extends JPanel { public LangPanel() { JButton b1 = new
JButton("Marathi"); add(b1); JButton b2 = new JButton("Hindi") add(b2); JButton b3 = new
JButton("Bengali"); add(b3) JButton b4 = new JButton("Tamil");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); } } class FlavorsPanel
extends JPanel { public FlavorsPanel() { JComboBox jcb = new JComboBox(); jcb.addItem("Vanilla");
jcb.addItem("Chocolate"); jcb.addItem("Strawberry"); add(jcb); } }

A) Error B) No Error C) Both A & B D) None of the above Answer - Error

Question) Which of the following method of applet class is used to clear the screen and calls the paint( )
method

A) update( ) B) paint( ) C) repaint( ) D) reupdate( ) Answer - update( )

Question) Observe the following code and Choose the correct output from the given options : import
java.awt.*; import javax.swing.*; public class test extends JFrame { public test() { super("Login Form");
Container cpane=getContentPane(); cpane.setLayout(new FlowLayout()); JLabel l1=new JLabel("Name");
JLabel l2=new JLabel("Password"); JTextField t1=new JTextField(20); JTextField t2=new JTextField(20);
JButton b1=new JButton("Login"); JButton b2=new JButton("Cancel"); cpane.add(l1); cpane.add(t1);
cpane.add(l2); cpane.add(t2); cpane.add(b1); cpane.add(b2);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String args[]) { test obj=new
test(); obj.setVisible(true); obj.setSize(200,200); } }

A) B) C) None of the above D) Answer -

Question) The__________method is automatically called the first time the applet is displayed on the screen
and every time the applet receives focus.

https://localhost/dashboard/ques_ans_22517.php 48/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) update( ) B) paint( ) C) repaint( ) D) reupdate( ) Answer - paint( )

Question) Find the missing statement in the following code import java.awt.*; import java.awt.event.*; import
javax.swing.*; public class ButtonDemo extends JFrame { JButton yes,no,close; JLabel lbl; ButtonDemo() {
yes = new JButton("YES"); no = new JButton ("No"); close = new JButton ("CLOSE"); lbl = new JLabel ("");
__________________________ setSize (400,200); add(yes); add(no); add(close); add(lbl); setVisible(true);
//setDefaultCloseOperation(JFrame.EXIT_NO_CLOSE); ButtonHandler bh = new ButtonHandler();
yes.addActionListener(bh); yes.addActionListener(bh); no.addActionListener(bh);
close.addActionListener(bh); } class ButtonHandler implements ActionListener { public void
actionPerformed(ActionEvent ae) { if (ae.getSource()==yes) { lbl.setText("Button Yes is pressed"); } if
(ae.getSource()==no) { lbl.setText("Button No is pressed"); } if (ae.getSource()==close) { System.exit(0); } } }
public static void main(String args[]) { n

A) setLayout (new GridLayout(4,1)); B) setLayout (new borderLayout(4,1)); C) setLayout (new


flowLayout(4,1)); D) None of the above Answer - setLayout (new GridLayout(4,1));

Question) The___________method is defined by the AWT which causes the AWT runtime system to
execute a call to your applet’s update( ) method.

A) update( ) B) paint( ) C) repaint( ) D) reupdate() Answer - repaint( )

Question) which code gives following output ?

A) import java.awt.*; import java.applet.*; /* <applet code="Buttonexample" width=300 height=200>


</applet> */ public class Buttonexample extends Applet { public void init() { Button b1=new Button("ok");
Button b2=new Button("cancel"); Button b3=new Button("exit"); add(b1);add(b2);add(b3); } } B) import
java.awt.*; import java.applet.*; /* <applet code="Buttonexample" width=300 height=200> </applet> */ public
class Buttonexample extends Applet { public void init() { Button b1=new Button("ok"); Button b2=new
Button("cancel"); Button b3=new Button("exit"); add(b2);add(b1);add(b3); } } C) import java.awt.*; import
java.applet.*; /* <applet code="Buttonexample" width=300 height=200> </applet> */ public class
Buttonexample extends Applet { public void init() { Button b1=new Button("ok"); Button b2=new
Button("cancel"); Button b3=new Button("exit"); add(b3);add(b1);add(b2); } } D) import java.awt.*; import
java.applet.*; /* <applet code="Buttonexample" width=300 height=200> </applet> */ public class
Buttonexample extends Applet { public void init() { Button b1=new Button("ok"); Button b2=new
Button("cancel"); Button b3=new Button("exit"); add(b3);add(b2);add(b1); } } Answer - import
java.awt.*; import java.applet.*; /* <applet code="Buttonexample" width=300 height=200> </applet> */
public class Buttonexample extends Applet { public void init() { Button b1=new Button("ok"); Button
b2=new Button("cancel"); Button b3=new Button("exit"); add(b2);add(b1);add(b3); } }

Question) What is the output of the following code ? import java.awt.event.*; import java.awt.*; import
javax.swing.*; class solution extends JFrame { static JFrame f; static JButton b, b1, b2, b3; static JLabel l;
public static void main(String[] args) { f = new JFrame("panel"); l = new JLabel("panel label"); b = new
JButton("button1"); b1 = new JButton("button2"); b2 = new JButton("button3"); b3 = new JButton("button4");
JPanel p = new JPanel(new BorderLayout()); p.add(b, BorderLayout.NORTH); p.add(b1,
BorderLayout.SOUTH); p.add(b2, BorderLayout.EAST); p.add(b3, BorderLayout.WEST); p.add(l,
BorderLayout.CENTER); p.setBackground(Color.red); f.add(p); f.setSize(300, 300); f.show(); } }

A) B) C) D) Answer -

Question) In Swing ____________is a component that displays rows and columns of data.

A) Tabpane B) Table C) Scrollpane D) None of the above Answer - Table

https://localhost/dashboard/ques_ans_22517.php 49/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Which of the following method is used to display numerical values in applet?

A) paint( ) B) drawstring( ) C) draw( ) D) convert( ) Answer - drawstring( )

Question) Consider the following program What will be the output? import java.sql.*; class Example { public
static void main(String srgs[]) { try { Class.forname("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:STUD"); System.out.println("connection Established"); }
catch(sQLException e) { System.out.pritln("SQL error"); } catch(Exceptionn e) { System.out.println("error");
}}}

A) error ; missing B) Error } missing C) Connection Established D) SQL error Answer -


Connection Established

Question) We can change the text to be displayed by an applet by supplying new text through
a____________tag.

A) B) C) D) Answer - 379a.jpeg

Question) Which of the following is/are the possible values for alignment attribute of Applet tag. i) Top ii) Left
iii) Middle iv) Baseline

A) i, ii and iii only B) ii, iii and iv only C) i, iii and iv only D) All i, ii, iii and iv Answer - All i, ii, iii
and iv

Question) We can change the text to be displayed by an applet by supplying new text through________tag.

A) SPACE=pixels B) HSPACE=pixels C) HWIDTH=pixels D) HBLANK=pixels Answer -


HSPACE=pixels

Question) Debug the following program 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 = { "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 =
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 Horizontal Scrollbar is declared D) None of the above Answer - Error in
statement in which Horizontal Scrollbar is declared

Question) __________attribute of applet tag specify the width of the space on the HTML page that will
reserved for the applet.

A) WIDTH=pixels B) HSPACE=pixels C) HWIDTH=pixels D) HBLANK=pixels Answer -


WIDTH=pixels

https://localhost/dashboard/ques_ans_22517.php 50/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Consider following code and state missing code? import java.sql.*; class Demo1{ public static
void main(String args[])throws Exception { try {
Class.forName("_________________________________________"); Connection
con=DriverManager.getConnection("Jdbc:Odbc:demo"); Statement st=con.createStatement(); ResultSet
rs=st.executeQuery("select * from student"); while(rs.next()) { System.out.println(rs.getInt(1)+"
"+rs.getString(2)+" " +rs.getString(3)); } catch(Exception e) {} } }

A) sun.odbc.jdbc.OdbcJdbcDriver B) oracle.jdbc.driver.OracleDriver C) sun.jdbc.odbc.JdbcOdbcDriver


D) None of the Above Answer - sun.jdbc.odbc.JdbcOdbcDriver

Question) What is the super class of container?

A) java.awt.Container B) java.awt.Component C) java.awt.Panel D) java.awt.Layout Answer -


java.awt.Component

Question) Following methods belongs to which class? 1) public void add(Component c) 2) public void
setSize(int width,int height) 3) public void setLayout(LayoutManager m) 4) public void setVisible(boolean)

A) Graphics class B) Component class C) Both A & B D) None of the above Answer -
Component class

Question) __________is a server that is mediator between real web server and client application.

A) IBMServer B) SQLServer C) ReserverSockets D) Proxy server Answer - Proxy server

Question) Port number 80 is reserved for

A) FTP B) Telnet C) e-mail D) HTTP Answer - HTTP

Question) View Data helps you to maintain data when you move from ------------------------------.

A) Controller to View B) Temp Data C) Controller to Data D) None of above Answer - Controller
to View

Question) What is the purpose of JTable?

A) JTable object displays ONLY rows B) JTable object displays ONLY columns C) JTable object displays
both rows and columns D) JTable object displays data in Tree form Answer - JTable object
displays both rows and columns

Question) MVC is composed of three components:

A) Member Vertical Controller B) Model View Control C) Model View Controller D) Model Variable
Centered Answer - Model View Controller

Question) __________method is used to know the type of content used in the URL.

A) ContentType() B) Contenttype() C) GetContentType() D) getContentType() Answer -


getContentType()

Question) Which of the following is TRUE?

https://localhost/dashboard/ques_ans_22517.php 51/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) Action method can be static method in a controller class B) Action method can be private method in a
controller class C) Action method can be protected method in a controller class D) Action method must
be public method in a controller class Answer - Action method must be public method in a
controller class

Question) Port number 25 is reserved for

A) FTP B) Telnet C) SMTP D) HTTP Answer - SMTP

Question) To hold component ___________ are used

A) Container B) AWT C) Both D) None Answer - Container

Question) What parameter we can pass to public int getInt() method?

A) int columnIndex B) int row C) Both D) None of the above Answer - int columnIndex

Question) Find the error in the following code : import java.awt.*; import javax.swing.*; /*<applet code="test"
width=200 height=200> </applet>*/ public class test extends JApplet { public void init() { Container
c=getContentPane(); JTabbedPane jp=new JTabbedPane(); JButton b1=new JButton("COMP.TECH");
p1.add(b1); JButton b2=new JButton("INFO.TECH"); p1.add(b2); JButton b3=new JButton("ELEC.ENGG");
p1.add(b3); JButton b4=new JButton("FIRST"); p2.add(b4); JButton b5=new JButton("SECOND");
p2.add(b5); JButton b6=new JButton("THIRD"); p2.add(b6); jp.addTab("Branch",p1); jp.addTab("Year",p2);
c.add(jp); } }

A) JPanel p2=new JPanel(); JButton b3=new JButton(); B) variable p1 ,cannot find symbol C) /*<applet
code="test" width=200 height=200> </applet>*/ D) jp.addTab() Answer - variable p1 ,cannot find
symbol

Question) List out few different return types of a controller action method

A) View Result B) Javascript Result C) Redirect Result D) All of these Answer - All of these

Question) What are the steps for the execution of an MVC project?

A) Receive first request for the application B) Performs routing C) Creates MVC request handler D) All
of the above Answer - All of the above

Question) Which method of a Frame object is used to place a GUI component (such as a button) into the
Frame?

A) . insert( Component c ) B) add( Component c ) C) draw( Component c ) D) click( Component c )


Answer - add( Component c )

Question) Which of following is TRUE?

A) The controller redirects incoming request to model B) The controller executes an incoming request C)
The controller controls the data D) The controller render html to view Answer - The controller
executes an incoming request

Question) Which class is used to encapsulate IP address and DNS?

A) URLConnection B) Telnet C) DatagramPacket D) netAddress Answer - netAddress

https://localhost/dashboard/ques_ans_22517.php 52/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) A JFrame supports three operations when the user closes the window. Which of the choices
below is not one of the three:

A) LOWER_ON_CLOSE B) DISPOSE_ON_CLOSE. C) DO_NOTHING_ON_CLOSE D)


HIDE_ON_CLOSE. Answer - LOWER_ON_CLOSE

Question) What is the return type of getString() method?

A) String B) int C) byte D) short Answer - String

Question) Which is the correct code for displaying following output

A) import javax.swing.*; public class TableExample { JFrame f; TableExample(){ f=new JFrame(); String
data[][]={ {"101","Amit","670000"}, {"102","Jai","780000"}, {"101","Sachin","700000"}}; String column[]=
{"ID","NAME","SALARY"}; JTable jt=new JTable(data,column); jt.setBounds(30,40,200,300); JScrollPane
sp=new JScrollPane(jt); f.add(sp); f.setSize(300,400); f.setVisible(true); } public static void main(String[]
args) { } } B) import javax.swing.*; public class TableExample { JFrame f; TableExample(){ f=new JFrame();
String data[][]={ {"101","Amit","670000"}, {"102","Jai","780000"}, {"101","Sachin","700000"}}; String
column[]={"ID","NAME","SALARY"}; JTable jt=new JTable(data,column); jt.setBounds(30,40,200,300);
JScrollPane sp=new JScrollPane(jt); f.add(sp); } public static void main(String[] args) { new TableExample();
} } C) import javax.swing.*; public class TableExample { JFrame f; TableExample(){ f=new JFrame(); String
data[][]={ {"101","Amit","670000"}, {"102","Jai","780000"}, {"101","Sachin","700000"}}; String column[]=
{"ID","NAME","SALARY"}; JTable jt=new JTable(data,column); jt.setBounds(30,40,200,300);
f.setSize(300,400); f.setVisible(true); } public static void main(String[] args) { new TableExample(); } } D)
import javax.swing.*; public class TableExample { JFrame f; TableExample(){ f=new JFrame(); String data[]
[]={ {"101","Amit","670000"}, {"102","Jai","780000"}, {"101","Sachin","700000"}}; String column[]=
{"ID","NAME","SALARY"}; JTable jt=new JTable(data,column); jt.setBounds(30,40,200,300); JScrollPane
sp=new JScrollPane(jt); f.add(sp); f.setSize(300,400); f.setVisible(true); } public static void main(String[]
args) { new TableExample(); } } Answer - import javax.swing.*; public class TableExample {
JFrame f; TableExample(){ f=new JFrame(); String data[][]={ {"101","Amit","670000"},
{"102","Jai","780000"}, {"101","Sachin","700000"}}; String column[]={"ID","NAME","SALARY"};
JTable jt=new JTable(data,column); jt.setBounds(30,40,200,300); JScrollPane sp=new
JScrollPane(jt); f.add(sp); f.setSize(300,400); f.setVisible(true); } public static void main(String[]
args) { new TableExample(); } }

Question) Select correct output for following code: import javax.swing.*; import java.awt.event.*; class
RadioButtonExample extends JFrame implements ActionListener{ JRadioButton rb1,rb2; JButton b;
RadioButtonExample(){ rb1=new JRadioButton("Male"); rb1.setBounds(100,50,100,30); rb2=new
JRadioButton("Female"); rb2.setBounds(100,100,100,30); ButtonGroup bg=new ButtonGroup();
bg.add(rb1);bg.add(rb2); b=new JButton("click"); b.setBounds(100,150,80,30); b.addActionListener(this);
add(rb1);add(rb2);add(b); setSize(300,300); setLayout(null); setVisible(true); } public void
actionPerformed(ActionEvent e){ if(rb1.isSelected()){ JOptionPane.showMessageDialog(this,"You are
Male."); } if(rb2.isSelected()){ JOptionPane.showMessageDialog(this,"You are Female."); } } public static
void main(String args[]){ new RadioButtonExample(); }}

A) B) C) D) Answer -

Question) Port number 21 is reserved for

A) FTP B) Telnet C) e-mail D) HTTP Answer - FTP

Question) Select the code for following output:

https://localhost/dashboard/ques_ans_22517.php 53/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) import javax.swing.*; public class TabbedPaneExample { TabbedPaneExample(){ f=new JFrame();


JTextArea ta=new JTextArea(200,200); JPanel p1=new JPanel(); p1.add(ta); JPanel p2=new JPanel();
JPanel p3=new JPanel(); JTabbedPane tp=new JTabbedPane(); tp.setBounds(50,50,200,200);
tp.add("main",p1); tp.add("visit",p2); tp.add("help",p3); f.add(tp); f.setSize(400,400); f.setLayout(null);
f.setVisible(true); } public static void main(String[] args) { new TabbedPaneExample(); }} B) import
javax.swing.*; public class TabbedPaneExample { JFrame f; TabbedPaneExample(){ f=new JFrame();
JTextArea ta=new JTextArea(200,200); JPanel p1=new JPanel(); p1.add(ta); JPanel p2=new JPanel();
JPanel p3=new JPanel(); JTabbedPane tp=new JTabbedPane(); tp.setBounds(50,50,200,200);
tp.add("main",p1); tp.add("visit",p2); tp.add("help",p3); f.add(tp); f.setSize(400,400); f.setLayout(null);
f.setVisible(true); } public static void main(String[] args) { new TabbedPaneExample(); }} C) import
javax.swing.*; public class TabbedPaneExample { JFrame f; TabbedPaneExample(){ f=new JFrame();
JTextArea ta=new JTextArea(200,200); p1.add(ta); JPanel p2=new JPanel(); JPanel p3=new JPanel();
JTabbedPane tp=new JTabbedPane(); tp.setBounds(50,50,200,200); tp.add("main",p1); tp.add("visit",p2);
tp.add("help",p3); f.add(tp); f.setSize(400,400); f.setLayout(null); f.setVisible(true); } public static void
main(String[] args) { new TabbedPaneExample(); }} D) import javax.swing.*; public class
TabbedPaneExample { JFrame f; TabbedPaneExample(){ f=new JFrame(); JTextArea ta=new
JTextArea(200,200); JPanel p1=new JPanel(); p1.add(ta); JPanel p2=new JPanel(); JPanel p3=new
JPanel(); JTabbedPane tp=new JTabbedPane(); tp.setBounds(50,50,200,200); f.add(tp); f.setSize(400,400);
f.setLayout(null); f.setVisible(true); } public static void main(String[] args) { new TabbedPaneExample(); }}
Answer - import javax.swing.*; public class TabbedPaneExample { JFrame f;
TabbedPaneExample(){ f=new JFrame(); JTextArea ta=new JTextArea(200,200); JPanel p1=new
JPanel(); p1.add(ta); JPanel p2=new JPanel(); JPanel p3=new JPanel(); JTabbedPane tp=new
JTabbedPane(); tp.setBounds(50,50,200,200); tp.add("main",p1); tp.add("visit",p2);
tp.add("help",p3); f.add(tp); f.setSize(400,400); f.setLayout(null); f.setVisible(true); } public static
void main(String[] args) { new TabbedPaneExample(); }}

Question) Which of the following statements are true. 1. ResultSet object can be moved forward only and it
is not updatable. 2. The object of ResultSet maintains a cursor pointing to a row of a table. 3. The statement
interface is a factory of ResultSet 4. The performance of the application will be faster if you use
PreparedStatement interface

A) 1,2,3 B) 2,4 C) 1,3,4 D) 1,2,3,4 Answer - 1,2,3,4

Question) The Transmission Control Protocol

A) Support fast transfer of packets B) support connectionless transport of packets C) support unreliable
transport of packets D) support connection oriented transport of packets Answer - support
connection oriented transport of packets

Question) Which of the following methods cannot be called on JLabel?

A) setIcon() B) getText() C) setLabel() D) setBorderLayout() Answer - setBorderLayout()

Question) User Datagram Protocol is__________

A) Support fast transfer of packets B) support connection-less transport of packets C) support unreliable
transport of packets D) All of the above Answer - All of the above

Question) A JTabbedPane does the following operations_____________________

https://localhost/dashboard/ques_ans_22517.php 54/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) arranges GUI components into layers such that only one layer is visible at a time B) allows users to
access a layer of GUI components via a tab C) extends JComponent D) All of the above. Answer -
All of the above.

Question) Where are the tabs on a JTabbedPane placed by default

A) top B) bottom C) left D) right. Answer - top

Question) Find the missing statement from the below given code :- import java.awt.*; import javax.swing.*;
import java.awt.event.*; public class menu extends JFrame { // menubar static JMenuBar mb; // JMenu
static JMenu x; // Menu items static JMenuItem m1, m2, m3; // create a frame static JFrame f; public static
void main() { // create a frame f = new JFrame("Menu demo"); // create a menubar mb = new JMenuBar(); //
create a menu x = new JMenu("Menu"); // create menuitems m1 = new JMenuItem("MenuItem1"); m2 =
new JMenuItem("MenuItem2"); m3 = new JMenuItem("MenuItem3"); // add menu items to menu x.add(m1);
x.add(m2); x.add(m3); // add menu to menu bar ___________________ // add menubar to frame
f.setJMenuBar(mb); // set the size of the frame f.setSize(500, 500); f.setVisible(true); } }

A) m1 = new JMenuItem("MenuItem1"); B) x.add(m1); C) f.setVisible(true); D) mb.add(x); Answer


- mb.add(x);

Question) The Transmission Control Protocol is

A) Low level routing protocol B) Middle level routing protocol C) Higher level routing protocol D) None of
above Answer - Higher level routing protocol

Question) Mnemonics can be used with all sub classes of which class?

A) JComponent B) JMenu C) JMenuItem D) All of the above Answer - All of the above

Question) Menus are attached to the windows by calling___________ method

A) addMenus() B) setMenu() C) setJMenuBar() D) addJMenuBar() Answer - setJMenuBar()

Question) The elements of a _________ Layout are organized in a top to bottom, left to right pattern.

A) Grid B) Border C) Card D) Flow Answer - Flow

Question) From the following program select the output. import java.awt.*; import javax.swing.*; public class
JTPDemo extends JApplet { public void init() { JTabbedPane jt = new JTabbedPane(); jt.add("Colors", new
CPanel()); jt.add( "Fruits", new FPanel()); jt.add("Vitamins", new VPanel( ) ) ; getContentPane().add(jt); } }
class CPanel extends JPanel { public CPanel() { JCheckBox cb1 = new JCheckBox("Red"); JCheckBox cb2
= new JCheckBox("Green"); JCheckBox cb3 = new JCheckBox("Blue"); add(cb1); add(cb2); add(cb3) ; } }
class FPanel extends JPanel { public FPanel() { JComboBox cb = new JComboBox(); cb.addItem("Apple");
cb.addItem("Mango"); cb.addItem("Pineapple"); add(cb); } } class VPanel extends JPanel { public VPanel() {
JButton b1 = new JButton("Vit-A"); JButton b2 = new JButton("Vit-B"); JButton b3 = new JButton("Vit-C");
add(b1); add(b2); add(b3); } }

A) B) C) Both A & B D) None of the above Answer -

Question) Internet Protocol is

A) Low level routing protocol B) Middle level routing protocol C) Higher level routing protocol D) None of
above Answer - Low level routing protocol

https://localhost/dashboard/ques_ans_22517.php 55/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Cookies were originally designed for

A) Client-side programming B) Server-side programming C) Both Client-side & Server-side programming


D) web programming Answer - Server-side programming

Question) What happens if setSize() is not called on a JFrame ?

A) The window is displayed at its preferred size B) The window is not displayed C) The window is
displayed at its absolute size D) Only the title bar appears Answer - The window is not displayed

Question) When the user press Enter key in a JTextField, the GUI component generates an_____________
, _______________ which is processed by an object that implements the interface.

A) ActionEvent, ActionListener B) ActionEvent, TextEventListener. C) TextEvent, TextListener D)


TextEvent, ActionEventListener Answer - ActionEvent, ActionListener

Question) The following specifies the advantages of ____ It is lightweight. It supports pluggable look and
feel. It follows MVC (Model View Controller) architecture.

A) AWT B) SWING C) Both A & B D) None of the above Answer - SWING

Question) What is in terms of JDBC ,a DataSource

A) A DataSource is the basic service for managing a set of JDBC drivers B) DataSource is a java
representation of physical data source C) DataSource is a registry point D) DataSource is a factory of
connections to a physical data source Answer - DataSource is a factory of connections to a
physical data source

Question) Which of the following encapsulates an SQL statement which is passed to the database to be
parsed, compiled, planned and executed?

A) DriverManager B) Connection C) JDBC Driver D) Statement Answer - Statement

Question) Which driver is efficient and preferable for using JDBC applications?

A) Type 1 B) Type 2 C) Type 3 D) Type 4 Answer - Type 4

Question) Which packages contains JDBC classes?

A) java.jdbc B) java.jdbc.sql C) java.sql D) java.rdb Answer - java.sql

Question) Which of the following methods are needed for loading the database driver in JDBC?

A) resultSet method B) class.forName() method C) getConnection() D) Both A and B Answer -


class.forName() method

Question) Is the JDBC-ODBC bridge multithreaded ?

A) True B) False C) can't predict D) don't know Answer - True

Question) ________ 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 - MySQL

https://localhost/dashboard/ques_ans_22517.php 56/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Which driver is efficient and always preferable for using JDBC applications

A) Type 1 driver B) Type 2 driver C) Type 3 driver D) Type 4 driver Answer - Type 4 driver

Question) Which model does a Java applet or application talks directly to the data source?

A) Two Tier Model B) Three Tier Model C) Both A and B D) None of the above Answer - Two Tier
Model

Question) What is the reason that a java program cannot directly communicate with an ODBC driver?

A) ODBC written in C# language B) ODBC written in C language C) ODBC written in C++ language D)
None of the above Answer - ODBC written in C language

Question) Which models do the JDBC API support for the database access?

A) Two Tier Model B) Three Tier Model C) Both A and B D) None of the above Answer - Both A
and B

Question) ODBC stands for?

A) Open database connectivity B) Open database concept C) Open database communications D) None
of the above Answer - Open database connectivity

Question) Which class has traditionally been the backbone of the JDBC architecture?

A) the JDBC driver manager B) the JDBC driver test suite C) the JDBC-ODBC bridge D) All mentioned
above Answer - the JDBC driver manager

Question) Which method is used to establish the connection with the specified url in a Driver Manager
class?

A) public static void registerDriver(Driver driver) B) public static void deregisterDriver(Driver driver) C)
public static Connection getConnection(String url) D) None of the above Answer - public static
Connection getConnection(String url)

Question) Consider the following program.What should be the correction done in the program to get correct
output? import java.sql.*; class Ddemo1 {{ 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" + " " + "Roll_No" + " " +
"Avg");while(rs.next()) { System.out.println(rs.getString(1)+" "+rs.getInt(2)+" "+rs.getDouble(3)); } s.close();
c.close(); }}

A) Missing semicolon B) Missing { C) Missing } D) Missing statement. Answer - Missing


statement.

https://localhost/dashboard/ques_ans_22517.php 57/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Consider the following program Select the statement that should be added to the program to get
correct output. import java.sql.*; public class db { public static void main(String args[])throws Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c
=DriverManager.getConnection("jdbc:odbc:XYZ","",""); PreparedStatement s=c.prepareStatement( "update
db3 set Name=? where 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"+" "+"Roll no"+" "+"Avg"); while(rs.next()) { System.out.println(rs.getString(1)+"
"+rs.getInt(2)+" "+rs.getDouble(3)); } s.close(); c.close(); }}

A) s.executeUpdate() B) c.createStatement( ) C) s.close() D) c.close() Answer -


s.executeUpdate()

Question) Consider the following program. What should be the correction done in the program to get correct
output? class Ddemo1 {public static void main(String args[]) throws 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" + " " + "Roll_No" + " " + "Avg");
while(rs.next()) { System.out.println(rs.getString(1)+" "+rs.getInt(2)+" "+rs.getDouble(3)); } s.close();
c.close(); }}

A) Missing semicolon B) Missing { C) Missing } D) Missing package statement. Answer - Missing


package statement.

Question) Which of the following is correct about driver interface of JDBC?

A) JDBC driver is an interface enabling a Java application to interact with a database. B) JDBC API is an
application interface of javafor connecting java as back end C) Both A and B D) None of the above
Answer - JDBC driver is an interface enabling a Java application to interact with a database.

Question) Which of the following is correct about Statement?

A) Used for general-purpose access to your database. B) Useful when you are using static SQL
statements at runtime. C) Both of the above. D) None of the above. Answer - Both of the above.

Question) Connection object can be initialized using the____________method of the Driver Manager class.

A) putConnection() B) setConnection() C) Connection() D) getConnetion() Answer -


getConnetion()

Question) The _________________ method executes an SQL statement that may return multiple results.

A) .executeUpdate() B) executeQuery() C) execute() D) noexecute() Answer - execute()

Question) ________Use to execute parameterized query?

A) Statement Interface B) PreparedStatement interface C) ResultSet Interface D) None of the above


Answer - PreparedStatement interface

Question) Every driver must provide a class that should implement the___________

A) Driver interface B) Driver manager C) Driver class D) Driver Answer - Driver interface

Question) How can you execute a stored procedure in the database?

https://localhost/dashboard/ques_ans_22517.php 58/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) Call method execute() on a CallableStatement object B) Call method executeProcedure() on a


Statement object C) Call method execute() on a StoredProcedure object D) Call method run() on a
ProcedureCommand object Answer - Call method execute() on a CallableStatement object

Question) Which of the following is false as far as type 4 driver is concern?

A) Type 4 driver is native protocol, pure java driver B) Type 4 drivers are 100% Java compatible C) Type
4 drivers uses Socket class to connect to the database D) Type 4 drivers can not be used with Netscape
Answer - Type 4 drivers can not be used with Netscape

Question) Which driver is efficient and always preferable for using JDBC applications?

A) Type 4 B) Type 3 C) Type 2 D) Type 1 Answer - Type 4

Question) The JDBC-ODBC bridge is

A) Three tiered B) Multithreaded C) Best for any platform D) All of the above Answer -
Multithreaded

Question) Which driver is called as thin-driver in JDBC?

A) Type-4 driver B) Type-1 driver C) Type-2 driver D) Type-3 driver Answer - Type-4 driver

Question) _____interface allows storing results of query?

A) Statement B) Connection C) ResultSet D) None of the above Answer - ResultSet

Question) Which layout manager should you use to arrange the components of container in tabular form?

A) Grid Layout B) Card Layout C) Border Layout D) Flow Layout Answer - Grid Layout

Question) Which of the following is the default layout for a applet?

A) Grid Layout B) Card Layout C) Border Layout D) Flow Layout Answer - Flow Layout

Question) Which of the following is the default layout for Frame?

A) Grid Layout B) Card Layout C) Border Layout D) Flow Layout Answer - Border Layout

Question) Which of the following statement is correct to change the layout of an applet?

A) setLayoutManager(new GridLayout()); B) setLayout(new GridLayout(2,2)); C) setGridLayout(2,2); D)


setBorderLayout(); Answer - setLayout(new GridLayout(2,2));

Question) Which method is used to set the layout of a container?

A) startLayout() B) initLayout() C) layoutContainer() D) setLayout() Answer - setLayout()

Question) Which containers use a Borderlayout as their default layout?

A) Window B) Frame C) Dialog D) All of the above Answer - All of the above

Question) --------------arranges the components as a deck of cards such that only one component is visible
at a time.

https://localhost/dashboard/ques_ans_22517.php 59/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) Grid Layout B) Card Layout C) Border Layout D) Flow Layout Answer - Card Layout

Question) Select the correct option to get the given output.

A) import java.awt.*; import javax.swing.*; public class Border { JFrame f; Border(){ f=new JFrame(); JButton
b1=new JButton("NORTH");; JButton b2=new JButton("SOUTH");; JButton b3=new JButton("EAST");;
JButton b4=new JButton("WEST");; JButton b5=new JButton("CENTER");; f.add(b1,BorderLayout.NORTH);
f.add(b2,BorderLayout.SOUTH); f.add(b3,BorderLayout.EAST); f.add(b4,BorderLayout.WEST);
f.add(b5,BorderLayout.CENTER); f.setSize(300,300); f.setVisible(true); } public static void main(String[]
args) { new Border(); } } B) import java.awt.*; import javax.swing.*; public class Border { JFrame f; Border()
{ f=new JFrame(); JButton b1=new JButton("NORTH");; JButton b2=new JButton("SOUTH");; JButton
b3=new JButton("EAST");; JButton b4=new JButton("WEST");; JButton b5=new JButton("CENTER");;
f.add(b1,BorderLayout.NORTH); f.add(b2,BorderLayout.RIGHT); f.add(b3,BorderLayout.EAST);
f.add(b4,BorderLayout.LEFT); f.add(b5,BorderLayout.CENTER); f.setSize(300,300); f.setVisible(true); }
public static void main(String[] args) { new Border(); } } C) import java.awt.*; import javax.swing.*; public
class Border { JFrame f; Border(){ f=new JFrame(); JButton b1=new JButton("NORTH");; JButton b2=new
JButton("SOUTH");; JButton b3=new JButton("EAST");; JButton b4=new JButton("WEST");; JButton
b5=new JButton("CENTER");; f.add(b1,BorderLayout.TOP); f.add(b2,BorderLayout.RIGHT);
f.add(b3,BorderLayout.BOTTOM); f.add(b4,BorderLayout.LEFT); f.add(b5,BorderLayout.CENTER);
f.setSize(300,300); f.setVisible(true); } public static void main(String[] args) { new Border(); } } D) import
java.awt.*; import javax.swing.*; public class Border { JFrame f; Border(){ f=new JFrame(); JButton b1=new
JButton("NORTH");; JButton b2=new JButton("SOUTH");; JButton b3=new JButton("EAST");; JButton
b4=new JButton("WEST");; JButton b5=new JButton("CENTER");; f.add(b1,BorderLayout.TOP);
f.add(b2,BorderLayout.SOUTH); f.add(b3,BorderLayout.BOTTOM); f.add(b4,BorderLayout.WEST);
f.add(b5,BorderLayout.CENTER); f.setSize(300,300); f.setVisible(true); } public static void main(String[]
args) { new Border(); } } Answer - import java.awt.*; import javax.swing.*; public class Border {
JFrame f; Border(){ f=new JFrame(); JButton b1=new JButton("NORTH");; JButton b2=new
JButton("SOUTH");; JButton b3=new JButton("EAST");; JButton b4=new JButton("WEST");;
JButton b5=new JButton("CENTER");; f.add(b1,BorderLayout.NORTH);
f.add(b2,BorderLayout.SOUTH); f.add(b3,BorderLayout.EAST); f.add(b4,BorderLayout.WEST);
f.add(b5,BorderLayout.CENTER); f.setSize(300,300); f.setVisible(true); } public static void
main(String[] args) { new Border(); } }

Question) import java.awt.*; import javax.swing.*; public class MyFlowLayout{ JFrame f; MyFlowLayout(){
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");
f.add(b1);f.add(b2);f.add(b3);f.add(b4);f.add(b5); ----------------------------------------- //setting flow layout of right
alignment f.setSize(300,300); f.setVisible(true); } public static void main(String[] args) { new
MyFlowLayout(); } } Find the missing statement to get the following output

A) f.setLayout(new FlowLayout()); B) f.setLayout(new FlowLayout(FlowLayout.RIGHT)); C)


f.setLayout(new FlowLayout(FlowLayout.CENTRE)); D) f.setLayout(new FlowLayout(FlowLayout.LEFT));
Answer - f.setLayout(new FlowLayout(FlowLayout.RIGHT));

Question) Which of the following layout manager should be used so that every component occupies the
same size in the container?

A) Grid Layout B) Card Layout C) Border Layout D) Flow Layout Answer - Grid Layout

https://localhost/dashboard/ques_ans_22517.php 60/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) import java.awt.*; class SampleFrame extends Frame { SampleFrame(String title) { super(title); } }
class FileDialogDemo { public static void main(String args[]) { Frame f = new SampleFrame("File Dialog
Demo"); ---------------------------- f.setSize(100, 100); FileDialog fd = new FileDialog(f, "File Dialog");
fd.setVisible(true); } } Find the missing statement to get the given output.

A) fd.setVisible(true); B) f.setVisible(false); C) fd.setVisible(false); D) f.setVisible(true); Answer -


f.setVisible(true);

Question) In CardLayout where components of every card are added?

A) Window B) Panel C) Applet D) Frame Answer - Panel

Question) Select correct statement to add component in south region-----

A) add(component obj,FlowLayout.SOUTH); B) add(component obj,BorderLayout.RIGHT); C)


add(component obj,BorderLayout.SOUTH); D) add(component obj,FlowLayout.RIGHT); Answer -
add(component obj,BorderLayout.SOUTH);

Question) Which of the following statements are used to create panel in border layout?

A) Frame p=new Frame(new BorderLayout()); B) Panel p=new Panel(); p.setLayout(new BorderLayout());


C) Panel p=new Panel(); D) Panel p=new Panel(); p.setLayout(new Border()); Answer - Panel
p=new Panel(); p.setLayout(new BorderLayout());

Question) ---------------is used to position components in an applet window.

A) Layout Manager B) addComponent(); C) add() D) Both a and b Answer - Layout Manager

Question) What is use of GridLayout Manager ?

A) To lay out components in a two-dimensional grid B) To lay components in tabular form C) Both a and b
D) none of the above Answer - Both a and b

Question) Which of the following is used to rollback a JDBC transaction?

A) rollback() B) rollforward() C) deleteTransaction() D) RemoveTransaction() Answer - rollback()

Question) When the message "No Suitable Driver" occurs?

A) When the driver is not registered by Class.forname() method B) When the user name, password and
the database does not match C) When the JDBC database URL passed is not constructed properly D)
When the type 4 driver is used Answer - When the JDBC database URL passed is not
constructed properly

Question) What is the disadvantage of Type-4 Native-Protocol Driver?

A) At client side, a separate driver is needed for each database B) Type-4 driver is entirely written in Java
C) The driver converts JDBC calls into vendor-specific database protocol D) It does not support to read
MySQL data Answer - At client side, a separate driver is needed for each database

Question) The Java software Bridge provides JDBC access via__________

A) ODBC drivers B) JDBC API C) Both A and B D) None of the above Answer - ODBC drivers

https://localhost/dashboard/ques_ans_22517.php 61/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Which statement about JDBC are true

A) JDBC is an API to connect relational-object and XML data sourses B) JDBC stands for Java Database
Connectiivity C) JDBC is an API to access relational database. D) JDBC is an API to bridge the object-
relational mismatch between OO programs and relational databases Answer - JDBC stands for
Java Database Connectiivity

Question) Which of the following are interfaces in javax.servlet.http package?

A) HttpServletRequest B) HttpServletResponse C) HttpSession D) All of the above Answer - All


of the above

Question) Which of the following informs an object that it is bound to or unbound from an HTTP session?

A) HttpServletRequest B) HttpServlet C) HttpSession D) HttpSessionBindingListener Answer -


HttpSessionBindingListener

Question) -----------------provides a way to identify a user across more than one page request or visit to a
Web site and to store information about that user.

A) HttpServletRequest B) HttpServlet C) HttpSession D) HttpSessionBindingListener Answer -


HttpSession

Question) ------------------- class provides methods to handle HTTP requests and responses

A) HttpServlet B) GenericServlet C) HttpSessionEvent D) None of the above Answer -


HttpServlet

Question) Which type of driver converts JDBC calls into network protocol used by database management
system directly?

A) Type 1 B) Type 2 C) Type 3 D) Type 4 Answer - Type 4

Question) Which JDBC driver types can be used either in applet or servlet code?

A) Both Type 1 and Type 2 B) Both Type 1 and Type 3 C) Both Type 3 and Type 4 D) Type 4 only
Answer - Both Type 3 and Type 4

Question) How many JDBC driver types does Sun define?

A) 1 B) 2 C) 3 D) 4 Answer - 4

Question) String[] getSelectedItems() is the method of _________ class.

A) List B) Choice C) Button D) TextArea Answer - List

Question) ______class is used to create radiobutton in AWT.

A) List B) Choice C) Checkbox D) CheckboxGroup Answer - CheckboxGroup

Question) __________ is used when user wants to enter text that is not displayed,such as password.

A) setEditable() B) setEchoChar() C) getSelectedText() D) setText() Answer - setEchoChar()

https://localhost/dashboard/ques_ans_22517.php 62/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Which of the following is correct statement? Consider t1 as TextField object.

A) t1.setEchoChar('*'); B) t1.setEchoChar("*"); C) t1.setEchoChar('**'); D) None of these Answer -


t1.setEchoChar('*');

Question) To create radiobutton in Applet which of the following are valid statements ?

A) CheckboxGroup cbg=new CheckboxGroup(); Checkbox cb1=new Checkbox("java",true,cbg); Checkbox


cb2=new Checkbox("php",true,cbg); B) CheckboxGroup cbg=new CheckboxGroup(); Checkbox cb1=new
Checkbox("java",true,cbg); Checkbox cb2=new Checkbox("php",false,cbg); C) CheckboxGroup cbg=new
CheckboxGroup(); Checkbox cb1=new Checkbox("java",false,cbg); Checkbox cb2=new
Checkbox("php",false,cbg); D) All of above Answer - All of above

Question) Which is the correct statement to produce following output ?

A) List l1=new List(4); B) List l1=new List(3,true); C) List l1=new List(3,false); D) List l1=new List();
Answer - List l1=new List(3,true);

Question) In the Delegation Event Model, a user interface element is able to delegate, the processing of an
event............................

A) a separate piece of code B) A source generates an event C) a separate elements in a graphical user
interface D) None of above Answer - a separate piece of code

Question) In The delegation Event Model, ................

A) an Event propogated up the containment hierarchy B) a source generates an event and sends it to one
or more listeners. C) notification sent to all components in containment hierarchy. D) None of Above
Answer - a source generates an event and sends it to one or more listeners.

Question) Which of the following classes in Java contains swing version of an applet?

A) JButton B) JApplet C) AbstractButton D) JLabel Answer - JApplet

Question) Which of the following value is not available to align arguments to use in Swing Constants
interface?

A) Left B) Right C) Middle D) Leading Answer - Middle

Question) Which of the following classes of Java swing extends Applet class?

A) JButton B) JApplet C) AbstractButton D) None of these Answer - JApplet

Question) In Java swing, which of the following components is/are represented by a rectangular area in
which a component may be viewed?

A) Scroll pane B) Tabbed pane C) Combo boxes D) None of these Answer - Scroll pane

Question) Swing components are ultimately derived form which of the following ?

A) javax.awt.* B) java.awt.* C) javax.swing.JComponent D) java.swing.* Answer -


javax.swing.JComponent

https://localhost/dashboard/ques_ans_22517.php 63/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Identify the layout manager for the given output container having a row of components that
should all be displayed at the same size, filling the container's entire area.

A) Grid Layout B) Card Layout C) Border Layout D) Flow Layout Answer - Grid Layout

Question) Swing components are preceded by the letter

A) S B) A C) X D) J Answer - J

Question) The syntax for creating and setting layout manager object is--------------

A) LayoutManager Obj= new LayoutManager(); B) LayoutManager Obj= new LayoutManager();


setLayout(Obj); C) setLayout(Obj); LayoutManager Obj= new LayoutManager(); D) setLayout(Obj);
Answer - LayoutManager Obj= new LayoutManager(); setLayout(Obj);

Question) The Swing is an API for providing graphical user interface for

A) Python programs B) Java programs C) C programs D) PHP programs Answer - Java


programs

Question) An Event can be generated by-

A) Pressing a button B) A counter exceeds a value C) cliking the Mouse D) All of the above.
Answer - All of the above.

Question) A general form, event registration method-

A) public void addTypeListener (TypeListener el) B) public void addEventObject(EventObject eo) C)


public void addActionEvent(ActionEvent ae) D) public void addComponetEvent(ComponentEvent ce)
Answer - public void addTypeListener (TypeListener el)

Question) Listeners are created by implementing one or more of the ________________defined by the
java.awt.event package.

A) class B) interfaces C) object D) package Answer - interfaces

Question) import javax.swing.*; import java.awt.*; -------------------------------------------------- public class


FlowLayoutDemo extends JApplet { public void init() { Container cp = getContentPane(); -------------------------
------ JButton button1 = new JButton("Button1"); JButton button2 = new JButton(" Button2"); JButton button3
= new JButton(" Button3"); cp.add(button1); cp.add(button2); cp.add(button3); } } Identify the missing
statement to get the following output.

A) <applet code="FlowLayoutDemo" width=100 height=100></applet> B) <applet


code="FlowLayoutDemo" width=100 height=100></applet> cp.setLayout(); C) <applet code="FlowLayout"
width=100 height=100></applet> cp.setLayout( new FlowLayout() ); D) <applet code="FlowLayoutDemo"
width=100 height=100></applet> cp.setLayout( new FlowLayout() ); Answer - <applet
code="FlowLayoutDemo" width=100 height=100></applet> cp.setLayout( new FlowLayout() );

Question) At The root of the java event class hierarchy is...............

A) ContainerEvent B) ComponentEvent C) WindowEvent D) EventObject Answer - EventObject

https://localhost/dashboard/ques_ans_22517.php 64/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Match the correct pairs- a. getSource( ) i. Determine the type of the event b. toString ( ) ii.
Returns the source of the event c. getID( ) iii- Constructor d. EventObject(Object src) iv- returns the string
equivalent of the event.

A) c-i , a-ii, d-iii, b-iv B) c-ii , a-i, d-iv, b-iii C) c-iii , a-ii, d-i, b-iv D) c-iv , a-iii, d-ii, b-i Answer - c-i ,
a-ii, d-iii, b-iv

Question) An ActionEvent is generated -

A) a button is pressed, component gains or losses keyboard focus, scroll bar is manipulated. B) a button is
pressed, scroll bar is manipulaed, menu item is selected. C) a button is pressed, input received from the
keyboard, window is activated. D) a button is pressed, a list item is double-clicked, menu item is selected.
Answer - a button is pressed, a list item is double-clicked, menu item is selected.

Question) The method getWhen( ) returns-

A) a value that indicates which modifier keys pressed. B) the time at which the event took place. C)
obtain the command name for the invoking ActionEvent object. D) reference to the object that generated
event. Answer - the time at which the event took place.

Question) Which of these are integer constants defined in ActionEvent class-

A) ALT_MASK B) META_MASK C) SHIFT_MASK D) All of the mentioned Answer - All of the


mentioned

Question) Which components of AWT are used to produce following output.

A) TextArea,Label,Button B) Label,Choice,Button C) List,TextField,Button D) List,Label,TextArea


Answer - List,TextField,Button

Question) Select proper output for following.. import java.awt.*; import java.applet.*; public class list extends
Applet { public void init() { Button b1=new Button("OK"); List l=new List(5,true); TextField t1=new
TextField("Languages used"); CheckboxGroup cbg=new CheckboxGroup(); Checkbox c1,c2; c1=new
Checkbox("Server Side",true,cbg); c2=new Checkbox("Client Side",false,cbg); l.add("java"); l.add("php");
l.add("c++"); l.add("c"); l.add("Python"); add(l); add(t1);add(b1);add(c1);add(c2); }} /*<applet code=list.class
height=200 width=200> </applet>*/

A) B) C) D) Answer -

Question) We cannot alter text in TextField when___

A) setEditable(true) B) setEditable(false) C) isEditable() D) All of Above Answer -


setEditable(false)

Question) ____method is used to lock the textfield component

A) getText() B) setText() C) getSelectedText() D) setEditable(false) Answer - setEditable(false)

Question) which is constructor of Checkbox()?

A) Checkbox(String label) B) Checkbox(String label,boolean state) C) Checkbox(String label,boolean


state,CheckboxGroup group) D) All of Above Answer - All of Above

Question) Following are the method(s) of List class

https://localhost/dashboard/ques_ans_22517.php 65/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) getSelectedIndex() B) getSelectedIndexes() C) getSelectedItem() D) All of Above Answer - All


of Above

Question) Which of the following method does not belongs to Choice class.

A) getItem() B) getSelectedIndexes() C) getSelectedItem() D) All of Above Answer -


getSelectedIndexes()

Question) Which of these interfaces define a method actionPerformed()?

A) ComponentListener B) ContainerListener C) ActionListener D) InputListener Answer -


ActionListener

Question) setSelectedCheckbox() is the method of ________

A) Checkbox B) CheckboxGroup C) List D) RadioButton Answer - CheckboxGroup

Question) TextArea supports _____method(s) of TextComponent class

A) select() B) isEditable() C) getText() D) All of above Answer - All of above

Question) Which of these are methods of MouseListener Interface?

A) mouseDragged() B) MouseMotionListener() C) MouseClick() D) MousePressed() Answer -


MousePressed()

Question) What does following line of code do ? TextField text=new TextField(30);

A) Creates text object with 30 rows of text B) Creates text object and initilizes with value 30 C) Creates
text object with 30 columns of text D) This is invalid code Answer - Creates text object with 30
columns of text

Question) How many ways can we align the label in a container ?

A) 1 B) 2 C) 3 D) 4 Answer - 3

Question) AWT includes multiline editor called as ______

A) TextField B) Label C) Button D) TextArea Answer - TextArea

Question) Which are the active controls that support any interaction with the user ?

A) Choice B) List C) Button D) All of Above Answer - All of Above

Question) 1.import java.awt.*; 2.import java.applet.*; 3.public class ChoiceDemo extends Applet 4.{ 5. public
void init() 6. { 7. Button b1=new Button("OK"); 8. Choice l=new Choice(); 9. l.add("java"); 10. l.add("php");
11. l.add("c++"); 12. l.add("c",true); 13. l.add("Python"); 14. add(l); 15. add(b1); 16.}} 17. 18./*<applet
code=choice.class height=200 width=200> 19.</applet>*/ Which statement number shows compilation error
?

A) 7.Button b1=new Button("ok"); B) 8.Choice l=new Choice(); C) 12.l.add("c",true); D) No Compilation


Error in given code Answer - 12.l.add("c",true);

https://localhost/dashboard/ques_ans_22517.php 66/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) import java.awt.*; import java.applet.*; public class choiceDemo extends Applet { public void init()
{ Button b1=new Button("OK"); Choice l=new Choice(); Label lb=new Label("List"); add(lb); l.add("java");
l.add("php"); l.add("c++"); l.add("c"); lb.add("Python"); add(l); add(b1); }} /*<applet code=choice.class
height=200 width=200> </applet>*/ Which is incorrect statement ?

A) Label lb=new Label("List"); B) add(b1); C) lb.add("Python"); D) None of above Answer -


lb.add("Python");

Question) import java.awt.*; import java.applet.*; public class textareaex extends Applet { public void init() {
TextField t2=new TextField("welcome",20,40); TextArea t1=new TextArea(10,30); add(t1);add(t2); }} /*
<applet code=textareaex.class height=200 width=200> </applet>*/ Which statement will give an error ?

A) TextArea t1=new TextArea(10,30); B) TextField t2=new TextField("welcome",20,40); C) public class


textareaex extends Applet D) add(t1);add(t2); Answer - TextField t2=new
TextField("welcome",20,40);

Question) An ItemEvent is generated when............................

A) user clicked the mouse B) keyboard input occurs. C) a checkable menu item is selected or deselected.
D) The window was activated. Answer - a checkable menu item is selected or deselected.

Question) The Swing was previously known as

A) Java shoot B) Java control C) Java Class D) Java Foundation Class Answer - Java
Foundation Class

Question) Swing is an excellent replacement for

A) Abstract Window Toolkit (AWT) B) Java control C) Java drive D) Java class Answer - Abstract
Window Toolkit (AWT)

Question) The following are advanced components that comes with Swing except

A) Trees B) Lists C) Graph D) Table Answer - Graph

Question) Swing components are referred to as platform-independent and thus described to as

A) Heavyweight B) Elements C) Lightweight D) Light Components Answer - Lightweight

Question) In Java Swing, the JTable has a model called

A) JModel B) TableModel C) JRule D) JSwing Answer - JSwing

Question) select the correct output for following code import javax.swing.*; public class FirstSwingExample {
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, width, height
f.add(b);//adding button in JFrame f.setSize(400,500);//400 width and 500 height f.setLayout(null);//using no
layout managers f.setVisible(true);//making the frame visible } }

A) B) C) D) Answer -

https://localhost/dashboard/ques_ans_22517.php 67/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) select the correct output for following code import javax.swing.*; class LabelExample { public
static void main(String args[]) { JFrame f= new JFrame("Label Example"); JLabel l1,l2; l1=new JLabel("First
Label."); l1.setBounds(50,50, 100,30); l2=new JLabel("Second Label."); l2.setBounds(50,100, 100,30);
f.add(l1); f.add(l2); f.setSize(300,300); f.setLayout(null); f.setVisible(true); } }

A) B) C) D) None of the above Answer -

Question) -------------- is the class representing event notifications for changes to sessions within a web
application.

A) HttpServlet B) Cookie C) HttpSessionEvent D) None of the above Answer -


HttpSessionEvent

Question) Which of the following method call can be used to send an error response to the client using the
specified integer 'statusCode' and String error message 'message'?

A) request.sendError(statusCode,message) B) response.sendError(statusCode,message) C)
header.sendError(statusCode,message) D) None of the above Answer -
response.sendError(statusCode,message)

Question) _______method of HttpServletResponse interface can be used to redirect response to another


resource, it may be servlet, jsp or html file.

A) sendRedirect() B) sendError() C) Redirect() D) None of the above Answer - sendRedirect()

Question) Which methods are used to bind the objects on HttpSession instance and get the objects?

A) setAttribute() only B) getAttribute() only C) Both A and B D) None of the above Answer - Both
A and B

Question) getAuthType() returns the name of the _______used to protect the servlet.

A) authentication scheme B) authority Scheme C) Authorization scheme D) none of above


Answer - authentication scheme

Question) ____ returns an enumeration of the header names

A) getHeaderNames() B) getNames() C) getHeader() D) none of the above Answer -


getHeaderNames()

Question) _______ method returns the part of this request's URL that calls the servlet.

A) getServletPath() B) getPathInfo() C) getPathTranslated() D) None of the above Answer -


getServletPath()

Question) Which of the following is not a method of HttpServletRequest interface.

A) isRequestedSessionIdFromCookie( ) B) getHeader(String field ) C) getMethodI( ) D)


addCookie(Cookie cookie) Answer - addCookie(Cookie cookie)

Question) Which class provides system independent server side implementation?

A) Socket B) ServerSocket C) Server D) ServerReader Answer - ServerSocket

https://localhost/dashboard/ques_ans_22517.php 68/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) ------------Determines if the session ID must be encoded in the URL identified as url. If so, returns
the modified version of url. Otherwise, returns url.

A) encodeRedirectURL(String url) B) String encodeURL(String url) C) encode(String url) D) None of the


above Answer - String encodeURL(String url)

Question) ________ returns a boolean indicating whether the named response header has already been
set.

A) void containsHeader(String name) B) boolean containsHeader(String name) C) boolean


containsHeader() D) Boolean isHeader(String name) Answer - boolean containsHeader(String
name)

Question) Following Shows networking terminologies ?

A) IP Address B) Protocol C) URL D) All of the above Answer - All of the above

Question) ________ returns true if the server created the session and it has not yet been accessed by the
client.

A) invalidate( ) B) isNew() C) getLastAccessedTime( ) D) None of the above Answer - isNew()

Question) Invalidate() method belongs to ______interface

A) SessionBindingListener B) HttpSessionBindingListener C) HttpBindingListener D) HttpListener


Answer - HttpSessionBindingListener

Question) ______ interface is implemented by objects that need to be notified when they are bound to or
unbound from an HTTP session.

A) SessionBindingListener B) HttpSessionBindingListener C) HttpBindingListener D)


HttpSessionBinding Answer - HttpSessionBindingListener

Question) Cookies are stored at _____ side.

A) server B) client C) Both A and B D) Neither A nor B Answer - client

Question) Some of the information that is saved for each cookie includes the following:

A) The name of the cookie B) The value of the cookie C) The expiration date of the cookie D) All of the
above Answer - All of the above

Question) ---------------returns true if the browser is sending cookies only over a secure protocol, or false if
the browser can send cookies using any protocol.

A) getSecure( ) B) getName( ) C) clone() D) None of these Answer - getSecure( )

Question) The HttpServlet class extends ______

A) GenericServlet B) Servlet C) Throwable D) none of the above Answer - GenericServlet

Question) Which of the following is not a method of HttpServlet class?

A) doDelete() B) doGet() C) doHead() D) getValue() Answer - getValue()

https://localhost/dashboard/ques_ans_22517.php 69/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Which method is Called by the server when an HTTP request arrives for this servlet?

A) getLastModified() B) service() C) init() D) None of the above Answer - None of the above

Question) HttpSessionEvent encapsulates ______Object

A) Event B) session C) request D) response Answer - Event

Question) _____ returns the name of the cookie.

A) getName() B) getName(String s) C) getName(String s,String a) D) none of the above Answer -


getName()

Question) ---------returns the current session associated with this request, or if the request does not have a
session, creates one.

A) getName() B) getSession() C) getSessionName() D) putSession() Answer - getSession()

Question) A servlet developer overrides which of the following methods?

A) doDelete() B) doGet() C) doHead() D) All of the above Answer - All of the above

Question) Identify Error in the following servlet code import java.io.*; public class ColorGetServlet extends
HttpServlet { public void doGet(HttpServletRequest request,HttpServletResponse response) throws
ServletException, IOException { String color = request.getParameter("color");
response.setContentType("text/html"); PrintWriter pw = response.getWriter(); pw.println("<B>The selected
color is: "); pw.println(color); pw.close(); } }

A) javax.servlet.http.* ;is missing B) javax.servlet.*; is missing C) Both A and B D) None of the above
Answer - Both A and B

Question) Which classes are used for connection-oriented socket programming?

A) Socket B) ServerSocket C) Both A and B D) None of the above Answer - Both A and B

Question) The ______is invoked when a form on a Web page is submitted.

A) servlet B) session C) cookie D) none of above Answer - servlet

Question) Find error in the following code import java.io.*; import javax.servlet.*; import javax.servlet.http.*;
public class ColorPostServlet extends HttpServlet { public void doPost(HttpServletRequest
request,HttpServletResponse response) throws ServletException, IOException { String color =
request.getParameter("color"); PrintWriter pw = response.getWriter(); pw.println("<B>The selected color is:
"); pw.println(color); pw.close(); } }

A) Some classes/ interfaces not imported B) Correct Exception is not thrown by the method C) No Error
D) response.setContentType("text/html"); is missing Answer -
response.setContentType("text/html"); is missing

Question) Which is a one-way communication only between the client and the server and it is not a reliable
and there is no confirmation regarding reaching the message to the destination?

A) TCP/IP B) UDP C) Both A & B D) None of the above Answer - UDP

https://localhost/dashboard/ques_ans_22517.php 70/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Which method returns copy of this cookie object?

A) getclone() B) clone() C) setclone() D) None of these Answer - clone()

Question) Which class allows state information to be stored on a client machine?

A) Cookie B) HttpServlet C) HttpSession D) None of these Answer - Cookie

Question) getCookies() method returns ______ of the cookies in this request

A) array B) enum C) object D) none of the above Answer - array

Question) Which method returns the URL?

A) getURL() B) URL() C) getRequestURL() D) None of the above Answer - getRequestURL()

Question) ______ returns true if a cookie contains session id otherwise false

A) isRequestedSessionFromCookie() B) isRequestedFromCookie() C) isRequestedSessionCookie() D)


None of the Above Answer - isRequestedSessionFromCookie()

Question) ______ method returns true if requested session ID is valid in the current session context

A) isRequestedSessionIdValid() B) isSessionIdValid() C) isRequestedIdValid() D)


RequestedSessionIdValid() Answer - isRequestedSessionIdValid()

Question) Which method redirects the client to the URL?

A) sendRedirect(String url) B) Redirect(String url) C) sendError(String url) D) None of the above


Answer - sendRedirect(String url)

Question) ____ method adds field to the header with date value equal to msec?

A) void setDateHeader(String field,long msec) B) void DateHeader(String field,int msec) C) void


setDateHeader(long msec) D) void setDate(String field,long msec) Answer - void
setDateHeader(String field,long msec)

Question) Which method sets status code for this response to code

A) void setStatus(int code) B) void setStatus() C) void Status(int code) D) None of the above
Answer - void setStatus(int code)

Question) Which method returns the time when the client last made a request for this session

A) void getLastAccessDate() B) long getLastAccessedTime() C) getAccessedTime() D) None of the


above Answer - long getLastAccessedTime()

Question) Which method performs an HTTP DELETE?

https://localhost/dashboard/ques_ans_22517.php 71/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) void doDelete(HttpServletRequest req,HttpServletResponse res) throws IOException, ServletException


B) void Delete(HttpServletRequest req,HttpServletResponse res) throws IOException, ServletException
C) void destroy(HttpRequest req,HttpServletResponse res) throws IOException, ServletException D)
void doDestroy(HttpRequest req,HttpResponse res) throws IOException, ServletException Answer -
void doDelete(HttpServletRequest req,HttpServletResponse res) throws IOException,
ServletException

Question) Which method performs an HTTP GET?

A) void Get(HttpServletRequest req,HttpServletResponse res) throws ServletException B) void


doGet(HttpServletRequest req,HttpServletResponse res) throws IOException, ServletException C) void
DoGet(HttpServletRequest req,HttpServletResponse res) throws IOException, ServletException D) None
of the above Answer - void doGet(HttpServletRequest req,HttpServletResponse res) throws
IOException, ServletException

Question) _____ method invalidates this session and removes it from the context?

A) void invalidate() B) void validate() C) void verify() D) void removeAttribute() Answer - void
invalidate()

Question) _________ method removes attribute specified by attr from the session.

A) void removeAttribute(String attr) B) void removeAttribute() C) void deleteAttribute(String attr) D) void


remove() Answer - void removeAttribute(String attr)

Question) Which of the following is not a method of HttpSession interface?

A) getAttribute() B) setAttribute() C) setHeader() D) isNew() Answer - setHeader()

Question) All the methods of _____Interface throw IllegalStateException

A) Session B) HttpSession C) cookies D) Servlet Answer - HttpSession

Question) Which of the following is true about cookies?

A) Cookies are stored on client B) Cookies contain state information C) Cookies track user activities D)
All of the above Answer - All of the above

Question) Which one is not a constructor for cookie?

A) Cookie() only B) Cookie(String name) only C) a and b D) Cookie(String name,String value)


Answer - a and b

Question) If an expiration date is not explicitly assigned to a cookie,it is deleted _____.

A) Immediately after creation B) When session is expired C) when current browser session ends. D)
Never Answer - when current browser session ends.

Question) Which of the following is not a method of cookie class?

A) Clone() B) getMaxAge() C) doGet() D) getName() Answer - doGet()

Question) Which of the following are methods of HttpServlet Class?

https://localhost/dashboard/ques_ans_22517.php 72/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) setComment() B) doDelete() only C) doGet() only D) b and c Answer - b and c

Question) HttpServlet class methods throw _______.

A) IOException only B) ServletException only C) IllegalstateException only D) IOException and


ServletException only Answer - IOException and ServletException only

Question) Which of the following is constructor for HttpSessionEvent Class?

A) HttpSessionEvent() B) HttpSessionEvent(Httpsession session) C) HttpSessionEvent(String value) D)


None of the above Answer - HttpSessionEvent(Httpsession session)

Question) httpServlet program overrides ____ method

A) doPut() only B) doHead() only C) doTrace() D) All Of The Above Answer - All Of The Above

Question) _____ and _____ requests are most commonly used when handling form input

A) get , post B) put , trace C) head , delete D) none of above Answer - get , post

Question) ____ identifies a servlet to process HTTP GET request

A) session B) cookie C) URL D) request Answer - URL

Question) Parameters of ____ request are included as part of the URL that is sent to the Web Server.

A) HTTPPOST B) HTTPGET C) HTTPDELETE D) HTTPTRACE Answer - HTTPGET

Question) ------------ method returns true if the cookie contains session id.otherwise returns false

A) Boolean isRequestedSessionIdFromCookie() B) Boolean isRequestedSessionId() C) Boolean


isSessionIdFromCookie() D) None of the above Answer - Boolean
isRequestedSessionIdFromCookie()

Question) ---------method returns any extra path information associated with the URL the client sent when it
made this request.

A) String getPathInfo() B) String getPath() C) String getMethod() D) None of the above Answer -
String getPathInfo()

Question) ------------- returns an array of the cookies in this request

A) Cookie[] getCookies() B) Cookie[] getMaxCookies() C) Cookie[] getMinCookies() D) None of the


above Answer - Cookie[] getCookies()

Question) Which method returns int equivalent of the header field named field?

A) int getHeader() B) int getIntHeader() C) int getIntHeader(String field) D) None of these Answer
- int getIntHeader(String field)

Question) ---------- method returns name of the user who issues this request.

A) String getRemoteUser() B) String getUser() C) String getRemote() D) None of these Answer -


String getRemoteUser()

https://localhost/dashboard/ques_ans_22517.php 73/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Which method adds cookie to the HTTP response

A) void addCookie() B) void addCookie(Cookie cookie) C) void addCookie(String cookie) D) void


addCookie(int i) Answer - void addCookie(Cookie cookie)

Question) _____ sets status code for this response to code

A) setStatus() B) setStatus(int code) C) setStatusCode(int code) D) None of the Above Answer -


setStatus(int code)

Question) Cookies were originally designed for __________

A) Client-side programming B) Server-side programming C) Both Client-side & Server-side programming


D) web programming Answer - Server-side programming

Question) ----is not a protocol

A) Telnet B) TCP C) FTP D) hit Answer - hit

Question) Following are tasks of Proxy Server__________

A) Filter certain request B) cache the results of request for future use C) provide faster access of catched
pages to clients D) All of the above Answer - All of the above

Question) Select incorrect statement about Internet Protocol

A) It is low level routing Protocol B) It breaks data into small packets C) sends packet to an address
across network D) it is higher level Protocol Answer - it is higher level Protocol

Question) Canvas is a ______________

A) Window B) Frame C) Panel D) applet Answer - Window

Question) By default page-up and page-down increment of scrollbar is_____________.

A) 20 B) 10 C) 15 D) 5 Answer - 10

Question) Scrollbar( ) creates a ______________ scroll bar by default.

A) Vertical B) Horizantal C) Both D) None Answer - Vertical

Question) ----- is the protocol that web browser and server use to transfer hypertext pages and images

A) FTP B) HTTP C) telnet D) none of above Answer - HTTP

Question) Which of the following are various AWT controls?

A) Labels, Push buttons, Check boxes, Choice lists. B) Text components, Threads, Strings, Servelts,
Vectors C) Labels, Strings, JSP, Netbeans, Sockets D) Push buttons, Servelts, Notepad, JSP
Answer - Labels, Push buttons, Check boxes, Choice lists.

Question) To execute a statement, we invoke method

https://localhost/dashboard/ques_ans_22517.php 74/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) execute method B) executeRel method C) executeStmt method D) executeConn method


Answer - execute method

Question) A typical __________ program obtains a remote reference to one or more remote objects on a
server and then invokes methods on them.

A) server B) client C) thread D) concurrent Answer - client

Question) File transfer protocol(FTP) is used for____________

A) Speed B) Efficient C) Security D) All of the above Answer - All of the above

Question) Which of these class is necessary to implement datagrams?

A) DatagramPacket B) DatagramSocket C) All of the mentioned D) None of the mentioned


Answer - All of the mentioned

Question) The Prepared statement _____symbolis a placeholder that is replaced by the input parameter at
seen time

A) ? B) * C) / D) + Answer - ?

Question) Which methods are commonly used in ServerSocket class?

A) public OutputStream getOutputStream() B) public synchronized void close() C) public Socket accept()
D) none of the above Answer - public Socket accept()

Question) The ___________method is used to insert data into table

A) execute() B) executeQuery() C) executeUpdate() D) None of the above Answer -


executeUpdate()

Question) Which method is used to load the driver?

A) Class.forName() B) class.forname() C) Connection con D) None of the above Answer -


Class.forName()

Question) A small data file in the browser.

A) Cookie B) Web Server C) FTP D) DATABASE Answer - Cookie

Question) 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


- Connection Oriented

Question) Unlike Transmission Control Protocol (TCP), User Datagram Protocol (UDP) has Services which
is

A) Connection Oriented B) Connectionless C) Connection Available D) Connection Origin Answer


- Connectionless

Question) The JDBC-ODBC Bridge driver translates the JDBC API and used with _________

https://localhost/dashboard/ques_ans_22517.php 75/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) JDBC drivers B) ODBC drivers C) Both A and B D) None of the above Answer - ODBC
drivers

Question) Which protocol is for breaking and sending packets to an address across a network.

A) UDP B) TCP/IP C) Proxy server D) none of the above Answer - TCP/IP

Question) Consider the following code. What will be student table data after executing this code as table
has only one record. import java.sql.*; public class MyDB { public static void main(String[] args) throws
Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:mystud"); PreparedStatement ps =
con.prepareStatement("delete * from student"); ps .executeUpdate(); Statement st = con.createStatement();
ResultSet Rset = ps.executeQuery("select * from student"); while (Rset.next()) { int studid =
Rset.getInt("rno"); String studname = Rset.getString("name"); System.out.println(studid + " " +studname); } }
}

A) One record will get displayed. B) No record will get displayed. C) All records will get displayed. D)
None of the above. Answer - No record will get displayed.

Question) The __________object allows you to execute parametrized queries

A) putString() B) insertString() C) setString() D) setToString() Answer - setString()

Question) UDP stands for ---------

A) User Datagram Protocol B) Uses Datagram Protocol C) user data procedure D) user data program
Answer - User Datagram Protocol

Question) Central Computer which is powerful than other computers in the network is called as
__________.

A) client B) server C) hub D) switch Answer - server

Question) which class is used to create servers that listen for either local or client program?

A) Server Machine B) Client Machine C) HttpServer D) ServerSockets Answer - ServerSockets

Question) The class java.sql.Timestamp is associated with _______

A) java.util.time B) java.sql.Time C) java.util.Date D) None of the above Answer - java.util.Date

Question) Fill in the blank space? import java.sql; class connectDB { public static void main(String arg[]) { try
{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Driver Loaded"); String
url="jdbc:odbc:myDCN"); Connection con=__________.getConnection(url); System.out.println("Connection
to database is created"); } catch(SQLException e) { System.out.println("Error"+e); } catch(Exception e) {
system.out.println("Error"+e); } } } }

A) DriverManager B) classmanager C) statementmanager D) None of the above Answer -


DriverManager

Question) Which are the navigation methods of resultset?

A) beforeFirst() B) afterLast() C) first() D) All of the above Answer - All of the above

https://localhost/dashboard/ques_ans_22517.php 76/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) __________method is used to execute the queries that contains the INSERT, DELETE and
UPDATE statements.

A) execute() B) executeQuery() C) executeUpdate() D) getResultSet() Answer -


executeUpdate()

Question) Which of the following query is use for select query?

A) execute() B) execute(String sql) C) executeUpdate(String sql) D) executeQuery(String sql)


Answer - executeQuery(String sql)

Question) _________ method of HttpServletResponse interface adds cookies to the HTTP response .

A) public void addCookie(Cookie cookie ) B) public void addCookie( ) C) public void getCookie(Cookie
cookie ) D) public void getCookie( ) Answer - public void addCookie(Cookie cookie )

Question) HTTP stands for___________?

A) Hypertext transfer processor B) Hypertext Transfer Protocol C) High transfer protocol D) hyper
transfer protocol Answer - Hypertext Transfer Protocol

Question) _______method from JDBC is the means of establishing a connection between URL and
Database.

A) getConnection() B) executeQuery() C) createStatement() D) executeUpdate() Answer -


getConnection()

Question) A servlet can write a cookie to a user's machine via the addCookie( ) method of the
_____________ interface

A) ServletRequest B) HttpServletRequest C) HttpServletResponse D) ServletResponse Answer -


HttpServletResponse

Question) Which driver converts JDBC API calls into DBMS-specific client API calls?

A) Type 1 B) Type 2 C) Type 3 D) Type 4 Answer - Type 2

Question) Correct syntax of the constructor to create Cookie object is____:

A) Cookie(String value, String name) B) Cookie(int value, String name) C) Cookie(String name, String
value) D) Cookie(int value, int name) Answer - Cookie(String name, String value)

Question) which driver converts JDBC API calls directly into the DBMS specific network protocol without a
middle tier?

A) Type 1 B) Type 2 C) Type 3 D) Type 4 Answer - Type 4

Question) Information that is saved for each cookie includes ______

A) The name, the value and expiration date of the cookie. B) The name and expiration date of the cookie
only C) The name of Cookie only. D) The name and the value of the cookie only Answer - The
name, the value and expiration date of the cookie.

https://localhost/dashboard/ques_ans_22517.php 77/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) which driver converts JDBC API calls middle tier net server that translates the calls into the
DBMS specific network protocol ?

A) Type 1 B) Type 2 C) Type 3 D) Type 4 Answer - Type 3

Question) Which driver allows access to multiple databases using one driver?

A) Type 1 B) Type 2 C) Type 3 D) Type 4 Answer - Type 3

Question) Following is the correct syntax for creating Cookies Object c .

A) Cookie c = new Cookie(MyCookie, data); B) Cookie c = new Cookie("MyCookie", data); C) cookie c =


new cookie("MyCookie", data); D) Cookie c = new Cookie(data,"MyCookie"); Answer - Cookie c =
new Cookie("MyCookie", data);

Question) The Elements Of Flow Layouts are arranged in --------------------fashion

A) stacked, on the top of the other B) laid out using the square of a grid C) Organized top to bottom, left
to right D) organized at the borders and the centre of a container Answer - Organized top to
bottom, left to right

Question) which method returns the current result as Resultset object.

A) execute() B) executeQuery() C) getResult() D) getResultSet() Answer - getResultSet()

Question) Which method executes the given SQL statement , which return the single ResultSet object?

A) execute() B) executeQuery() C) executeUpdate() D) getResultSet() Answer - executeQuery()

Question) What is the Difference Between Grid And Gridbaglayout?

A) In Grid layout the size of each grid is varying where as in GridbagLayout grid size is constant. B) In Grid
layout the size of each grid is constant where as in GridbagLayout grid size can be varied. C) The size of
each component in both layout is same D) All of the above Answer - In Grid layout the size of
each grid is constant where as in GridbagLayout grid size can be varied.

Question) _______ method is called when servlet is initialized.

A) destroy() B) service() C) init() D) connect() Answer - init()

Question) Which driver provides JDBC access via one or more ODBC drivers

A) Type 1 driver B) Type 2 driver C) Type 3 driver D) Type 4 driver Answer - Type 1 driver

Question) To iterate the resultset you use its _________ method

A) next() B) previous() C) beforefirst() D) afterLast() Answer - next()

Question) A servlet is an instance of ___________

A) HTTPServlet class B) Cookie C) HttpSessionBindingEvent D) HttpUtils Answer - HTTPServlet


class

Question) Which of the following method is used to Sets the maximum age of the cookie in seconds.

https://localhost/dashboard/ques_ans_22517.php 78/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) public void setmaxage(int secs) B) public void Setmaxage(String secs) C) public void
setMaxAge(String secs) D) public void setMaxAge(int secs) Answer - public void setMaxAge(int
secs)

Question) When iterating the ResultSet you want to access the column values of each record. You do so by
calling one or more of the many ______ methods.

A) getXXX() B) updateXXX() C) setXXX() D) None of the above Answer - getXXX()

Question) Which method moves the cursor to the first row of the resultset?

A) first() B) last() C) next() D) previous() Answer - first()

Question) Which method is called to process HTTP request?

A) destroy() B) service() C) init() D) None of these Answer - service()

Question) Which of the following method of HttpServletRequest interface is used to return all the cookies
from the browser.

A) Cookie getcookies() B) private Cookie[] getCookies() C) public Cookie[] getCookies() D) public


Cookie[] setCookies() Answer - public Cookie[] getCookies()

Question) Which is correct for the Three Tier Architecture of JDBC? i) It can connect to different databases
without changing code ii)Business logic is clearly separated from database.

A) only i B) only ii C) both D) none Answer - both

Question) What Is A Layout Manager?

A) A layout manager is an object that is used to organize components in a container. B) It is a container


object. C) It is a component object. D) All of the above Answer - A layout manager is an object
that is used to organize components in a container.

Question) getUserName() is used to

A) retrive name of the user B) access name C) Both of the above. D) None of the above. Answer
- retrive name of the user

Question) what are the components of Three Tier Architecture?

A) Client-Tier B) Middle_Tier C) Data Source Layer D) All of the above Answer - All of the above

Question) ----------method indicates to the browser whether the cookie should only be sent using a secure
protocol, such as HTTPS or SSL.

A) public void setSecure(boolean flag) B) public void setsecure(int flag) C) private void
setSecure(boolean flag) D) public boolean setSecure(boolean flag) Answer - public void
setSecure(boolean flag)

Question) Which driver is known as Network Protocol, Pure Java Driver?

A) Type 1 B) Type 2 C) Type 3 D) Type 4 Answer - Type 3

https://localhost/dashboard/ques_ans_22517.php 79/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Which driver is known as Native Protocol, Pure Java Driver.?

A) Type 1 B) Type 2 C) Type 3 D) Type 4 Answer - Type 4

Question) Which method moves the cursor to the beginning of the resultset that is before first row?

A) beforeFirst() B) afterLast() C) first() D) last() Answer - beforeFirst()

Question) Following method is used for setting up comments in the cookie.

A) public void setComment(int purpose) B) public void setComment(String purpose) C) public void
getComment(String purpose) D) private void setcomment(String purpose) Answer - public void
setComment(String purpose)

Question) The server calls __________ method to relinquish any resources, such as files handles that are
allocated for servlet.

A) service() B) init() C) destroy() D) stop() Answer - destroy()

Question) The life cycle of servlet is managed by ___________

A) servlet context B) servlet container C) servletconfig D) All of the above Answer - servlet
container

Question) Which of the following method is used to specify the path to which the client should return the
cookie.

A) public void setPath(String path) B) public void setpath(String value) C) public void setPath(int path)
D) private void setpath(String path) Answer - public void setPath(String path)

Question) The include() method of RequestDispatcher ______

A) Sends a request to another resource B) Include the content of resource like servlet,jsp or html C)
Appends the request and response object to the current servlet D) None of the above Answer -
Include the content of resource like servlet,jsp or html

Question) Find the error in the following code import java.io.*; import javax.servlet.*; public class
HelloServlet extends GenericServlet{ public void service(ServletRequest request, ServletResponse
response) throws ServletException,IOException{ response.setContentType("text/html"); PrintWriter pw =
response.getOutputStream(); pw.println("<b> Hello"); pw.close();

A) import javax.servlet.*; B) response.setContentType("text/html") C) PrintWriter pw =


response.getOutputStream(); D) None of these Answer - PrintWriter pw =
response.getOutputStream();

Question) Which of the following method is used to Set the domain in which this cookie is visible.

A) public void setDomain(String pattern) B) public void setDomain(int pattern) C) public void
getDomain(String pattern) D) private void setdomain(String pattern) Answer - public void
setDomain(String pattern)

Question) Which package contains the classes and interfaces required to build servlet?

https://localhost/dashboard/ques_ans_22517.php 80/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) javax.servlet and javax.servlet.http B) javax.servlet only C) javax.servlet.http only D) java.servlet and


java.servlet.http Answer - javax.servlet and javax.servlet.http

Question) Which of the following method returns the cookie protocol version.

A) int getVersion( ) B) int setversion( ) C) int GetVersion( ) D) String getVersion( ) Answer - int
getVersion( )

Question) _______ class provides functionality that makes it easy to handle requests and responses.

A) Generic Servlet B) ServletInputStream C) ServletOutputStream D) None of these Answer -


Generic Servlet

Question) Which of these classes implement the LayoutManager interface?

A) RowLayout B) ColumnLayout C) GridBagLayout D) All of the above Answer - GridBagLayout

Question) _______method establishes the MIME type of the HTTP response.

A) setContentType() B) ContentType() C) setType() D) none of above Answer -


setContentType()

Question) ______ is a way to maintain state (data) of an user.

A) Session Tracking B) Cookie tracking C) HttpServletState D) Session Answer - Session


Tracking

Question) Which of the following interface declares the lifecycle method for servlet.

A) Servlet B) Servlet Config C) ServletContext D) ServletResponse Answer - Servlet

Question) ____________encapsulates session events.

A) httpsessionevent B) HttpSessionEvent C) HttpSessionTrackingEvent D) HttpSessionEventObject


Answer - HttpSessionEvent

Question) ____________ interface allows servlet to get initialization parameters.

A) SingleThreadModel B) ServletRequest C) ServletConfig D) ServletContext Answer -


ServletConfig

Question) Which of the following method returns the session in which the event occurred?

A) HttpSession setSession( ) B) httpsession getsession( ) C) HttpSession getSession( ) D) HttpSession


setSessionEvent( ) Answer - HttpSession getSession( )

Question) HTTP is a __________ protocol.

A) stateless B) state oriented C) stateful D) none of above Answer - stateless

Question) How will the following program lay out its buttons. Select the one correct answer. import
java.awt.*; public class MyClass { public static void main(String args[]) { String[] labels =
{"A","B","C","D","E","F"}; Window win = new Frame(); win.setLayout(new GridLayout(1,0,2,3)); for(int i=0;i <
labels.length;i++) win.add(new Button(labels[i])); win.pack(); win.setVisible(true); } }

https://localhost/dashboard/ques_ans_22517.php 81/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) The program will not display any buttons. B) The program will display all buttons in a single row. C)
The program will display all buttons in a single column. D) The program will display three rows - A B, C D,
and E F. Answer - The program will display all buttons in a single row.

Question) A session can be created via the getSession( ) method of __________.

A) HttpServletResponse B) HttpServletRequest C) HttpServlet D) GenericServlet Answer -


HttpServletRequest

Question) ______method Writes the specified message to a servlet log file, usually an event log.

A) log(jString msg) B) log() C) Both A and B D) none of above Answer - log(jString msg)

Question) JComboBox constructors are________________

A) JComboBox( ) B) JComboBox(Vector v) C) JComboBox(Vector v,Vector v) D) both a & b


Answer - both a & b

Question) In some applications, it is necessary to __________ so that information can be collected from
several interactions between a browser and a server.

A) save date and time information B) save creation of session C) save state information D) save objects
Answer - save state information

Question) A session can be created via the ___________ method of HttpServletRequest.

A) getSessionCreate( ) B) setSession( ) C) setsession( ) D) getSession( ) Answer - getSession(


)

Question) Which Swing classes can be used with progress bars?

A) JProgressBar B) ProgressMonitor C) ProgressMonitorInputStream D) all the above Answer -


all the above

Question) How will the following program lay out its buttons. Select the one correct answer. import
java.awt.*; public class MyClass { public static void main(String args[]) { String[] labels = {"A"}; Window win =
new Frame(); win.setLayout(new FlowLayout()); for(int i=0;i < labels.length;i++) win.add(new
Button(labels[i])); win.pack(); win.setVisible(true); } }

A) The button A will appear on the top left corner of the window. B) The button A will appear on the middle
row and column, in the center of the window. C) The button A will appear on the top right corner of the
window. D) The button A will appear on the top right corner of the window. Answer - The button A
will appear on the middle row and column, in the center of the window.

Question) HttpSession hs = request.getSession(true); Above statement indicates that_____

A) Get the HttpSession object B) Get the Http object. C) Set the HttpSession object. D) Set the Cookie
object. Answer - Get the HttpSession object

https://localhost/dashboard/ques_ans_22517.php 82/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) What will be the output of the following code? 1. import java.io.*; 2. import java.util.*; 3. import
javax.servlet.*; 4. import javax.servlet.http.*; 5 public class DateServlet extends HttpServlet { 6. public void
doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
7. HttpSession hs = request.getSession(true); 8. response.setContentType(""text/html""); 9. PrintWriter pw =
response.getWriter(); 10. pw.print(""<B>""); 11. Date date = (Date)hs.getAttribute(""date""); 12. if(date !=
null) { 13. pw.print(""Last access: "" + date + ""<br>""); 14. } 15. date = new Date(); 16.
hs.setAttribute(""date"", date); 17. pw.println(""Current date: "" + date); 18. } 19. }

A) The first line shows the date and time when the servlet was last accessed. The second line shows the
current date and time. B) shows the date and time when the servlet was last accessed. C) shows the
date and time when the servlet was last accessed D) The first line shows the date and time when the
servlet is first accessed. The second line shows the previous date and time. Answer - The first line
shows the date and time when the servlet was last accessed. The second line shows the current
date and time.

Question) The ________ method is overridden to process any HTTP POST requests that are sent to
servlet.

A) doGet() B) doPost( ) C) doPut() D) doHead() Answer - doPost( )

Question) The ____________ method is overridden to process any HTTP GET requests that are sent to
this servlet.

A) doPost( ) B) doPut() C) doGet( ) D) doHead() Answer - doGet( )

Question) The doGet( ) method is overridden to process any ________ requests that are sent to this
servlet.

A) HTTP POST B) HTTP SET C) HTTP TRACE D) HTTP GET Answer - HTTP GET

Question) The doPost( ) method is overridden to process any _________requests that are sent to this
servlet.

A) HTTP POST B) HTTP SET C) HTTP TRACE D) HTTP GET Answer - HTTP POST

Question) Suppose a JFrame uses the GridLayout(2,0). If six buttons are added to the frame, how many
columns are displayed?

A) 1 B) 2 C) 3 D) 4 Answer - 3

Question) How many frames are c related ? import java.awt.*; import javax.swing.*; public class FrameTest
{ public static void main(String args[]) { JFrame fr=new JFrame("My frame"); JFrame fr1=fr; JFrame fr2=fr1;
fr.setVisible(true); fr1.setVisible(true); fr2.setVisible(true); } }

A) 1 B) 2 C) 3 D) 0 Answer - 1

Question) ___________provide client request information to a servlet.

A) ServletResponse B) ServletRequest C) both a and b D) None of these Answer -


ServletRequest

Question) The SingleThreadModel indicates that the __________ is thread safe.

A) process B) Thread C) Servlet D) GenericServlet Answer - Servlet


https://localhost/dashboard/ques_ans_22517.php 83/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) GenericServlet class implements _____ and __________ interfaces.

A) ServletRequest and ServletResponse B) ServletResponse and Servlet C) Servlet and ServletConfig


D) None of these Answer - Servlet and ServletConfig

Question) ________class provides stream to read binary data from the request.

A) ServletException B) GenericServlet C) ServletOutputStream D) ServletInputStream Answer -


ServletInputStream

Question) ________ class indicates that a servlet error occurred.

A) ServletException B) IOExeption C) ServletNotFound D) None of these Answer -


ServletException

Question) ___________ indicates that a servlet is permanently or temporarily unavailable.

A) ServletUnavailableException B) IllegalException C) ServletException D) UnavailableException


Answer - UnavailableException

Question) The default alignment of buttons in Flow Layout is ..........

A) LEFT B) CENTER C) RIGHT D) JUSTIFY Answer - CENTER

Question) The default horizontal and vertical gap in FlowLayout is

A) 0 Pixel B) 1 Pixel C) 5 Pixel D) 10 Pixel Answer - 5 Pixel

Question) The default horizontal and vertical gap in BorderLayout is

A) 0 Pixel B) 1 Pixel C) 5 Pixels D) 10 Pixels Answer - 0 Pixel

Question) Which of the following interface allows a servlet to get initialization parameters.

A) ServletConfig B) ServletContext C) ServletRequest D) ServletResponse Answer -


ServletConfig

Question) getServletContext() returns the __________ for this servlet.

A) value B) context C) enumeration D) None of these Answer - context

Question) Which of the following method returns the value of the initialization parameter named param

A) ServletContextgetServletContext() B) String getInitParameter(String param) C) Enumeration


getInitParameterNames() D) String getServerInfo() Answer - String getInitParameter(String
param)

Question) The ServletContext interface is implemented by the ________

A) client B) server C) cookie D) session Answer - server

Question) Which of the following interface enables the servlet to obtain information about their
environment?

https://localhost/dashboard/ques_ans_22517.php 84/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) ServletContext B) ServletConfig C) ServletRequest D) ServletResponse Answer -


ServletContext

Question) ___________ methods are dangerous to use because they can corrupt the server's state
machine.

A) getServlet() B) getServletNames() C) both a and b D) None of these Answer - both a and b

Question) ________returns the port number to which the request was sent.

A) String getScheme() B) String getServerName() C) int getServerPort() D) String getRemoteHost()


Answer - int getServerPort()

Question) . ________ returns the host name of the server to which the request was sent.

A) String getScheme() B) String getServerName() C) int getServerPort() D) String getRemoteHost()


Answer - String getServerName()

Question) ______ method returns the name of the scheme used to make this request, for example, http,
https, or ftp.

A) getScheme() B) setScheme() C) putScheme() D) none of the above Answer - getScheme()

Question) ________ Returns the fully qualified name of the client or the last proxy that sent the request.

A) String getRemoteHost() B) String getRemoteAddr() C) String getProtocol() D) None of these


Answer - String getRemoteHost()

Question) Which of the following package is missing for the below program? import java.io.*: import
javax.servlet.*; public class PostParameterServlet extends GenericServlet{ public void
service(ServletRequest request, ServletResponse response) throws ServletException ,IOException{
Printwriter pw= response.getWriter(); Enumeration e= request.getParameterNames();
while(e.hasMoreElements()) { String pname= (String) e.nextElement(); pw.print(pname + "= "); Sting pvalue
= request.getParameter(pname); pw.println(pvalue); } pw.close(); } }

A) import.java.util.*; B) import javax.servlet.http.*; C) import java.awt.*; D) None of these Answer


- import.java.util.*;

Question) Write the missing statement in the below code import javax.servlet.*; public class
WelcomeServlet extends GenericServlet { public void service( ServletRequest request,ServlerResponse
response) throws ServletException ,IOException { response.setContentType("text/html"); PrintWriter pw =
response.getWriter(); pw.println("<b> Hello"); } }

A) pw.close() B) pw.stop() C) pw.destroy() D) none of these Answer - pw.close()

Question) Identify the missing statement at line no. 6. 1. import java.io.*; 2. import javax.servlet.*; 3. public
class First extends GenericServlet{ 4. public void service(ServletRequest req,ServletResponse res) throws
IOException, ServletException{ 5. res.setContentType("text/html"); 6. ? 7. out.print("<html><body>"); 8.
out.print("<b>hello generic servlet</b>"); 9. out.print("</body></html>"); 10. } 11. }

A) PrintWriter out=res.getWriter(); B) PrintWriter in = res.getWriter() C) PrintWriter out=res.putWriter();


D) PrintWriter in = res.putWriter() Answer - PrintWriter out=res.getWriter();

Question) Which method is used to specify before any lines that uses the PrintWriter?
https://localhost/dashboard/ques_ans_22517.php 85/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) SetPageType() B) SetType() C) setContextType() D) setResponseType() Answer -


setContextType()

Question) Which method of servlet is/are called several times in its life?

A) destroy() B) service() C) init() D) none of above Answer - none of above

Question) In a web application, running in a web server, servlet is responsible for creating______object.

A) request and response B) request only C) response only D) none of above Answer - request
and response

Question) Servlets execute ______of a web server

A) within the address space B) out of the address space C) any address space D) none of the above
Answer - within the address space

Question) The UnavailableException Class is subclass of ______

A) IllegalArgumentException B) ClassNotFoundExceptin C) ServletException D) All Of The Above


Answer - ServletException

Question) Which of the following method Write s and stack the trace for e to the server log?

A) void log(Throwable e ) B) void log( String s) C) void log() D) void log(String s, Throwable e)
Answer - void log(String s, Throwable e)

Question) Which of the following method returns an enumeration with the name of servlets in the same
namespace in the server?

A) String getInitParameter(String param) B) Enumeration getInitParameterNames() C) Enumeration


getServletNames() D) None of these Answer - Enumeration getServletNames()

Question) _____________ returns the real path that corresponds to the virtual path 'vpath'.

A) String getServerInfo() B) String getMimeType(String File) C) String getRealPath(String vpath) D) int


getContentLength() Answer - String getRealPath(String vpath)

Question) The ________ interface is used to indicate that only a single thread should execute the service()
method of a servlet.

A) SingleThreadModel B) UnithreadModel C) ThreadModel D) None of These Answer -


SingleThreadModel

Question) The SingleThreadModel interface defines no constants and declares no methods.

A) True B) False C) D) Answer - True

Question) The servlet programmer should implement_______ interface to ensure that servlet can handle
only one request at a time.

A) ServletResponse B) ServlerRequest C) SingleThreadModel D) None of these Answer -


SingleThreadModel

https://localhost/dashboard/ques_ans_22517.php 86/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Which of the following class provides implementations of the basic life cycle methods for a
servlet.

A) Servlet InputStream B) GenericServlet C) ServletException D) Servlet OutputStream Answer -


GenericServlet

Question) void log(String s) method belongs to which of the following classes.

A) GenericServlet Class B) Servlet OutputStream Class C) Servlet InputStream Class D) None of


These Answer - GenericServlet Class

Question) Every servlet has it's own ________object and servlet container is responsible for instantiating
this object.

A) ServletConfig B) servletContext C) Both A and B D) none of the above Answer -


ServletConfig

Question) The ServletContext is _______ object and available to all the servlets in the web application.

A) unique B) seperate C) different D) optional Answer - unique

Question) Which of the following is the unique object per servlet?

A) ServletConfig B) ServletContext C) ServletRequest D) None of these Answer - ServletConfig

Question) . _______ is an unique object for complete application.

A) ServletConfig B) ServletContext C) ServletRequest D) None of these Answer -


ServletContext

Question) We cannot set attributes in ________ interface that other servlets can use in their
implementations.

A) ServletConfig B) ServletContext C) ServletRequest D) None of these Answer -


ServletContext

Question) ______interface is used for inter-servlet communication

A) RequestDispatcher B) ServlerRequest C) ServletResponse D) none of above Answer -


RequestDispatcher

Question) Which of the following interface is used to forward the request to another resource that can be
HTML, JSP or another servlet in same application?

A) Request Dispatcher Interface B) SinglethreadModel Interface C) ServletResponse Interface D) None


of These Answer - Request Dispatcher Interface

Question) Which of the following method forwards the request from a servlet to another resource (servlet,
JSP file, or HTML file) on the server?

A) void include(ServletRequest request, ServletResponse response) B) void forward(ServletRequest


request, ServletResponse response) C) void include(ServletRequest request) D) void
forward(ServletRequest request) Answer - void forward(ServletRequest request,
ServletResponse response)

https://localhost/dashboard/ques_ans_22517.php 87/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) ________ is protocol independent implementation of Servlet

A) ServletInputStream B) ServletOutputStream C) GenericServlet D) None of These Answer -


GenericServlet

Question) Which of the following interface guarantees that no two threads will execute concurrently in the
servlet's service method ?

A) ServletResponse B) ServletRequest C) SingleThreadModel D) ServletConfig Answer -


SingleThreadModel

Question) ______ is the super class of all servlets.

A) GenericServlet B) HttpServlet C) Servlet D) none of above Answer - GenericServlet

Question) How many ServletContext objects are available for an entire web application?

A) One each per servlet B) One each per request C) One each per response D) Only one
Answer - Only one

Question) Servlet creates ______ thread for each request of client.

A) single B) two C) multiple D) None of These Answer - single

Question) Servlet runs each request in a __________ ?

A) OS shell B) JVM C) Separate thread D) JRE Answer - Separate thread

Question) GenericServlet class is encapsulated inside __________ package

A) java.lang B) javax.servlet C) java.servlet D) javax.servlet.http Answer - javax.servlet

Question) _________ is responsible for managing execution of servlet

A) Web Container B) Servlet Context C) JVM D) Server Answer - Web Container

Question) Consider the following program which class should be extended? import java.io.*; import
javax.servlet.*; public class First extends ************{ public void service(ServletRequest
req,ServletResponse res) throws IOException,ServletException{ res.setContentType("text/html"); PrintWriter
out=res.getWriter(); out.print("<html><body>"); out.print("<b>hello generic servlet</b>"); out.print("</body>
</html>"); } }

A) HttpServlet B) GenericServlet C) Servlet D) None of These Answer - GenericServlet

Question) ItemEvent constructor- ItemEvent(ItemSelectable src, int type, Object entry, int state) Here entry
means......

A) The specific item that generated the item event is passed B) The type of object C) a reference to the
component that generated event D) The current state of that item. Answer - The specific item that
generated the item event is passed

Question) The getItem( ) method can be used...

https://localhost/dashboard/ques_ans_22517.php 88/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) to obtain a reference to the all item B) to obtain a reference to the item that changed. C) get reference
to the component. D) get reference to the frame Answer - to obtain a reference to the item that
changed.

Question) The example of user interface elements that implement the ItemSelectable interface-

A) Choices and TextBox B) TextBox and Lists C) Lists and choices D) Lists and canvas Answer -
Lists and choices

Question) The getStateChange ( ) method returns the state change.

A) The mouse pressed or released B) Selected or Deselected C) A page-up or page-down D) The


window gained input focus. Answer - Selected or Deselected

Question) . Debug the following program 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 = { "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; JScrollPane jsp = new
JScrollPane(table, v, h); contentPane.add(jsp, BorderLayout.CENTER); } }

A) Error in statement in which applet tag is declared B) Error in statement in which JScrollPane is created
C) Error in statement in which JTable is created D) None of the above Answer - Error in
statement in which JTable is created

Question) Cookie ck=new Cookie("auth",null); ck.setMaxAge(0); A _______ value in the above method
means that the cookie is not stored persistently and will be deleted when the Web browser exits.

A) Negative, Positive B) Positive C) Zero D) Negative Answer - Negative

Question) A cookie's value can uniquely identify a client, so cookies are commonly used for
___________________.

A) Cookie Management B) Session Management C) Http Management D) Servlet Answer -


Session Management

Question) ________ is removed each time when user closes the browser.

A) Non-persistent cookie B) Persistent cookie C) session D) httpservlet Answer - Non-persistent


cookie

Question) __________________ valid for single session only.

A) Persistent cookie B) Non-persistent cookie C) session D) httpservlet Answer - Non-persistent


cookie

Question) ___________ is not removed each time when user closes the browser. It is removed only if user
logout or sign out.

https://localhost/dashboard/ques_ans_22517.php 89/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) Non-persistent cookie B) Persistent cookie C) session D) httpservlet Answer - Persistent


cookie

Question) _____________ is valid for multiple session

A) Persistent cookie B) Non-persistent cookie C) session D) httpservlet Answer - Persistent


cookie

Question) Chose the correct output following code import javax.swing.*; class TextFieldExample { public
static void main(String args[]) { JFrame f= new JFrame("TextField Example"); JTextField t1,t2; t1=new
JTextField("Welcome to Javatpoint."); t1.setBounds(50,100, 200,30); t2=new JTextField("AWT Tutorial");
t2.setBounds(50,150, 200,30); f.add(t1); f.add(t2); f.setSize(400,400); f.setLayout(null); f.setVisible(true); } }

A) B) C) D) Answer -

Question) Identify the methods which belong to Cookies.

A) public void setMaxAge(int expiry) B) public String getName() C) public String getValue() D) All of
above Answer - All of above

Question) Which of the following methods are related to Cookies?

A) public void setName(String name) B) public void setValue(String value) C) public Cookie[]
getCookies() D) All of above Answer - All of above

Question) Find which of the following options contains error : import java.applet.*; import java.awt.*; import
javax.swing.*; Public class fonts extends JApplet { Public void paint(Graphics g) { String str =" "; String
FontList[]; GraphicsEnvironment ge= GraphicsEnvironment.getLocalGraphicsEnvironment();
FontList=ge.getAvailableFontFamilyNames(); For(int i=0;i<fontlist.length;i++) Str+=FontList[i]+ " ";
g.drawString(str,10,16); } }

A) str+=FontList[i]+ ""; B) String FontList[]; C) For(int i=0;i<fontlist.length;i++) D) none of the above


Answer - For(int i=0;i<fontlist.length;i++)

Question) Choose the correct output to display the following Code. import javax.swing.*; import
java.awt.event.*; public class TextFieldExample implements ActionListener{ JTextField tf1,tf2,tf3; JButton
b1,b2; TextFieldExample(){ JFrame f= new JFrame(); tf1=new JTextField(); tf1.setBounds(50,50,150,20);
tf2=new JTextField(); tf2.setBounds(50,100,150,20); tf3=new JTextField(); tf3.setBounds(50,150,150,20);
tf3.setEditable(false); b1=new JButton("+"); b1.setBounds(50,200,50,50); b2=new JButton("-");
b2.setBounds(120,200,50,50); b1.addActionListener(this); b2.addActionListener(this);
f.add(tf1);f.add(tf2);f.add(tf3);f.add(b1);f.add(b2); f.setSize(300,300); f.setLayout(null); f.setVisible(true); }
public void actionPerformed(ActionEvent e) { String s1=tf1.getText(); String s2=tf2.getText(); int
a=Integer.parseInt(s1); int b=Integer.parseInt(s2); int c=0; if(e.getSource()==b1){ c=a+b; }else
if(e.getSource()==b2){ c=a-b; } String result=String.valueOf(c); tf3.setText(result); } public static void
main(String[] args) { new TextFieldExample(); } }

A) B) C) D) Answer -

Question) import java.net.*; In above statement net is -------

A) package B) class C) interface D) method Answer - package

Question) Identify the correct sequence of creating cookies.

https://localhost/dashboard/ques_ans_22517.php 90/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) 1) Create a Cookie object. 2) Set the maximum Age. 3) Place the Cookie in HTTP response header. B)
1) Set the maximum Age. 2) Place the Cookie in HTTP response header. 3) Create a Cookie object. C) 1)
Place the cookie in HTTP response header. 2) Set the maximum Age. 3) Create a Cookie object." D) 1)
Set the maximum Age. 2) Create a Cookie object. 3)Place the Cookie in HTTP response header.
Answer - 1) Create a Cookie object. 2) Set the maximum Age. 3) Place the Cookie in HTTP response
header.

Question) Choose the correct output to display the following code import javax.swing.*; public class
TextAreaExample { TextAreaExample(){ JFrame f= new JFrame(); JTextArea area=new
JTextArea("Welcome to javatpoint"); area.setBounds(10,30, 200,200); f.add(area); f.setSize(300,300);
f.setLayout(null); f.setVisible(true); } public static void main(String args[]) { new TextAreaExample(); }}

A) Output B) Output C) Output D) None of the above Answer - Output

Question) ------ is a protocol

A) netnews B) Sting C) hit D) none of above Answer - netnews

Question) -------is protocol

A) netnews B) finger C) e-mail D) all of the above Answer - all of the above

Question) ________________ interface enables a servlet to obtain information about a client request.

A) HttpServletRequest B) HttpServletResponse C) httpservletrequest D) Http Request Answer -


HttpServletRequest

Question) which of the following are the methods in belong to HttpServletRequest interface.

A) String getAuthType( ) B) Cookie[ ] getCookies( ) C) Both A and B D) Neither A nor B Answer -


Both A and B

Question) choose the output for following code: package jprogressbardemo; import java.awt.*; import
javax.swing.*; public class Main { public static void main(String[] args) { final int MAX = 100; final JFrame
frame = new JFrame("JProgress Demo"); // creates progress bar final JProgressBar pb = new
JProgressBar(); pb.setMinimum(0); pb.setMaximum(MAX); pb.setStringPainted(true); // add progress bar
frame.setLayout(new FlowLayout()); frame.getContentPane().add(pb);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 200);
frame.setVisible(true); // update progressbar for (int i = 0; i <= MAX; i++) { final int currentValue = i; try {
SwingUtilities.invokeLater(new Runnable() { public void run() { pb.setValue(currentValue); } });
java.lang.Thread.sleep(100); } catch (InterruptedException e) { JOptionPane.showMessageDialog(frame,
e.getMessage()); } } } }

A) B) C) both a & b D) none of the above Answer -

Question) Which of the following methods belong to HttpServletResponse interface.

A) void sendRedirect(String url) throws IOException B) void sendError(int c, String s) throws IOException
C) Both A and B D) Neither A nor B Answer - Both A and B

Question) Which of the following methods belong to in HttpSession interface.

https://localhost/dashboard/ques_ans_22517.php 91/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) String getId( ) B) void invalidate( ) C) long getLastAccessedTime( ) D) All of the above Answer
- All of the above

Question) What components will be needed to get following output?

A) JLabel, JTabbedPane, JCheckBox B) JTabbedPane, JList, JApplet C) JPanel, JTabbedPane, JList


D) JApplet, JTabbedPane, JPanel Answer - JPanel, JTabbedPane, JList

Question) _______________enables a servlet to read and write the state information that is associated with
an HTTP session.

A) HttpRequest B) HttpSession C) HttpServletRequest D) HttpServletResponse Answer -


HttpSession

Question) Choose the correct output to display the following Code. import javax.swing.*; import
java.awt.event.*; public class TextAreaExample implements ActionListener{ JLabel l1,l2; JTextArea area;
JButton b; TextAreaExample() { JFrame f= new JFrame(); l1=new JLabel(); l1.setBounds(50,25,100,30);
l2=new JLabel(); l2.setBounds(160,25,100,30); area=new JTextArea(); area.setBounds(20,75,250,200);
b=new JButton("Count Words"); b.setBounds(100,300,120,30); b.addActionListener(this);
f.add(l1);f.add(l2);f.add(area);f.add(b); f.setSize(450,450); f.setLayout(null); f.setVisible(true); } public void
actionPerformed(ActionEvent e){ String text=area.getText(); String words[]=text.split(" "); l1.setText("Words:
"+words.length); l2.setText("Characters: "+text.length()); } public static void main(String[] args) { new
TextAreaExample(); } }

A) B) C) Both A & B D) None of the above Answer -

Question) Choose the correct output to display the following code. import javax.swing.*; public class
PasswordFieldExample { public static void main(String[] args) { JFrame f=new JFrame("Password Field
Example"); JPasswordField value = new JPasswordField(); JLabel l1=new JLabel("Password:");
l1.setBounds(20,100, 80,30); value.setBounds(100,100,100,30); f.add(value); f.add(l1); f.setSize(300,300);
f.setLayout(null); f.setVisible(true); } }

A) B) C) D) Answer -

Question) choose the correct output for for following code: import java.awt.*; import java.awt.event.*; import
javax.swing.*; /* <applet code="JComboBoxDemo" width=300 height=100> </applet> */ public class
JComboBoxDemo extends JApplet implements ItemListener { JLabel jl; ImageIcon france, germany, italy,
japan; public void init() { // Get content pane Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout()); // Create a combo box and add it // to the panel JComboBox jc =
new JComboBox(); jc.addItem("France"); jc.addItem("Germany"); jc.addItem("Italy"); jc.addItem("Japan");
jc.addItemListener(this); contentPane.add(jc); // Create label jl = new JLabel(new ImageIcon("france.gif"));
contentPane.add(jl); } public void itemStateChanged(ItemEvent ie) { String s = (String)ie.getItem();
jl.setIcon(new ImageIcon(s + ".gif")); } }

A) B) C) D) none of the above Answer -

Question) import java.net.ServerSocket; In above statement ServerSocket is -----------

A) package B) class C) interface D) method Answer - class

https://localhost/dashboard/ques_ans_22517.php 92/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) choose output for following code: import javax.swing.*; import java.lang.*; public class
ToolTipExample { public static void main(String[] args) { //Creating PasswordField and label JPasswordField
value = new JPasswordField(); value.setBounds(100,100,100,30); value.setToolTipText("Enter your
Password"); JLabel l1=new JLabel("Password:"); l1.setBounds(20,100, 80,30); //Adding components to
frame f.add(value); f.add(l1); f.setSize(300,300); f.setLayout(null); f.setVisible(true); } }

A) Error in the program B) C) D) none of the above Answer - Error in the program

Question) Find the missing statement from the following code: import javax.swing.*; import java.lang.*;
public class ToolTipExample { public static void main(String[] args) {
_________________________________ //Creating PasswordField and label JPasswordField value = new
JPasswordField(); value.setBounds(100,100,100,30); value.setToolTipText("Enter your Password"); JLabel
l1=new JLabel("Password:"); l1.setBounds(20,100, 80,30); //Adding components to frame f.add(value);
f.add(l1); f.setSize(300,300); f.setLayout(null); f.setVisible(true); } }

A) JPanel p=new JPanel("Password Field Example"); B) JFrame f=new JFrame("Password Field


Example"); C) JContentPane c=new JContentPane("Password Field Example"); D) none of the above
Answer - JFrame f=new JFrame("Password Field Example");

Question) Which of these is a full form of DNS?

A) Data Network Service B) Data Name Service C) Domain Network Service D) Domain Name Service
Answer - Domain Name Service

Question) The HttpSession interface is implemented by the __________.

A) session B) cookies C) client D) server Answer - server

Question) A cookie is stored on a _______ and contains state information.

A) Session B) Cookies C) client D) server Answer - client

Question) UDP support -------

A) a simpler communication B) a faster communication C) point to point data gram oriental model D) All
of the above Answer - All of the above

Question) Panel is a pure container and is not a window in itself. The sole purpose of a Panel is to organize
the components on to a window.

A) True B) False C) D) Answer - True

Question) Swing is a ----------------------------, whose components are all ultimately derived from the
javax.swing.JComponent class.

A) Model-Based B) component-based framework C) Relational Based D) None of the above


Answer - component-based framework

Question) java.net package's interfaces are____________

A) URLConnection B) ContentHandlerFactory C) DatagramSocket D) All of the above Answer -


ContentHandlerFactory

https://localhost/dashboard/ques_ans_22517.php 93/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Choose correct output for following code: import javax.swing.*; import java.awt.event.*; public
class PasswordFieldExample { public static void main(String[] args) { JFrame f=new JFrame("Password
Field Example"); final JLabel label = new JLabel(); label.setBounds(20,150, 200,50); final JPasswordField
value = new JPasswordField(); value.setBounds(100,75,100,30); JLabel l1=new JLabel("Username:");
l1.setBounds(20,20, 80,30); JLabel l2=new JLabel("Password:"); l2.setBounds(20,75, 80,30); JButton b =
new JButton("Login"); b.setBounds(100,120, 80,30); final JTextField text = new JTextField();
text.setBounds(100,20, 100,30); f.add(value); f.add(l1); f.add(label); f.add(l2); f.add(b); f.add(text); }
f.setSize(300,300); f.setLayout(null); f.setVisible(true); b.addActionListener(new ActionListener() { public
void actionPerformed(ActionEvent e) { String data = "Username " + text.getText(); data += ", Password: "+
new String(value.getPassword()); label.setText(data); } }); } }

A) Error in the program B) C) D) Answer - Error in the program

Question) Constructor of JCheckBoxMenuItem is

A) JCheckBoxMenuItem() B) JCheckBoxMenuItem(Action a) C) JCheckBoxMenuItem(String text,


boolean b) D) All of the above Answer - All of the above

Question) Constructor of JTable is

A) JTable() B) JTable(Object[][] rows, Object[] columns) C) Both A & B D) None of the above
Answer - Both A & B

Question) Choose correct output for following code: import javax.swing.*; class MenuExample { JMenu
menu, submenu; JMenuItem i1, i2, i3, i4, i5; MenuExample(){ JFrame f= new JFrame("Menu and MenuItem
Example"); JMenuBar mb=new JMenuBar(); menu=new JMenu("Menu"); submenu=new JMenu("Sub
Menu"); i1=new JMenuItem("Item 1"); i2=new JMenuItem("Item 2"); i3=new JMenuItem("Item 3"); i4=new
JMenuItem("Item 4"); i5=new JMenuItem("Item 5"); menu.add(i1); menu.add(i2); menu.add(i3);
submenu.add(i4); submenu.add(i5); menu.add(submenu); mb.add(menu); f.setJMenuBar(mb);
f.setSize(400,400); f.setLayout(null); f.setVisible(true); } public static void main(String args[]) { new
MenuExample(); }}

A) B) C) D) Answer -

Question) Select Correct Code for Given Output:

https://localhost/dashboard/ques_ans_22517.php 94/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; public class TreeExample {


TreeExample(){ f=new JFrame(); DefaultMutableTreeNode style=new DefaultMutableTreeNode("Style");
DefaultMutableTreeNode color=new DefaultMutableTreeNode("color"); DefaultMutableTreeNode font=new
DefaultMutableTreeNode("font"); style.add(color); style.add(font); DefaultMutableTreeNode red=new
DefaultMutableTreeNode("red"); DefaultMutableTreeNode blue=new DefaultMutableTreeNode("blue");
DefaultMutableTreeNode black=new DefaultMutableTreeNode("black"); DefaultMutableTreeNode
green=new DefaultMutableTreeNode("green"); color.add(red); color.add(blue); color.add(black);
color.add(green); JTree jt=new JTree(style); f.add(jt); f.setSize(200,200); f.setVisible(true); } public static
void main(String[] args) { new TreeExample(); }} B) import javax.swing.*; import
javax.swing.tree.DefaultMutableTreeNode; public class TreeExample { JFrame f; TreeExample(){ f=new
JFrame(); DefaultMutableTreeNode style=new DefaultMutableTreeNode("Style"); DefaultMutableTreeNode
color=new DefaultMutableTreeNode("color"); DefaultMutableTreeNode font=new
DefaultMutableTreeNode("font"); style.add(color); style.add(font); DefaultMutableTreeNode red=new
DefaultMutableTreeNode("red"); DefaultMutableTreeNode blue=new DefaultMutableTreeNode("blue");
DefaultMutableTreeNode black=new DefaultMutableTreeNode("black"); DefaultMutableTreeNode
green=new DefaultMutableTreeNode("green"); color.add(red); color.add(blue); color.add(black);
color.add(green); JTree jt=new JTree(style); f.add(jt); f.setSize(200,200); f.setVisible(true); } public static
void main(String[] args) { new TreeExample(); }} C) import javax.swing.*; import
javax.swing.tree.DefaultMutableTreeNode; public class TreeExample { JFrame f; TreeExample(){ f=new
JFrame(); DefaultMutableTreeNode style=new DefaultMutableTreeNode("Style"); DefaultMutableTreeNode
color=new DefaultMutableTreeNode("color"); DefaultMutableTreeNode font=new
DefaultMutableTreeNode("font"); style.add(color); style.add(font); DefaultMutableTreeNode red=new
DefaultMutableTreeNode("red"); DefaultMutableTreeNode blue=new DefaultMutableTreeNode("blue");
DefaultMutableTreeNode black=new DefaultMutableTreeNode("black"); DefaultMutableTreeNode
green=new DefaultMutableTreeNode("green"); color.add(red); color.add(blue); color.add(black);
color.add(green); f.add(jt); f.setSize(200,200); f.setVisible(true); } public static void main(String[] args) { new
TreeExample(); }} D) import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; public class
TreeExample { JFrame f; TreeExample(){ f=new JFrame(); DefaultMutableTreeNode style=new
DefaultMutableTreeNode("Style"); DefaultMutableTreeNode color=new DefaultMutableTreeNode("color");
DefaultMutableTreeNode font=new DefaultMutableTreeNode("font"); style.add(color); style.add(font);
DefaultMutableTreeNode red=new DefaultMutableTreeNode("red"); DefaultMutableTreeNode blue=new
DefaultMutableTreeNode("blue"); DefaultMutableTreeNode black=new DefaultMutableTreeNode("black");
DefaultMutableTreeNode green=new DefaultMutableTreeNode("green"); color.add(red); color.add(blue);
color.add(black); color.add(green); JTree jt=new JTree(style); } public static void main(String[] args) { new
TreeExample(); }} Answer - import javax.swing.*; import
javax.swing.tree.DefaultMutableTreeNode; public class TreeExample { JFrame f; TreeExample(){
f=new JFrame(); DefaultMutableTreeNode style=new DefaultMutableTreeNode("Style");
DefaultMutableTreeNode color=new DefaultMutableTreeNode("color"); DefaultMutableTreeNode
font=new DefaultMutableTreeNode("font"); style.add(color); style.add(font);
DefaultMutableTreeNode red=new DefaultMutableTreeNode("red"); DefaultMutableTreeNode
blue=new DefaultMutableTreeNode("blue"); DefaultMutableTreeNode black=new
DefaultMutableTreeNode("black"); DefaultMutableTreeNode green=new
DefaultMutableTreeNode("green"); color.add(red); color.add(blue); color.add(black);
color.add(green); JTree jt=new JTree(style); f.add(jt); f.setSize(200,200); f.setVisible(true); } public
static void main(String[] args) { new TreeExample(); }}

https://localhost/dashboard/ques_ans_22517.php 95/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Choose correct output for following code: import javax.swing.*; public class RadioButtonExample
{ JFrame f; RadioButtonExample(){ f=new JFrame(); JRadioButton r1=new JRadioButton("A) Male");
JRadioButton r2=new JRadioButton("B) Female"); r1.setBounds(75,50,100,30);
r2.setBounds(75,100,100,30); ButtonGroup bg=new ButtonGroup(); bg.add(r1);bg.add(r2);
f.add(r1);f.add(r2); f.setSize(300,300); f.setLayout(null); f.setVisible(true); } public static void main(String[]
args) { new RadioButtonExample(); }}

A) B) C) D) all the above Answer -

Question) What is the difference between scrollbar and scrollpane

A) A Scrollpane is a Component, but not a Container whereas Scrollbar is a Container and handles its own
events and perform its own scrolling. B) A Scrollbar is a Component, but not a Container whereas
Scrollpane is a Container and handles its own events and perform its own scrolling C) A Scrollbar is
handles not its own events and perform its own scrolling. whereas Scrollpane handles not its own events
and perform its own scrolling D) all the above Answer - A Scrollbar is a Component, but not a
Container whereas Scrollpane is a Container and handles its own events and perform its own
scrolling

Question) What does x mean in javax.swing

A) x mean in javax.swing is Extension of java B) x mean in javax.swing is Extreme of java C) x mean in


javax.swing is Ex. of java D) x mean in javax.swing is Extra of java Answer - x mean in
javax.swing is Extension of java

Question) A layout manager is basically an object, Its mainly used to organize

A) components in a container B) Objects in a container C) components in a window D) Objects in a


panel Answer - components in a container

Question) Find missing statement to get the output shown import javax.swing.*; import java.awt.*; import
java.awt.event.*; public class LabelExample extends Frame implements ActionListener{ JTextField tf;
JLabel l; JButton b; LabelExample(){ tf=new JTextField(); tf.setBounds(50,50, 150,20); l=new JLabel();
l.setBounds(50,100, 250,20); b=new JButton("Find IP"); b.setBounds(50,150,95,30);
b.addActionListener(this); add(b);add(tf);add(l); setSize(400,400); setLayout(null); setVisible(true); } public
void actionPerformed(ActionEvent e) { try{ String host=tf.getText();
____________________________________________ l.setText("IP of "+host+" is: "+ip); }catch(Exception
ex){System.out.println(ex);} } public static void main(String[] args) { new LabelExample(); } }

A) String ip=java.net.InetAddress.getHostAddress(); B) String


ip=java.net.InetAddress.getByName(host).getHostAddress(); C) String
ip=java.net.InetAddress.getByName(host); D) None of the above Answer - String
ip=java.net.InetAddress.getByName(host).getHostAddress();

Question) Choose correct output for following code: import javax.swing.*; import java.awt.*; import
java.awt.event.*; public class DialogExample { private static JDialog d; DialogExample() { JFrame f= new
JFrame(); d = new JDialog(f , "Dialog Example", true); d.setLayout( new FlowLayout() ); JButton b = new
JButton ("OK"); b.addActionListener ( new ActionListener() { public void actionPerformed( ActionEvent e ) {
DialogExample.d.setVisible(false); } }); d.add( new JLabel ("Click button to continue.")); d.add(b);
d.setSize(300,300); d.setVisible(true); } public static void main(String args[]) { new DialogExample(); } }

A) B) C) D) none of the above Answer -

https://localhost/dashboard/ques_ans_22517.php 96/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) TreeNode and MutableTreeNode is___________

A) Both are classes B) class and interface C) Both are interfaces D) interface and class Answer -
Both are interfaces

Question) Find Correct Output for given Code : import javax.swing.*; public class ToolTipExample { public
static void main(String[] args) { JFrame f=new JFrame("Password Field Example"); JPasswordField value =
new JPasswordField(); value.setBounds(100,100,100,30); value.setToolTipText("Enter your Password");
JLabel l1=new JLabel("Password:"); l1.setBounds(20,100, 80,30); f.add(value); f.add(l1);
f.setSize(300,300); f.setLayout(null); f.setVisible(true); } }

A) Error B) C) D) Answer -

Question) Which method is used to change size and position of Components?

A) void set(int x,int y,int width,int height) B) void setBounds(int width,int height,int x) C) void setbounds(int
x,int y,int width,int height) D) void setBounds(int x,int y,int width,int height) Answer - void
setBounds(int x,int y,int width,int height)

Question) JRadioButton is a subclass of ________ class.

A) AbstractButton B) ButtonGroup C) JButton D) ImageIcon Answer - AbstractButton

Question) To implement swings which package is to be imported from the following options :

A) javax.JSwing B) java.swing C) java.javax D) javax.swing Answer - javax.swing

Question) import java.awt.*; import java.applet.*; public class ListExapp extends Applet /* <applet
code="ListExapp" width=300 height=300></applet>*/ { public void init() { List c=new List(6); c.add("C");
c.add("C++"); c.add("Java"); c.add("PHP"); c.add("Android"); add(c); } } What is the ouput of above code ?

A) B) C) D) Answer -

Question) The default layout manager for the content pane of a swing based applet is__________

A) GridBoxLayout B) CardLayout C) FlowLayout D) Border-Layout Answer - FlowLayout

Question) Which of the following GridBagLayout variable defines the external padding (border) around the
component in its display area?

A) gridwidth, gridheight B) gridx, gridy C) ipadx, ipady D) insets Answer - insets

Question) Which of the following GridBagLayout variables defines the padding that gets added to each side
of the component?

A) gridwidth, gridheight B) gridx, gridy C) ipadx, ipady D) insets Answer - ipadx, ipady

Question) Which of the following GridBagLayout variables specifies the number of cells occupied by the
component horizontally and vertically in the grid?

A) gridwidth, gridheight B) gridx, gridy C) ipadx, ipady D) insets Answer - gridwidth, gridheight

Question) Which component displays information in hierarchical manner with parent-child relationship?

https://localhost/dashboard/ques_ans_22517.php 97/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) AWT B) Frame C) Swing D) Window Answer - Swing

Question) What is the name of the Swing class that is used for frames?

A) SwingFrame B) Window C) Frame D) JFrame Answer - JFrame

Question) Swing is the set of ____________ that provides more powerful & flexible components as
compare to Abstract Window Tooklit (AWT).

A) constructors B) methods C) classes D) destructors Answer - classes

Question) Which method is used to close a swing frame

A) WINDOW_CLOSING B) WindowEvent(Window src, int type, Window other) C)


windowClosing(WindowEvent we) D) setDefaultCloseOperation() Answer -
setDefaultCloseOperation()

Question) Select the correct code for following output

A) import java.awt.*; import java.applet.*; public class ListExapp extends Applet /* <applet code="ListExapp"
width=300 height=300></applet>*/ { public void init() { Button b1=new Button("ok"); Button b2=new
Button("Cancel"); Checkbox c1=new Checkbox("Client side"); Checkbox c2=new Checkbox("Server Side");
List c=new List(5); c.add("C"); c.add("C++"); c.add("Java"); c.add("PHP"); c.add("Android"); add(c1);
add(c2); add(c); add(b2); add(b1); } } B) import java.awt.*; import java.applet.*; public class ListExapp
extends Applet /* <applet code="ListExapp" width=300 height=300></applet>*/ { public void init() { Button
b1=new Button("ok"); Button b2=new Button("Cancel"); Checkbox c1=new Checkbox("Client side");
Checkbox c2=new Checkbox("Server Side"); List c=new List(5); c.add("C"); c.add("C++"); c.add("Java");
c.add("PHP"); c.add("Android"); add(c1); add(c2); add(b1); add(b2); } } C) import java.awt.*; import
java.applet.*; public class ListExapp extends Applet /* <applet code="ListExapp" width=300 height=300>
</applet>*/ { public void init() { Button b1=new Button("ok"); Button b2=new Button("Cancel"); Checkbox
c1=new Checkbox("Client side"); Checkbox c2=new Checkbox("Server Side"); List c=new List(5);
c.add("C"); c.add("C++"); c.add("Java"); c.add("PHP"); c.add("Android"); add(c1); add(c); add(b1); add(b2);
} } D) import java.awt.*; import java.applet.*; public class ListExapp extends Applet /* <applet
code="ListExapp" width=300 height=300></applet>*/ { public void init() { Button b1=new Button("ok");
Button b2=new Button("Cancel"); Checkbox c1=new Checkbox("Client side"); Checkbox c2=new
Checkbox("Server Side"); List c=new List(5); c.add("C"); c.add("C++"); c.add("Java"); c.add("PHP");
c.add("Android"); add(c1); add(c2); add(c); add(b1); add(b2); } } Answer - import java.awt.*; import
java.applet.*; public class ListExapp extends Applet /* <applet code="ListExapp" width=300
height=300></applet>*/ { public void init() { Button b1=new Button("ok"); Button b2=new
Button("Cancel"); Checkbox c1=new Checkbox("Client side"); Checkbox c2=new Checkbox("Server
Side"); List c=new List(5); c.add("C"); c.add("C++"); c.add("Java"); c.add("PHP"); c.add("Android");
add(c1); add(c2); add(c); add(b1); add(b2); } }

Question) Which of the following is not a swing class?

A) JComboBox B) JFrame C) JComponent D) canvas Answer - canvas

Question) __________ is a Swing class that allows the user to enter a multipleline of text

A) JLabel B) JTextField C) JTextArea D) JComboBox Answer - JTextArea

Question) _____________________ is not a Swing Component

https://localhost/dashboard/ques_ans_22517.php 98/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) CheckboxGroup B) CheckBox C) JComboBox D) all the above Answer - CheckboxGroup

Question) which AWT components are added in given output ?

A) Button,TextField B) Label,TextField C) Button,Label ,TextArea D) TextField,Button,TextArea


Answer - Button,Label ,TextArea

Question) The Jtable of swings is used to display data in form of_____________

A) JTable object displays rows and columns of data. B) JTable object displays rows ONLY. C) JTable
object displays columns ONLY D) none of the above Answer - JTable object displays rows and
columns of data.

Question) Which of the following view file types are supported in MVC?

A) .cshtml B) .vbhtml C) .aspx D) All of the above Answer - All of the above

Question) Observe the following code import java.awt.*; import java.applet.*; public class LayoutDemo5
extends Applet { public void init() { int i,j,k,n=4; setLayout(new BorderLayout()); Panel p1=new Panel();
Panel p2=new Panel(); p1.setLayout(new FlowLayout()); p1.add(new TextField(20)); p1.add(new
TextField(20)); p2.setLayout(new GridLayout(5,3)); p2.add(new Button("OK")); p2.add(new
Button("Submit")); add(p1,BorderLayout.EAST); add(p2,BorderLayout.WEST); } } /*<applet
code=LayoutDemo5.class width=300 height=400> </applet>*/ What will be the output of the above
program?

A) The output is obtained in Frame with two layouts: Frame layout and Flow Layout. B) The output is
obtained in Applet with two layouts: Frame layout and Flow Layout. C) The output is obtained in Applet
with two layouts: Frame layout and Border Layout. D) The output is obtained in Applet with two layouts:
Border layout and Flow Layout Answer - The output is obtained in Applet with two layouts:
Border layout and Flow Layout

Question) Term in MVC architecture that receives events is called as_________

A) Receiver B) Controller C) Transmitter D) Modulator Answer - Controller

Question) Which is the best approach to assign a session in MVC?

A) System.Web.HttpContext.Current.Session["LoginID"] =7; B) Current.Session["LoginID"] =7; C)


Session["LoginID"] =7; D) None Answer - Current.Session["LoginID"] =7;

Question) ___________Constructs a new scroll bar with the specified orientation.

A) Scrollbar() B) Scrollbar(int ) C) Scrollbar(int , int , int , int , int) D) All of above Answer -
Scrollbar(int )

Question) The class JList is a component which displays _________and allows the user to select one or
more items.

A) List of lists B) list of objects C) MVC Model D) Item List Answer - list of objects

Question) import java.awt.*; public class microGUI { public static void main ( String[] args ) { Frame frm =
new ___________(); frm.___________( 150, 100 ); frm.___________( true ); } } Fill in the blanks with
correct sequence of methods.

https://localhost/dashboard/ques_ans_22517.php 99/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) Form, setVisible, setOn B) Frame, setSize, setVisible C) Frame, setVisible, setSize D) Window,
setSize, paint Answer - Frame, setSize, setVisible

Question) Which is the correct constructor of GridLayout

A) GridLayout(int numrows) B) GridLayout(int numrows, int numcols,intx) C) GridLayout(int numrows, int


numcols,intx,inty) D) GridLayout(int numrows, int numcols) Answer - GridLayout(int numrows, int
numcols)

Question) 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 ); } } fill in the blanks with correct
option.

A) import, drawString, paint B) extends, paint, drawString C) extends, draw, paint D) include,
drawString, paint Answer - extends, paint, drawString

Question) Panel is a concrete subclass of _______________.

A) Window B) Container. C) Panel D) Frame Answer - Container.

Question) From Following list which is not a swing class?

A) ImageIcon B) JIcon C) JButton D) JPane Answer - JIcon

Question) import java.awt.*; import java.applet.*; public class buttonDemo extends Applet /* <applet
code="buttonDemo" width=300 height=300></applet>*/ { public void init() { Button a1=new Button("ok");
Button a2=new Button("Cancel"); Button a3=new Button("Submit"); a2.setLabel("Welcome");
a3.setEnabled(false); add(a1); add(a2); add(a3); } } What will be the output ?

A) B) C) D) Answer -

Question) A ___________________ array of strings is created for specifying the column headings in
JTable.

A) two-dimensional B) one-dimensional C) multi dimensional D) none of these Answer - one-


dimensional

Question) JProgressBar() of swings creates______________

A) Vertical Progress Bar Only B) Horizontal Progress Bar with Progress String. C) Horizontal and Vertical
Progress Bar without progress string. D) Horizontal Progress Bar without progress string. Answer -
Horizontal Progress Bar without progress string.

Question) Which is correct statement from given option for using a table in an applet:

A) Create aJScrollPaneobject B) Add the table to the scroll pane. C) Create aJTableobject D) All of the
above Answer - All of the above

Question) Java Swings is used to create ______________________ applications.

A) mobile enabled B) web based C) window based D) package based Answer - window based

Question) To add tab to the panel which method is used?

https://localhost/dashboard/ques_ans_22517.php 100/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) addTab() B) addJPanel() C) addPanel() D) addJTab() Answer - addTab()

Question) How to change the current layout managers for a container?

A) ChangeLayout() method B) isLayout() method C) setLayout() method D) getLayout() method


Answer - setLayout() method

Question) Select the correct code for given output?

A) import java.awt.*; import java.applet.*; public class buttonDemo1 extends Applet /* <applet
code="buttonDemo1" width=300 height=300></applet>*/ { public void init() { Button a1=new Button("ok");
Button a2=new Button("Cancel"); Button a3=new Button("Submit"); add(a1); add(a2); add(a3); } } B) import
java.awt.*; import java.applet.*; public class buttonDemo1 extends Applet /* <applet code="buttonDemo1"
width=300 height=300></applet>*/ { public void init() { Button a1=new Button("ok"); Button a2=new
Button("Cancel"); Button a3=new Button("Submit"); a2.setEnabled(false); add(a1); add(a2); add(a3); } } C)
import java.awt.*; import java.applet.*; public class buttonDemo1 extends Applet /* <applet
code="buttonDemo1" width=300 height=300></applet>*/ { public void init() { Button a1=new Button("ok");
Button a2=new Button("Cancel"); Button a3=new Button("Submit"); a2.setEnabled(true); add(a1); add(a2);
add(a3); } } D) import java.awt.*; import java.applet.*; public class buttonDemo1 extends Applet /* <applet
code="buttonDemo1" width=300 height=300></applet>*/ { public void init() { Button a1=new Button("ok");
Button a2=new Button("Cancel"); Button a3=new Button("Submit"); a1.setEnabled(false); add(a1); add(a2);
add(a3); } } Answer - import java.awt.*; import java.applet.*; public class buttonDemo1 extends
Applet /* <applet code="buttonDemo1" width=300 height=300></applet>*/ { public void init() { Button
a1=new Button("ok"); Button a2=new Button("Cancel"); Button a3=new Button("Submit");
a2.setEnabled(false); add(a1); add(a2); add(a3); } }

Question) JComboBox control initially displays _____ entry

A) One B) Two C) Empty D) NULL Answer - One

Question) What does the File dialog constructor Dialog(Frame parent,String title,int mode) does ?

A) Creates a file dialog window with the specified title ONLY. B) Creates a file dialog window with the
specified title for loading or saving a file. C) Creates a file dialog window with the specified title for loading
ONLY. D) Creates a file dialog window with the specified title for saving a file ONLY. Answer -
Creates a file dialog window with the specified title for loading or saving a file.

Question) The title of the dialog box is stored in ____________

A) dialog variable B) Window variable C) Title variable D) Frame Variable Answer - Title variable

Question) Dialog box is closed then which method is called?

A) Exit() B) dialog_close() C) close() D) dispose() Answer - dispose()

Question) AbstractButton is the template class for________________

A) Push Buttons B) Radio Buttons C) Check boxes D) All of the above. Answer - All of the
above.

Question) What is use of 5th parameter in given constructor Scrollbar(int,int,int,int,int)

A) orientation B) visible C) maximum D) minimum Answer - maximum

https://localhost/dashboard/ques_ans_22517.php 101/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) In given constructor what 3rd parameter indicates Scrollbar s=new Scrollbar(0,10,20,0,1000)

A) orientation B) visible C) thumbsize D) none of these Answer - thumbsize

Question) What is purpose of default constructor of Scrollbar( ) class?

A) To create vertical Scrollbar B) To create horizontal Scrollbar C) Both D) all of above Answer -
To create vertical Scrollbar

Question) The three software parts of a GUI program are:

A) Windows, Buttons, Mice B) GUI Components, Graphics, Code C) GUI Components, Event Listeners,
Application Code D) Frames, Code, Events Answer - GUI Components, Event Listeners,
Application Code

Question) Consider the following code segment. Insert correct code at blank space.
checkbox._____________ (new ItemListener() { public void _______________(ItemEvent ie) { if
(checkbox.getState() == true) { JOptionPane.showMessageDialog(null, "checkbox is checked"); } else {
JOptionPane.showMessageDialog(null, "checkbox is unchecked"); } } });

A) itemStateChanged, addItem B) ItemListener, itemChanged C) StateChanged, addItem D)


addItemListener, itemStateChanged Answer - addItemListener, itemStateChanged

Question) Which of the following sets the frame to 300 pixels wide by 200 high?

A) frm.setSize( 300, 200 ); B) frm.setSize( 200, 300 ); C) frm.paint( 300, 200 ); D) frm.setVisible( 300,
200 ); Answer - frm.setSize( 300, 200 );

Question) What is a container object in GUI programming?

A) A container is another name for an array or vector. B) A container is any class that is made up of other
classes. C) A container is a primitive variable that contains the actual data. D) A container is an object
like a Frame that has other GUI components placed inside of it. Answer - A container is an object
like a Frame that has other GUI components placed inside of it.

Question) Which of the following is the Java toolkit used to write GUI programs?

A) GUI toolkit B) Abstract Windowing Toolkit C) Graphics Event Toolkit D) Java Enhancement Toolkit
Answer - Abstract Windowing Toolkit

Question) 1. import java.awt.*; 2. import java.awt.event.*; 3. public class ItemEx1 implements ItemListener {
4. Frame jf; 5. Checkbox chk1, chk2; 6. Label label1; 7. ItemEx1() { 8. jf= new Frame("Checkbox"); 9. chk1
= new Checkbox("Happy"); 10. chk2 = new Checkbox("Sad"); 11. label1 = new Label(); 12. jf.add(chk1); 13.
jf.add(chk2); 14. chk1.addItemListener(this); 15. chk2.addItemListener(this); 16. jf.setLayout(new
FlowLayout()); 17. jf.setSize(220,150); 18. jf.setVisible(true); 19. } 20. // Line no 20 21. Checkbox ch =
(Checkbox) ie.getItemSelectable(); 22. if(ch.getState()==true) { 23. label1.setText(ch.getLabel()+ " is
checked"); 24. jf.add(label1); 25. jf.setVisible(true); 26 } 27 else { 28 label1.setText(ch.getLabel()+ " is
unchecked"); 29 jf.add(label1); 30 jf.setVisible(true); 31 } 32 } 33 public static void main(String... ar) { 34 new
ItemEx1(); 35 } 36 } Identify correct code at line no 20

A) public void itemModified(ItemEvent ie) { B) public void itemStateSelectable(ItemEvent ie) { C) public


void itemChange(ItemEvent ie) { D) public void itemStateChanged(ItemEvent ie) { Answer - public
void itemStateChanged(ItemEvent ie) {

https://localhost/dashboard/ques_ans_22517.php 102/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) When is the paint() method of a frame object called?

A) The user calls it to display the frame. B) The main() method calls it once when the program starts. C)
The Java system calls it every time it decides to display the frame. D) The Java system calls it once when
the program starts. Answer - The Java system calls it every time it decides to display the frame.

Question) 1. public void itemStateChanged(ItemEvent ie) { 2. Checkbox ch =


(Checkbox)ie.setItemSelectable(); 3. if(ch.getState()==true) { 4. label1.setText(ch.getLabel()+ " is checked");
5. jf.add(label1); 6. jf.setVisible(true); 7 .} Which statement is true ?

A) There are syntax errors on line no. 1 B) There are syntax errors on line no. 2 C) There are syntax
errors on line no. 4 D) There are syntax errors on line no. 6 Answer - There are syntax errors on
line no. 2

Question) What is a Graphics object?

A) The Graphics object represents the part of the Frame that you can draw on. B) The Graphics object
represents the whole Frame. C) The Graphics object represents the entire monitor. D) The Graphics
object represents the graphics board. Answer - The Graphics object represents the part of the
Frame that you can draw on.

Question) Which of the following determines how the components of a container are displayed?

A) Display Manager B) Component Manager C) Stage Manager D) Layout Manager Answer -


Layout Manager

Question) Which method of a Frame is used to set the layout manager?

A) setLayout() B) add() C) actionPerformed() D) setVisible() Answer - setLayout()

Question) 1. public void itemStateChanged(ItemEvent ie ) { 2. JCheckBox cb = (JCheckBox) ie.getItem( ); 3.


int state ie.getStateChange( ); 4. // Line no 4 5. System.out.println(cb.getText( ) + "selected"); 6. else 7.
System.out.println(cb.getText( ) + "cleared"); 8. } Identify correct code at line no 4

A) if (state == ItemEvent.Change) B) if (state == ItemEvent.Modified) C) if (state ==


ItemEvent.SELECTED) D) if (state == ItemEvent.getText) Answer - if (state ==
ItemEvent.SELECTED)

Question) Which are the not types of key events-

A) KEY_PRESSED B) KEY_DOUBLE C) KEY_RELEASED D) KEY_TYPED Answer -


KEY_DOUBLE

Question) Interface MouseMotionListener belongs to _____________ package.

A) java.listener B) java.util.event C) java.awt.event D) java.motion Answer - java.awt.event

Question) _____________is the super class of all event classes.

A) Event B) Object C) EventObject D) EventClass Answer - EventObject

Question) Which of this interface is defines a method adjustmentValueChanged( ) ?

https://localhost/dashboard/ques_ans_22517.php 103/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) ComponentListener B) ContainerListener C) ItemStateListener D) AdjustmentListener Answer


- AdjustmentListener

Question) Which of these interfaces define a method keyPressed()?

A) MouseMotion Listener B) MouseListener C) KeyBoardListener D) KeyListener Answer -


KeyListener

Question) From following options which of these is method of MouseMotionListener Interface

A) mouseMoved() B) MouseMotionListener() C) MouseClick() D) MousePressed() Answer -


mouseMoved()

Question) Fill in the blank: MouseMotionListener interface defines___________methods

A) one B) two C) three D) four Answer - two

Question) A source is an ________ that generates an event .

A) class B) interface C) object D) variable Answer - object

Question) Assuming we have a class which implements the ActionListener interface, which method should
be used to register this with a Button? ;

A) addListener(*) B) addActionListener(*); C) addButtonListener(*); D) setListener(*); Answer -


addActionListener(*);

Question) windowGainedFocus() and windowLostFocus() methods are belongs to _____________ interface


.

A) WindowInterface B) WindowFocused Interface C) WindowFocusListener D) WindowAction Interface


Answer - WindowFocusListener

Question) Fill in the blank: MouseListener interface define…........methods

A) 2 B) 5 C) 7 D) 4 Answer - 5

Question) KEY_TYPED Event generated when....

A) key pressed or released B) only when character is generated C) only key pressed D) only key
released Answer - only when character is generated

Question) Which of these methods are used to register a Window listener?

A) windowListener() B) addListener() C) addWindowListener() D) eventWindowListener() Answer


- addWindowListener()

Question) Which of these methods are used to register a mouse motion listener?

A) addMouse() B) addMouseListener() C) addMouseMotionListner() D) eventMouseMotionListener()


Answer - addMouseMotionListner()

Question) KeyEvent Constructor- KeyEvent(Component src, int type, long when, int modifiers, int code, char
ch) Here when means-

https://localhost/dashboard/ques_ans_22517.php 104/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) a reference to the component that generated the event. B) The type of event occured. C) virtual key
codes D) The system time at which the key was pressed. Answer - The system time at which the
key was pressed.

Question) What is a listener in context to event handling?

A) A listener is a variable that is notified when an event occurs. B) A listener is a object that is notified
when an event occurs. C) A listener is a method that is notified when an event occurs. D) None of the
mentioned. Answer - A listener is a object that is notified when an event occurs.

Question) The KeyEvent class methods-

A) getKeyCode ( ) B) geyKeyTyped( ) C) getKeyChar ( ) D) both a and c Answer - both a and c

Question) Which of these are methods of TextListener Interface?

A) textChange() B) textModified() C) textValueChanged() D) textValueModified() Answer -


textValueChanged()

Question) If no valid character is available then geyKeyChar( ) returns-

A) VK_UNDEFINED B) CHAR_UNDEFINED C) VK_CONTROL D) CHAR_ERROR Answer -


CHAR_UNDEFINED

Question) Which of these are methods of KeyListener Interface?

A) keyPressed() B) keyReleased() C) keyTyped() D) All of this Answer - All of this

Question) KeyEvent is a subclass of-

A) InputEvent B) TextEvent C) ItemEvent D) MouseEvent Answer - InputEvent

Question) Which source generates adjustment events?

A) Button B) List C) Scroll bar D) Text components Answer - Scroll bar

Question) DatagramPacket(byte data[ ], int size) DatagramPacket(byte data[ ], int offset, int size) are
examples of--------------

A) package B) class C) Interface D) constructors Answer - constructors

Question) ___________ method is used to register a Component listener.

A) addMouse() B) addComponentListener( ) C) addMouseMotionListener() D)


eventMouseMotionListener() Answer - addComponentListener( )

Question) MouseEvent Constructor- MouseEvent(Component src, in type, long when, int modifiers, int x, int
y, int clicks, boolean triggersPopup) Here x and y means-

A) co-ordinates of the mouse passed B) The click count C) Reference to the component D) The system
time at which the mouse event occured. Answer - co-ordinates of the mouse passed

Question) getPoint( ) , method to obtain ...................................

https://localhost/dashboard/ques_ans_22517.php 105/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) x - co-ordinates of the mouse. B) y- co-ordinates of the mouse. C) both x and y co-ordinates of the
mouse. D) The total number of click count. Answer - both x and y co-ordinates of the mouse.

Question) The following statement return- Point getPoint( )

A) to obtain the coordinates of the mouse. B) returns Point int that contains the Y C) returns Point object
that contains the X D) to obtain the coordinates of the key Answer - to obtain the coordinates of
the mouse.

Question) The, int getClickCount( ) method returns-

A) number of mouse clicks for widgets. B) number of mouse clicks for graphical user interface. C) number
of mouse clicks for this event. D) number of mouse clicks from application started. Answer -
number of mouse clicks for this event.

Question) The isPopupTrigger( ) methods returns-

A) int B) void C) object D) boolean Answer - boolean

Question) The, getButton( ) method returns-

A) returns int value that represents the button that caused the event. B) returns boolean value that
represents the button that caused the event. C) returns void and generates events. D) returns object and
generates events. Answer - returns int value that represents the button that caused the event.

Question) The __________interface handles item event.

A) ActionListener B) ItemListener C) ItemHandler D) WindowListener Answer - ItemListener

Question) Which method not use to obtain the coordinates of the mouse-

A) Point getLocationOnScreen( ) B) int getKeyCode( ) C) int getXOnScreen( ) D) int getYOnScreen( )


Answer - int getKeyCode( )

Question) Which of these method are used to register a keyboard event Listener ?

A) KeyListener() B) addKeyListener() C) RegisterKeyListener() D) addKeyBoard() Answer -


addKeyListener()

Question) The TextEvent generated by-

A) text fields and text areas when characters are entered. B) text fields and text areas when mouse
entered. C) text fields and text areas when mouse clicked D) text fields and text areas when keyboard
press. Answer - text fields and text areas when characters are entered.

Question) Which is the correct general form of method of the ActionListener interface?

A) void ActionPerformed(ActionEvent ae) B) void ActionPerformed(Actionevent ae) C) void


actionPerformed(ActionEvent ae) D) void ActionPerformed(actionEvent ae) Answer - void
actionPerformed(ActionEvent ae)

Question) The TextEvent Constructor- TextEvent(Object src, int type) Here type means-

https://localhost/dashboard/ques_ans_22517.php 106/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) The type of text B) The type of object passed. C) The type of event. D) The type of source generated
events. Answer - The type of event.

Question) keyTyped() is method of __________ interface.

A) KeyBoard Interface B) Mouse Interface C) WindowListener Interface D) KeyListener Interface


Answer - KeyListener Interface

Question) keyPressed() is method of __________ interface.

A) KeyBoard Interface B) Mouse Interface C) WindowListener Interface D) KeyListener Interface


Answer - KeyListener Interface

Question) keyReleased() is method of __________ interface.

A) KeyBoard Interface B) Mouse Interface C) WindowListener Interface D) KeyListener Interface


Answer - KeyListener Interface

Question) windowDeiconified() is method of ________interface

A) WindowListener Interface B) Window Interface C) Window Conified Interface D) Action Interface


Answer - WindowListener Interface

Question) windowIconified() is method of ________interface

A) WindowListener Interface B) Window Interface C) WindowConified Interface D) Action Interface


Answer - WindowListener Interface

Question) WindowActivated() is method of ________interface.

A) WindowListener Interface B) Window Interface C) Window Activated Interface D) Action Interface


Answer - WindowListener Interface

Question) windowClosed() is method of ________interface.

A) WindowListener Interface B) Window Interface C) WindowClosed Interface D) Action Interface


Answer - WindowListener Interface

Question) windowClosing() is method of ________interface

A) WindowListener Interface B) Window Interface C) WindowConified Interface D) Action Interface


Answer - WindowListener Interface

Question) When a ------------- Dialog box is active, it blocks user input to all other windows in the program.

A) modal B) modeless C) file D) none of the above Answer - modal

https://localhost/dashboard/ques_ans_22517.php 107/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Find the missing Statements in the following program to get the given output: import java.awt.*;
import java.awt.event.*; public class DialogEx extends WindowAdapter implements ActionListener { Frame
frame; Label label1; TextField field1; Button button1, button2, button3; Dialog d1, d2, d3; DialogEx() { frame
= new Frame("Frame"); button1 = new Button("Open Modal Dialog"); label1 = new Label("Click on the
button to open a Modal Dialog"); frame.add(label1); frame.add(button1); button1.addActionListener(this);
frame.pack(); frame.setLayout(new FlowLayout()); frame.setSize(330,250); frame.setVisible(true); } public
void actionPerformed(ActionEvent ae) { if(ae.getActionCommand().equals("Open Modal Dialog")) { ------------
--------------------------- Label label= new Label("You must close this dialog window to use Frame
window",Label.CENTER); d1.add(label); d1.addWindowListener(this); d1.pack();
d1.setLocationRelativeTo(frame); d1.setLocation(new Point(100,100)); d1.setSize(400,200); --------------------
------------------- } } public void windowClosing(WindowEvent we) { d1.setVisible(false); } public static void
main(String...ar) { new DialogEx(); } }

A) d1= new Dialog(frame,"Modal Dialog",true); B) d1.setVisible(true); C) d1= new Dialog(frame,"Modal


Dialog",true); d1.setVisible(true); D) d1= new Dialog(frame,"Modal Dialog",true);d1.setVisible(false);
Answer - d1= new Dialog(frame,"Modal Dialog",true); d1.setVisible(true);

Question) Following method returns true if a cookie contains the session ID. Otherwise, returns false.

A) boolean RequestedSessionIdFromCookie( ) B) boolean isRequestedSessionId( ) C) boolean


isRequestedFromCookie( ) D) boolean isRequestedSessionIdFromCookie( ) Answer - boolean
isRequestedSessionIdFromCookie( )

Question) Which of the following method returns true if the URL contains the session ID. Otherwise, returns
false.

A) boolean isRequestedSessionIdFromURL( ) B) int requestedSessionIdFromURL( ) C) boolean


isRequestedSessionIdFromcookie( ) D) int isRequestedSessionIdFromURL( ) Answer - boolean
isRequestedSessionIdFromURL( )

Question) _________ method returns true if the requested session ID is valid in the current session context.

A) boolean RequestedSessionIdValid( ) B) boolean isRequestedSessionId( ) C) boolean


isRequestedValid( ) D) boolean isRequestedSessionIdValid( ) Answer - boolean
isRequestedSessionIdValid( )

Question) Which of the following method returns the session for this request. If a session does not exist,
one is created and then returned.

A) httpsession getsession( ) B) HttpServlet getSession( ) C) HttpSession getSession( ) D) Session


getsession( ) Answer - HttpSession getSession( )

Question) Text Fields is also know as ___________

A) Single line control B) Active Control C) Passive Control D) Edit Control Answer - Edit Control

Question) All the methods of HttpSession interface throw an _____________ if the session has already
been invalidated.

A) IllegalState B) IllegalException C) LegalStateException D) IllegalStateException Answer -


IllegalStateException

Question) Following method returns an enumeration of the attribute names associated with the session..

https://localhost/dashboard/ques_ans_22517.php 108/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) Enumeration getAttributeNames( ) B) String getAttributeNames( ) C) void getAttributeNames( ) D)


none of the above Answer - Enumeration getAttributeNames( )

Question) Echoing of characters can be disabled as they are typed by using_________________

A) echoChar() B) isEchochar() C) setEchochar() D) echoCharIsSet() Answer - setEchochar()

Question) Following method returns the time (in milliseconds since midnight, January 1, 1970, GMT) when
this session was created.

A) int getcreationtime( ) B) long CreationTime( ) C) long getCreationTime( ) D) long getCreation( )


Answer - long getCreationTime( )

Question) JChoice control of swings is a kind of_____________

A) Menu B) Item C) Radio D) List Answer - Menu

Question) Which of the following method invalidates the session and removes it from the context.

A) String invalidate( ) B) void invalidate( ) C) int invalidate( ) D) void setinvalidate( ) Answer -


void invalidate( )

Question) JLabels are ____________ Control.

A) Active B) User C) Passive D) Interactive Answer - Passive

Question) Which of the following classes represents event notifications for changes to sessions within a
web application

A) Cookie B) HttpServlet C) HttpSessionEvent D) HttpSessionBindingEvent Answer -


HttpSessionEvent

Question) Which Property is wrong for JLabel

A) Label.LEFT B) Label.CENTER C) Label.RIGHT D) Label.BOTTOM Answer - Label.BOTTOM

Question) URLEncoder , URLConnection , URLDecoder are examples of

A) package B) class C) interface D) method Answer - class

Question) ContentHandlerFactory , CookiePolicy,CookieStore are examples of

A) package B) class C) interface D) method Answer - interface

Question) Which of the following are the different methods of ResultSet interface? 1. public boolean next()
2. public boolean previous() 3. public boolean back() 4. public boolean last()

A) 1,2,3 B) 1,2,4 C) 2,3,4 D) All of the above. Answer - 1,2,4

Question) Which of the following are the different methods of Statement interface? 1. public int[]
executeBatch() 2. public boolean execute(String sql) 3. public int executeUpdate(String sql) 4. public int
insert(String sql)

A) 1,2,3 B) 2,3,4 C) 1,3,4 D) All of the above. Answer - 1,2,3

https://localhost/dashboard/ques_ans_22517.php 109/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Consider the following program, Select the statement that should be added to the program to get
correct output. import java.sql.*; public class MyData { public static void main(String args[])throws Exception
{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
c=DriverManager.getConnection("jdbc:odbc:MyDSN","",""); PreparedStatement s=c.prepareStatement(
"update student set Name=* where Roll_no=*"); s.setString(1,"XYZ"); s.setString(2,"1"); s.executeUpdate();
s.close(); c.close(); } }

A) a. use s.executeQuery() method B) Use ; in main method C) Use s.setString(2,1) method D) use ? in
PreparedStatement Answer - use ? in PreparedStatement

Question) 6. Which is the incorrect statement in the following Code? import java.sql.*; public class Sample1
{ public static void main(String args[])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:DSN2","",""); PreparedStatement
s=c.createStatement( ); ResultSet rs=s.executeQuery("select* from student"); System.out.println("Name"+"
"+"Roll no"+" "+"Avg"); while(rs.next()) { System.out.println(rs.getString(1)+" "+rs.getInt(2)+"
"+rs.getDouble(3)); } s.close(); c.close(); } }

A) ResultSet rs=s.executeQuery(); B) Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); C)


PreparedStatement s=c.createStatement(); D) None of the above Answer - PreparedStatement
s=c.createStatement();

Question) Consider the following program. What should be the correction done in the program to get correct
output? import java.sql.*; public class DataBase{ public static void main(String[] args) {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn =
DriverManager.getConnection("jdbc:odbc:abc", "", ""); String s1="insert into student values(1,'abc');
s.executeUpdate(s1); s.close(); conn.close();}catch(IOException e){System.out.println(e);} } }

A) Insert try and catch(FileNotFoundException fe) B) Use s.executeQuery(s1); C) Insert try and
catch(Exception e) D) Insert catch(Exception e) Answer - Insert try and catch(Exception e)

Question) Fill in the blanks respectively. import java.io.*; import javax.servlet.*; import javax.servlet.http.*;
public class GetCookiesServlet extends HttpServlet { public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException { Cookie[] cookies =
request._____________; response.setContentType("text/html"); PrintWriter pw = response.getWriter();
pw.println("<B>"); for(int i = 0; i < cookies.length; i++) { String name = cookies[i].______________; String
value = cookies[i].____________ ; pw.println("name = " + name + "; value = " + value); } pw.close(); } }

A) getname(); getvalue(); getcookies(); B) doHead(); doOptions(); doTrace() C) service(); doHead();


doTrace(); D) getCookies(); getName(); getValue(); Answer - getCookies(); getName();
getValue();

Question) Fill in the blanks at the line number 4 and 8 respectively. 1. import java.io.*; 2. import
javax.servlet.*; 3. import javax.servlet.http.*; 4. public class GetCookiesServlet extends __________ { 5.
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException { 6. Cookie[] cookies = request.getCookies(); 7. response.setContentType(""text/html""); 8.
PrintWriter pw =__________.getWriter(); 9. pw.println(""<B>""); 10. for(int i = 0; i < cookies.length; i++) { 11.
String name = cookies[i].getName(); 12. String value = cookies[i].getValue(); 13. pw.println(""name = "" +
name + ""; value = "" + value); 14. } 15. pw.close(); 16. } 17. }

A) GenericServlet , request B) HttpServlet , response C) HttpServlet , request D) GenericServlet ,


response Answer - HttpServlet , response

https://localhost/dashboard/ques_ans_22517.php 110/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) What will be the output of the following program. import java.sql.*; import java.io.*; public class
RetrieveImage { public static void main(String[] args) { try{ Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
PreparedStatement ps=con.prepareStatement("select * from imgtable"); ResultSet rs=ps.executeQuery();
if(rs.next()){ Blob b=rs.getBlob(2); data byte barr[]=b.getBytes(1,(int)b.length()); FileOutputStream fout=new
FileOutputStream("d:\picture.jpg"); fout.write(barr); fout.close(); }//end of if con.close(); }catch (Exception e)
{e.printStackTrace(); } } }

A) image will be inserted into the database B) Image will be retrieved from the database. C) ; missing
D) } missing Answer - Image will be retrieved from the database.

Question) setAttribute( ), getAttribute( ), getAttributeNames( ), and removeAttribute( ) methods of


____________ interface.

A) HttpSession B) HttpServlet C) HttpServletResponse D) HttpServletRequest Answer -


HttpSession

Question) import java.awt.*; import java.applet.*; public class checkboxDemo extends Applet /* <applet
code="checkboxDemo" width=300 height=300></applet>*/ { public void init() { Checkbox cb1,cb2;
CheckboxGroup cbg=new CheckboxGroup(); cb1=new Checkbox("Java",true,cbg); cb2=new
Checkbox("C++",false,cbg); add(cb1);add(cb2); } } What is expected output of above code ?

A) Creates two checkboxes named "Java" and "C++" B) Creates two radio buttons with "Java" and "C++"
with "Java" button as selected initially. C) Creates two radio buttons with "Java" and "C++" with "C++"
button as selected initially. D) None of these Answer - Creates two radio buttons with "Java" and
"C++" with "Java" button as selected initially.

Question) void setPath(String p) void setSecure(boolean secure) void setValue(String v) void setVersion(int
v) Identify the class where above methods belong to.

A) HttpSession B) HttpServlet C) Cookie D) GenericServlet Answer - Cookie

Question) import java.awt.*; import javax.swing.*; public class LayoutDemo{ JFrame f; LayoutDemo(){
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");
f.add(b1);f.add(b2);f.add(b3);f.add(b4);f.add(b5); f.setLayout(new FlowLayout(FlowLayout.RIGHT)); //setting
flow layout of right alignment f.setSize(300,300); f.setVisible(true); } public static void main(String[] args) {
new LayoutDemo(); } } Find the output.

A) B) C) D) Answer -

Question) Select correct option to get the proper output: import java.awt.*; import java.applet.*; public class
LayoutDemo extends Applet { static final int n = 4; public void init() { setLayout(new GridLayout(n, n));
setFont(new Font("SansSerif", Font.BOLD, 24)); for(int i = 0; i < n; i++) { for(int j = 0; j <n; j++) { int k = i * n +
j; if(k > 0) add(new Button("" + k)); } } } } /*<applet code="LayoutDemo.class" width=100 height=100>
</applet>*/

A) B) C) D) Answer -

Question) Which of the following statement is used for connectivity with Oracle database?

https://localhost/dashboard/ques_ans_22517.php 111/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) Connection con=DriverManager.getConnection("odbc:oracle:thin:@localhost:1512:xe","system","oracle");
B) Connection
con=DriverManager.getConnection("jdbc:thin:oracle:@localhost:1512:xe","system","oracle"); C)
Connection con=DriverManager.getConnection("odbc:oracle:thin:@localhost:1521:xe","system","oracle");
D) Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
Answer - Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");

Question) Which layout is used to align fixed width components at the edges?

A) java.awt.BorderLayout B) java.awt.FlowLayout C) java.awt.GridLayout D) java.awt.CardLayout


Answer - java.awt.BorderLayout

Question) Which of the following class is used to apply the grid layout?

A) java.awt.BorderLayout B) java.awt.FlowLayout C) java.awt.GridLayout D) java.awt.CardLayout


Answer - java.awt.GridLayout

Question) -------------------- class is used to apply flow layout.

A) java.io.FlowLayout B) java.awt.FlowLayout C) javax.awt.GridLayout D) javax.awt.CardLayout


Answer - java.awt.FlowLayout

Question) Which of the following methods are used to navigate through the different cards in card layout?

A) public void next(Container parent) B) public void previous(Container parent) C) public void
first(Container parent) D) All of the above Answer - All of the above

Question) Which of the following method is used to show the specific card?

A) public void show(Container parent, String name) B) public void show(Container parent) C) public void
first(Container parent, String name) D) public void next(Container parent, String name) Answer -
public void show(Container parent, String name)

Question) We can control the alignment of components in a flow layout arrangement, by using-------------
FlowLayout Fields.

A) FlowLayout.RIGHT B) FlowLayout.LEFT C) FlowLayout.CENTER D) All of the above Answer -


All of the above

Question) Identify the Layout and alignment of components in the given output.

A) FlowLayout and LEFT alignment B) FlowLayout and RIGHT alignment C) GridLayout and LEFT
alignment D) GridLayout and RIGHT alignment Answer - FlowLayout and RIGHT alignment

Question) Consider the following code. Fill the proper method in the blank space to get the count of total
records updated. import java.sql.Statement; public class MyExecuteMethod { public static void main(String
a[] ){ try { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con = DriverManager.
getConnection getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle"); Statement stmt =
con.createStatement(); //The query can be update query or can be select query String query = "select * from
emp"; boolean status = stmt.execute(query); if(status){ ResultSet rs = stmt.getResultSet(); while(rs.next()){
System.out.println(rs.getString(1)); } rs.close(); } else { int count = stmt.-------------------------;
System.out.println("Total records updated: "+count); } } catch (SQLException e) { e.printStackTrace();} } }

https://localhost/dashboard/ques_ans_22517.php 112/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) getUpdateCount(); B) getCount(); C) readCount(); D) readUpdateCount(); Answer -


getUpdateCount();

Question) Identify the layout in the given output.

A) BorderLayout B) GridLayout C) GridBagLayout D) CardLayout Answer - GridLayout

Question) insert() is the method of _____ class.

A) TextArea B) TextField C) Button D) None of above Answer - TextArea

Question) A programmer uses a Java class known as ___________ to connect to a database

A) JDBC driver B) Package C) JDBC Interface D) none of the Above Answer - JDBC driver

Question) Identify the layout in the given output.

A) BorderLayout B) GridLayout C) GridBagLayout D) CardLayout Answer - GridBagLayout

Question) ____________ is a call-level interface.

A) Oracle's Oracle Call Interface (OCI) B) Microsoft's Open Database Connectivity (ODBC) C) JDBC D)
All of the Above Answer - All of the Above

Question) Identify the layout in given output.

A) BorderLayout B) GridLayout C) FlowLayout D) CardLayout Answer - FlowLayout

Question) Because of ________ coupling a 2 tiered application will run ________.

A) loose, faster B) tight, faster C) loose, slower D) tight, slower Answer - tight, faster

Question) Which of the following code is used to retrieve auto generated primary key.

https://localhost/dashboard/ques_ans_22517.php 113/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) public class MyAutoGeneratedKeys { public static void main(String a[]){ try {


Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con = DriverManager. getConnection
getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle"); String query = "insert into emps
(name, dept, salary) values (?,?,?)"; PreparedStatement pstmt =
con.prepareStatement(query,Statement.RETURN_GENERATED_KEYS); pstmt.setString(1, "John");
pstmt.setString(2, "Acc Dept"); pstmt.setInt(3, 10000); pstmt.executeUpdate(); rs =
pstmt.putGeneratedKeys(); if(rs != null && rs.next()){ System.out.println("Generated Emp Id: "+rs.getInt(1));
} } catch (SQLException e) { e.printStackTrace();}}} B) public class MyAutoGeneratedKeys { public static
void main(String a[]){ try { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con =
DriverManager. getConnection getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
String query = "insert into emps (name, dept, salary) values (?,?,?)"; PreparedStatement pstmt =
con.prepareStatement(query,Statement.RETURN_GENERATED_KEYS); pstmt.setString(1, "John");
pstmt.setString(2, "Acc Dept"); pstmt.setInt(3, 10000); pstmt.executeUpdate(); rs =
pstmt.getAutoGeneratedKeys(); if(rs != null && rs.next()){ System.out.println("Generated Emp Id:
"+rs.getInt(1)); } } catch (SQLException e) { e.printStackTrace();}}} C) public class MyAutoGeneratedKeys {
public static void main(String a[]){ try { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con =
DriverManager. getConnection getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
String query = "insert into emps (name, dept, salary) values (?,?,?)"; PreparedStatement pstmt =
con.prepareStatement(query,Statement.RETURN_GENERATED_KEYS); pstmt.setString(1, "John");
pstmt.setString(2, "Acc Dept"); pstmt.setInt(3, 10000); pstmt.executeUpdate(); rs = pstmt.getKeys(); if(rs !=
null && rs.next()){ System.out.println("Generated Emp Id: "+rs.getInt(1)); } } catch (SQLException e) {
e.printStackTrace();}}} D) public class MyAutoGeneratedKeys { public static void main(String a[]){ try {
Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con = DriverManager. getConnection
getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle"); String query = "insert into emps
(name, dept, salary) values (?,?,?)"; PreparedStatement pstmt =
con.prepareStatement(query,Statement.RETURN_GENERATED_KEYS); pstmt.setString(1, "John");
pstmt.setString(2, "Acc Dept"); pstmt.setInt(3, 10000); pstmt.executeUpdate(); rs =
pstmt.getGeneratedKeys(); if(rs != null && rs.next()){ System.out.println("Generated Emp Id: "+rs.getInt(1));
} } catch (SQLException e) { e.printStackTrace();}}} Answer - public class MyAutoGeneratedKeys {
public static void main(String a[]){ try { Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager. getConnection
getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle"); String query = "insert into
emps (name, dept, salary) values (?,?,?)"; PreparedStatement pstmt =
con.prepareStatement(query,Statement.RETURN_GENERATED_KEYS); pstmt.setString(1, "John");
pstmt.setString(2, "Acc Dept"); pstmt.setInt(3, 10000); pstmt.executeUpdate(); rs =
pstmt.getGeneratedKeys(); if(rs != null && rs.next()){ System.out.println("Generated Emp Id:
"+rs.getInt(1)); } } catch (SQLException e) { e.printStackTrace();}}}

Question) Which of the Following is NOT true for Two Tier Architecture

A) The direct communication takes place between client and server. B) There is no intermediate between
client and server. C) A 2 tiered application will run faster. D) In two tier architecture the server can
respond multiple request same time Answer - In two tier architecture the server can respond
multiple request same time

Question) Which of the following methods are used to set the Hgap and Vgap in flow layout?

A) setHgap (int) B) int setVgap (int), int setHgap (int) C) void setHgap (int),void setVgap (int) D) None of
the above Answer - void setHgap (int),void setVgap (int)

Question) A driver is used to ___________ to a particular database.

https://localhost/dashboard/ques_ans_22517.php 114/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) issue sql queries B) open a connection C) load database D) load resultset Answer - open a
connection

Question) ----------------method is used to set the alignment in flow layout.

A) setAlignment (int) B) getAlignment () C) setAlignment () D) getAlignment (int) Answer -


setAlignment (int)

Question) The core API in java.sql consists of ___ interfaces, ___ classes, and 4 exception types.

A) 16, 8 B) 32,8 C) 8, 4 D) 32,4 Answer - 16, 8

Question) By using which interface one can store images in the database in java

A) ResultSet interface B) PreparedStatement interface C) Connection interface D) None of the above


Answer - PreparedStatement interface

Question) The constructors in BorderLayout class are------------

A) BorderLayout() B) BorderLayout(int hgap, int vgap) C) Both a and b D) None of the above
Answer - Both a and b

Question) The core API in java.sql consists of ___ interfaces, 8 classes, and ___ exception types.

A) 8, 4 B) 16, 8 C) 4, 4 D) 16, 4 Answer - 16, 4

Question) The constructors in GridLayout class are-----------

A) GridLayout() B) GridLayout(int rows, int cols) C) GridLayout(int rows, int cols, int hgap, int vgap) D)
All of the above Answer - All of the above

Question) The JDBC interface is contained in the......

A) java.sql Package B) javax.sql Package C) Both of the Above D) None of the Above Answer -
Both of the Above

Question) Which method is used to find out the number of rows in the grid layout?

A) int getRows() B) void getRows() C) void getRows(int) D) None of the above Answer - int
getRows()

Question) The----------method is used to know number of columns in the grid layout.

A) int getColumns() B) void getColumns() C) void getColumns(int) D) None of the above Answer
- int getColumns()

Question) TextArea a2=new TextArea("Advanced is multitasking",5,30); Which method is used to get output
as "Advanced Java is multitasking."

A) insert("Java ",9) B) append("Java",9) C) getRows("Java",10) D) None of these Answer -


insert("Java ",9)

Question) The ------------------ and ----------------- methods are used to set the number of rows and columns in
the grid layout respectively.

https://localhost/dashboard/ques_ans_22517.php 115/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) void setRows(int rows) , void setColumns(int cols) B) void setColumns(int cols) C) void setColumns(int
cols), void setRows(int rows) D) void setRows(int rows) Answer - void setRows(int rows) , void
setColumns(int cols)

Question) Identify the layout in given output

A) BorderLayout B) GridLayout C) FlowLayout D) CardLayout Answer - FlowLayout

Question) Identify the layout in given output

A) BorderLayout B) GridLayout C) FlowLayout D) CardLayout Answer - BorderLayout

Question) Identity the Driver in the Figure

A) Type 1 Driver B) Type 2 Driver C) Type 3 Driver D) Type 4 Driver Answer - Type 1 Driver

Question) To execute a statement ,we invoke method_________

A) executeUpdate() B) executeRel() C) executeStmt() D) exectuteCon() Answer -


executeUpdate()

Question) The -------------------- constructor is used to create FileDialog with specified title.

A) FileDialog(Dialog parent) B) FileDialog(Dialog parent, String title) C) FileDialog(Frame parent) D)


None of the above Answer - FileDialog(Dialog parent, String title)

Question) Identify the Type of Following Driver

A) Type 1 Driver B) Type 2 Driver C) Type 3 Driver D) Type 4 Driver Answer - Type 3 Driver

Question) Identify the JDBC Driver

A) Type 1 Driver B) Type 2 Driver C) Type 3 Driver D) Type 4 Driver Answer - Type 4 Driver

Question) Which of the Following is Type 1 Driver

A) B) C) D) Answer -

Question) Which of the Following is Type 2 Driver

A) B) C) D) Answer -

Question) Identify the Type 3 Driver From the following Figures

A) B) C) D) Answer -

Question) Identify the Type 4 Driver From the following Figures

A) B) C) D) Answer -

https://localhost/dashboard/ques_ans_22517.php 116/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Consider Following Program import java.sql.*; public class JdbcSelectTest { public static void
main(String args[]){ try { --------------------------------------------- Statement stmt = conn.createStatement(); String
strSelect = "select rollno, name, marks from student"; System.out.println("The SQL query is: " + strSelect);
ResultSet rset = stmt.executeQuery(strSelect); System.out.println("The records selected are:"); int
rowCount = 0; while(rset.next()) { String rollno = rset.getString("rollno"); String name =
rset.getString("name"); int marks = rset.getInt("marks"); System.out.println(rollno + ", " + name + ", " +
marks); ++rowCount; } System.out.println("Total number of records = " + rowCount); conn.close(); }
catch(SQLException ex) { ex.printStackTrace(); } } } Chose correct response to fill the blank.

A) Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydata", "root", "root");


B) Connection conn; conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydata", "scott",
"tiger"); C) Connection conn = DriverManager.getConnection("jdbc:mysql://192.168.1.1:3306/mydata",
"root", "root"); D) All of the Above Answer - All of the Above

Question) Consider following Program import java.sql.*; public class JdbcSelectTest { public static void
main(String args[]){ try { Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/mydata", "root", "root"); Statement stmt =
conn.createStatement(); String strSelect = "select rollno, name, marks from student";
System.out.println("The SQL query is: " + strSelect); ResultSet rset = stmt.executeQuery(strSelect);
System.out.println("The records selected are:"); int rowCount = 0; while(rset.next()) { String rollno =
_____________________; String name = rset.getString("name"); int marks = _____________________;
System.out.println(rollno + ", " + name + ", " + marks); ++rowCount; } System.out.println("Total number of
records = " + rowCount); conn.close(); } catch(SQLException ex) { ex.printStackTrace(); } } } Choose Correct
Option to replace Blank

A) rs.getInt( B) rset.getString(1); & rset.getInt(3); C) stmt.getString( D) Both A and B Answer -


rset.getString(1); & rset.getInt(3);

Question) Fill in the blanks to insert values in Student(rollno,name,marks,contact) table. import java.sql.*;
public class SampleInsert { public static void main(String args[])throws Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c
=DriverManager.getConnection("jdbc:odbc:DSN2","",""); PreparedStatement
s=c.prepareStatement("______" ); int n=s. .executeUpdate(); Statement
st=con.createStatement();ResultSet rs=st.executeQuery("select * from student");
System.out.println("Name"+" "+"Roll no"+" "+"Avg"); while(rs.next()) { System.out.println(rs.getInt(1)+"
"+rs.getString(2)+" "+rs.getDouble(3) +" "+rs.getInt(4)); } s.close(); c.close(); } }

A) Insert into student values(?,?,?) B) Insert into table student (?,?,?,?) C) Insert into table student
values(?,?,?) D) Insert into student values(?,?,?,?) Answer - Insert into student values(?,?,?,?)

Question) The ----------- method is used to move to the first card in card layout.

A) public void previous(Container parent) B) public void first(Container parent) C) public void
next(Container parent) D) All of the above Answer - public void first(Container parent)

https://localhost/dashboard/ques_ans_22517.php 117/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Predict the output of Following program import java.sql.*; public class JdbcSelectTest { public
static void main(String args[]){ try { Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/mydata", "root", "root"); Statement stmt =
conn.createStatement(); String strSelect = "select rollno, name, marks from student";
System.out.println("The SQL query is: " + strSelect); ResultSet rset = stmt.executeQuery(strSelect);
System.out.println("The records selected are:"); int rowCount = 0; while(rset.first()) { String rollno =
rset.getString("rollno"); String name = rset.getString("name"); int marks = rset.getInt("marks");
System.out.println(rollno + ", " + name + ", " + marks); ++rowCount; } System.out.println("Total number of
records = " + rowCount); conn.close(); } catch(SQLException ex) { ex.printStackTrace(); } } }

A) print all the columns of student table B) print roll no, name and marks from student table C) print roll
no, name and marks of first student from student table D) None of the Above Answer - print roll
no, name and marks of first student from student table

Question) Which method is used to know the mode of the FileDialog.?

A) int getMode() B) void getMode() C) int getMode(int) D) void getMode(int) Answer - int
getMode()

Question) The ----------------- method is used to set the mode of the FileDialog.

A) void setMode(int mode) B) int setMode(int mode) C) void setMode() D) int setMode() Answer -
void setMode(int mode)

Question) Consider Following Program import java.sql.*; public class JdbcSelectTest { public static void
main(String args[]){ try { Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/mydata", "root", "root"); Statement stmt =
conn.createStatement(); String strSelect = "select rollno, name, marks from student";
System.out.println("The SQL query is: " + strSelect); ResultSet rset = stmt.executeQuery(strSelect);
System.out.println("The records selected are:"); int rowCount = 0; while(rset.next()) { String rollno =
rset.getString("rollno"); String name = rset.getString("name"); _____ marks = _______________;
System.out.println(rollno + ", " + name + ", " + marks); ++rowCount; } System.out.println("Total number of
records = " + rowCount); conn.close(); } catch(SQLException ex) { ex.printStackTrace(); } } } Choose Correct
Option to replace Blank.

A) int, rset.getInt B) String, a.getString C) Both of the Above D) None of the Above Answer - int,
rset.getInt

Question) Predict the Output of following program import java.sql.*; public class JdbcSelectTest { public
static void main(String args[]){ try { Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/mydata", "root", "root"); Statement stmt =
conn.createStatement(); String strSelect = "select rollno, name, marks from student";
System.out.println("The SQL query is: " + strSelect); ResultSet rset = stmt.executeQuery(strSelect);
System.out.println("The records selected are:"); int rowCount = 0; while(rset.last()) { String rollno =
rset.getString("rollno"); String name = rset.getString("name"); int marks = rset.getInt("marks");
System.out.println(rollno + ", " + name + ", " + marks); ++rowCount; } System.out.println("Total number of
records = " + rowCount); conn.close(); } catch(SQLException ex) { ex.printStackTrace(); } } }

A) print all the columns of student table B) print roll no, name and marks from student table C) print roll
no, name and marks of last student from student table D) generate sql Exception Answer - print
roll no, name and marks of last student from student table

https://localhost/dashboard/ques_ans_22517.php 118/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) _____class implements a single line text-entry area.

A) Button B) TextField C) Checkbox D) TextArea Answer - TextField

Question) Return type for method next(), first() and last() method of resultset is ______________

A) int B) String C) boolean D) ResultSet Object Answer - boolean

Question) Identify Correct Syntax for following method of ResulSet ______ absolute (______);

A) boolean, int B) boolean, void C) void, int D) void, void Answer - boolean, int

Question) Identify Correct Syntax for following method of ResulSet ______ first (______);

A) boolean, int B) boolean, void C) void, int D) void, void Answer - boolean, void

Question) Which is the correct syntax of next() method of ResultSet() interface ?

A) boolean next() B) void next() C) void first() D) void new() Answer - boolean next()

Question) Which driver provides JDBC access via one or more ODBC drivers

A) Type 1 driver B) Type 2 driver C) Type 3 driver D) Type 4 driver Answer - Type 1 driver

Question) Which type of driver is called partly java driver?

A) Type 1 driver B) Type 2 driver C) Type 3 driver D) Type 4 driver Answer - Type 2 driver

Question) __________ method of ResultSet object is called to retrieve Binary large Object from database.

A) getBigDecimal B) getBlob C) getBinaryStream D) getASCIIStream Answer - getBlob

Question) What should be enter at the blank space? import java.sql.*; class PreparedUpdate { public static
void main(String a[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection
con=DriverManager.getConnection("jdbc:odbc:javadb"); Statement st=con.createStatement(); String stm =
"update employee set name=? where name=?"; PreparedStatement ps = con.________________(stm);
ps.setString(1,"Ram"); ps.setString(2,"Ramesh"); ps.executeUpdate(stm); ResultSet rs =
st.executeQuery("select * from employee"); while(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"); } } }

A) PreparedStatement B) ParameterizedStatement C) prepareStatement D) None of the above


Answer - prepareStatement

https://localhost/dashboard/ques_ans_22517.php 119/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Which statement should be missing in the following program? 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.setInt(1,5); ps.setString(2,"sahil"); ps.setInt(3,5000); ps.execute(a1);
System.out.println("Record Inserted"); String querySel = "Select * from employee"; ResultSet rs =
ps.executeQuery(querySel); System.out.println("After Insertion"); while(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"); } } }

A) Missing semicolon B) Missing { C) Missing } D) Missing package statement. Answer - Missing


package statement.

Question) Which AWT components are used to produce given output ?

A) Button,TextArea,Choice B) List,TextArea,Label,Button C) Label,TextField,Choice,CheckboxGroup D)


List,Label,TextField,Button Answer - Label,TextField,Choice,CheckboxGroup

Question) Return type of execute() method is _______

A) boolean B) int C) ResultSet D) None of the Above Answer - boolean

Question) What should be added at the blank spaces? import java.sql.*; class ConnectDB { public static
void main(String a[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Driver
Loaded"); String url="jdbc:odbc:javadb"; __________________con=DriverManager.getConnection(url);
System.out.println(" Connection to DataBase created"); } catch(SQLException e) { System.out.println("
Error"+e); } catch(Exception e) { System.out.println(" Error"+e); } } }

A) DriverManager B) Connection C) Statement D) None of the above Answer - Connection

Question) import java.awt.*; import java.applet.*; public class checkboxDemo extends Applet /* <applet
code="checkbox" width=300 height=300></applet>*/ { public void init() { Checkbox cb1,cb2; ---------------------
--------------- cb1=new Checkbox("Java",true); cb2=new Checkbox("C++",true,cbg); add(cb1);add(cb2); } } Fill
in the blanks with correct statement.

A) CheckboxGroup cbg=new CheckboxGroup(); B) CheckboxGroup cbg=new CheckboxGroup(true); C)


CheckboxGroup cbg=new CheckboxGroup("Male",true); D) None of the above Answer -
CheckboxGroup cbg=new CheckboxGroup();

Question) _____________ interface defines methods that enable user to send SQL queries and receive
data from the database.

A) Statement B) Connection C) DriverManager D) None of the above Answer - Statement

Question) Which method moves record cursor to the next row of result set?

A) beforeFirst() B) afterLast() C) first() D) next() Answer - next()

Question) _____________object is used for precompiled SQL statements.

A) PreparedStatement B) ParameterizedStatement C) prepareStatement D) None of the above


Answer - PreparedStatement

https://localhost/dashboard/ques_ans_22517.php 120/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Identify Problem in the following code import java.sql.*; public class JdbcSelectTest { public static
void main(String args[]){ Connection conn =
DriverManager.getConnection("jdbc:mysql://192.168.1.1:3306/mydata", "root", "root"); Statement stmt =
conn.createStatement(); String strSelect = "select rollno, name, marks from student";
System.out.println("The SQL query is: " + strSelect); ResultSet rset = stmt.executeQuery(strSelect);
System.out.println("The records selected are:"); int rowCount = 0; while(rset.next()) { String rollno =
rset.getString("rollno"); String name = rset.getString("name"); int marks = rset.getInt("marks");
System.out.println(rollno + ", " + name + ", " + marks); ++rowCount; } System.out.println("Total number of
records = " + rowCount); } }

A) Try catch not used B) ResultSet object not created C) wrong getConnection() method syntax D) Both
A&B Answer - Try catch not used

Question) __________package contains the various interfaces and classes used by the JDBC API.

A) java.sql B) java.io C) java.net D) java.lang Answer - java.sql

Question) windowDeactivated() is method of ________interface

A) WindowListener Interface B) Window Interface C) WindowConified Interface D) Action Interface


Answer - WindowListener Interface

Question) windowOpened() is method of ________interface

A) WindowListener Interface B) Window Interface C) Window Conified Interface D) Action Interface


Answer - WindowListener Interface

Question) mouseClicked() is method of _________interface.

A) Mouse Interface B) MouseMotionListener Interface C) MouseClick Interface D) MouseListener


Interface Answer - MouseListener Interface

Question) mouseEntered() is method of _________interface .

A) Mouse Interface B) MouseMotionListener Interface C) MouseEntered Interface D) MouseListener


Interface Answer - MouseListener Interface

Question) mouseExited() is method of _________interface.

A) Mouse Interface B) MouseMotionListener Interface C) MouseExited Interface D) MouseListener


Interface Answer - MouseListener Interface

Question) mousePressed() is method of _________interface.

A) Mouse Interface B) MouseMotionListener Interface C) MousePressed Interface D) MouseListener


Interface Answer - MouseListener Interface

Question) mouseReleased() is method of _________interface.

A) Mouse Interface B) MouseMotionListener Interface C) MouseReleased Interface D) MouseListener


Interface Answer - MouseListener Interface

https://localhost/dashboard/ques_ans_22517.php 121/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Which of the following statements are true? 1) The MouseMotionListener interface defines
methods for handling mouse clicks. 2) The ActionListener interface defines methods for handling the
clicking of a button. 3) The MouseClickListener interface defines methods for handling mouse clicks. 4) The
MouseListener interface defines methods for handling mouse dragged

A) Statement 1 and 3 are true B) Only first statement is true C) Only second statement is true D) All
statements are true Answer - Only second statement is true

Question) Which of the following statements is true? 1) keyPressed() is method of KeyListerner Interface 2)
keyPressed() is method of MouseListener Interface 3) keyPressed() is method of ActionListener Interface 4)
keyPressed() is method of KeyBoardListener Interface

A) Statement 1 is true B) Statement 2 is true C) Statement 3 is true D) Statement 4 is true


Answer - Statement 1 is true

Question) Which package is required for events?

A) java.listener B) java.util.event C) java.awt.event D) java.motion Answer - java.awt.event

Question) The Following steps are required to perform 1) Implement the Listener interface and overrides its
methods 2) Register the component with the Listener

A) Exception Handling B) String Handling C) Event Handling D) Listener Handling Answer -


Event Handling

Question) Consider following three statement 1) ActionListener Interace defines one method to receive
action event 2) ItemListener Interface defines one method to recognize when the state of item change.. 3)
MouseListener interface defines mouseMoved() method

A) Statement 1 and 2 are true B) Only first statement is true C) Only second statement is true D) All
statements are true Answer - Statement 1 and 2 are true

Question) Which of the following statements are false 1)windowlistener define seven method
2)mouseMotionListerne define 2 method 3) ActionListener Interace defines three method to receive action
event 4)KeyListener Interface define Three method

A) Statement 1 is false B) Statement 2 is false C) Statement 3 is false D) Statement 4 is false


Answer - Statement 3 is false

Question) Consider following two statement 1) Implement the Listener interface and overrides its methods is
required to perform in event handling. 2) ActionListener Interace defines one method to receive action event

A) Only first statement is true B) Only second statement is true C) Both statements are true D) Both
statements are False Answer - Both statements are true

Question) Which of the following method of a Frame is used to change it's color?

A) setBackground(Color c ) B) setForeground( Color c ) C) add() D) getBackground() Answer -


setBackground(Color c )

Question) ContentHandler , MulticastSocket , URL, SocketImpl are examples of --------

A) package B) class C) Interface D) Method Answer - class

https://localhost/dashboard/ques_ans_22517.php 122/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) URLEncoder , URLConnection , URLDecoder are examples of --------

A) package B) class C) Interface D) All of the above Answer - class

Question) The WindowEvent class, WINDOW_ICONIFIED, integer constants meaning-

A) Showing a window for the first time. B) The window which contains the focus owner. C) Reducing the
window from to minimized. D) Restoring the window to its original size. Answer - Reducing the
window from to minimized.

Question) ItemEvent constructor- ItemEvent(ItemSelectable src, int type, Object entry, int state) Here src
means......

A) The specific item that generated the item event is passed B) The type of object C) a reference to the
component that generated event D) The current state of that item. Answer - a reference to the
component that generated event

Question) The WindowEvent class, WINDOW_DEICONIFIED, integer constants meaning-

A) Reducing the window to an icon on the desktop B) The window which contains the focus owner. C)
Showing a window for the first time. D) Restoring the window to its original size. Answer -
Restoring the window to its original size.

Question) Choose the incorrect statement ?

A) List l=new List(4); B) List l1=new List(6,true); C) Choice c=new Choice(); D) Choice c1=new
Choice(3); Answer - Choice c1=new Choice(3);

Question) What does URL stands for?

A) Uniform Resource Locator B) Uniform Resource Latch C) Universal Resource Locator D) Universal
Resource Latch Answer - Uniform Resource Locator

Question) The WindowEvent class, WINDOW_DEACTIVATED, integer constants meaning-

A) Reducing the window to an icon on the desktop B) The window which contains the focus owner. C)
This window has lost the focus D) Restoring the window to its original size. Answer - This window
has lost the focus

Question) Which of the following are true? A. The event-inheritance model has replaced the event-
delegation model. B. The event-inheritance model is more efficient than the event-delegation model. C. The
event-delegation model uses event listeners to define the methods of event-handling classes. D. The event-
delegation model uses the handleEvent( ) method to support event handling.

A) Statement 1 is true B) Statement 2 is true C) Statement 3 is true D) Statement 4 is true


Answer - Statement 3 is true

Question) WindowEvent is a subclass of __________________.

A) ComponentEvent B) TextEvent C) InputEvent D) Window Answer - ComponentEvent

Question) Which of these exceptions is thrown by URL classes constructors?

https://localhost/dashboard/ques_ans_22517.php 123/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) URLNotFound B) URLSourceNotFound C) MalformedURLException D) URLNotFoundException


Answer - MalformedURLException

Question) Which of these methods is used to know host of an URL?

A) host() B) getHost() C) GetHost() D) gethost() Answer - getHost()

Question) WindowEvent Constructor- WindowEvent(Window src, int type, Window other, int fromState, int
toState) Here fromState means-

A) the new state of the window B) prior state of the window. C) opposite window when a focus or
activation event occurs. D) reference to the object that generated this event. Answer - prior state
of the window.

Question) Which of the following components generate action events?

A) Button B) Labels C) Check boxes D) Windows Answer - Button

Question) getWindow ( ) method returns

A) int value of window B) Location of window C) void value D) Window object Answer - Window
object

Question) Which of the following are true? A) The MouseListener interface defines methods for handling
mouse clicks. B) The MouseMotionListener interface defines methods for handling mouse clicks. C) The
MouseClickListener interface defines methods for handling mouse clicks. D) The ActionListener interface
defines methods for handling the clicking of a button.

A) Only Statement A is true B) Only Statement D is true C) Statement A and D are true D) Statement B
and D are true Answer - Statement A and D are true

Question) WindowEvent class methods are-

A) getOppositeWindow() B) getNewState() C) getOldState() D) All of above Answer - All of


above

Question) Which of these class is used to access actual bits or content information of a URL?

A) URL B) URLDecoder C) URLConnection D) All of the mentioned Answer - All of the


mentioned

Question) What is the output of this program? import java.net.*; class networking { public static void
main(String[] args) throws MalformedURLException { URL obj = new
URL("https://www.sanfoundry.com/javamcq"); System.out.print(obj.getProtocol()); } }

A) http B) https C) www D) com Answer - https

Question) Which of these methods is used to know the full URL of an URL object?

A) fullHost() B) getHost() C) ExternalForm() D) toExternalForm() Answer - toExternalForm()

https://localhost/dashboard/ques_ans_22517.php 124/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Match the correct pairs- a. getKeyLocation() i. Set the keyCode value to indicate a physical key.
b. getKeyCode() ii. Returns the character associated with the key in this event. c. getKeyChar() iii. Returns
the location of the key that originated this key event. d. setKeyCode(int keyCode) iv. Returns the integer
keyCode associated with the key in this event.

A) d-i, c-ii, a-iii, b-iv B) d-ii, c-i, a-iii, b-iv C) d-i, c-ii, a-iv, b-iii D) d-iv, c-ii, a-iii, b-i Answer - d-i, c-ii,
a-iii, b-iv

Question) Which of the following statements is true?

A) keyTyped() is method of KeyListerner Interface B) keyTyped() is method of MouseListener Interface C)


keyTyped() is method of ActionListener Interface D) keyTyped() is method of KeyBoardListener Interface
Answer - keyTyped() is method of KeyListerner Interface

Question) .ContentHandlerFactory , SocketOptions , FileNameMap are included in --------package

A) .net B) .util C) . io D) .lang Answer - .net

Question) .com,.gov,.org are examples of--------

A) domain B) server name C) client name D) package Answer - domain

Question) Which of the following option is true?

A) keyReleased() is method of KeyListerner Interface B) keyReleased() is method of MouseListener


Interface C) keyReleased() is method of ActionListener Interface D) keyReleased() is method of
KeyBoardListener Interface Answer - keyReleased() is method of KeyListerner Interface

Question) Consider following code segment- 1. public void keyReleased(getKeyChar( ) ) { 2. str+=" -Key
Released- "; 3. label2.setText(str); 4. jf.setVisible(true); 5. str=""; 6.} 7. public void keyTyped(KeyEvent ke) {
8. str+=" -Key Typed- "; 9. label2.setText(str); 10. jf.setVisible(true); 11. } Which statement is true ?

A) There are syntax errors on line no. 1 B) There are syntax errors on line no. 3 C) There are syntax
errors on line no. 7 D) There are syntax errors on line no. 10 Answer - There are syntax errors on
line no. 1

Question) Select true statement from the following options.

A) mousePressed() is method of MouseMotionListener Interface B) mousePressed() is method of Mouse


Interface C) mousePressed() is method of MousePressed Interface D) mousePressed() is method of
MouseListener Interface Answer - mousePressed() is method of MouseListener Interface

Question) Select correct general form of Mouse Clicked method of Mouse Listener interface.

A) void mouseClicked(mouseEvent me) B) void MouseClicked(mouseEvent me) C) void


MouseClicked(MouseEvent me) D) void mouseClicked(MouseEvent me) Answer - void
mouseClicked(MouseEvent me)

Question) public void removeTypeListener(TypeListener el) Here Type means-

A) reference to the event listener B) name of the event C) type of multicasting of event D) None of the
above Answer - name of the event

Question) Which of these methods is used to know when was the URL last modified?

https://localhost/dashboard/ques_ans_22517.php 125/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) LastModified() B) getLastModified() C) GetLastModified() D) getlastModified()() Answer -


getLastModified()

Question) Which of these methods is used to know the type of content used in the URL?

A) ContentType() B) contentType() C) getContentType() D) GetContentType() Answer -


getContentType()

Question) What is the output of this program? import java.net.*; class networking { public static void
main(String[] args) throws Exception { URL obj = new URL("https://www.sanfoundry.com/javamcq");
URLConnection obj1 = obj.openConnection(); System.out.print(obj1.getContentType()); } }

A) html B) text C) html/text D) text/html Answer - text/html

Question) What is the output of this program? import java.net.*; class networking { public static void
main(String[] args) throws Exception { URL obj = new URL("https://www.sanfoundry.com/javamcq");
URLConnection obj1 = obj.openConnection(); int len = obj1.getContentLength(); System.out.print(len); } }

A) 127 B) -1 C) Compilation Error D) Runtime Error Answer - -1

Question) Select correct general form of Mouse Entered method of Mouse Listener interface.

A) void mouseEntered(mouseEvent me) B) void MouseEntered(mouseEvent me) C) void


MouseEntered(MouseEvent me) D) void mouseEntered(MouseEvent me) Answer - void
mouseEntered(MouseEvent me)

Question) Consider following code segment- 1. public void mouseClicked(MouseEvent event){ 2.


setBackground(Color.blue); 3.int x = event.getX(); 4.int y = event.getY(); 5.int c = getClickCount( ); 6. }
Which statement is true?

A) There are syntax errors on line no. 1 B) There are syntax errors on line no. 2 C) There are syntax
errors on line no . 4 D) There are syntax errors on line no. 5 Answer - There are syntax errors on
line no. 5

Question) Consider following code segment- 1. public void mouseClicked(MouseEvent event){ 2. boolean d
= event.isPopupTrigger( ); 3. } In above code segment Line no. 2 specifies:

A) tests if this event causes a pop-up menu to appear on this platform. B) tests if this event response pop-
up menu to appear on this platform. C) tests if this event is pop-up window. D) tests if this event is pop-
up Trigger. Answer - tests if this event causes a pop-up menu to appear on this platform.

Question) Find the Error in given code for implementing Mouse motion event handler import java.awt.*;
import java.awt.event.*; public class MouseEventsDemo extends Frame implements KeyListener { String
msg="" int mouseX=0, mouseY=0; public MouseEventsDemo() { addMouseMotionListener(this);
addWindowListener(new MyWindowAdapter()); } public void mouseDragged(MouseEvent me) {
mouseX=me.getX(); mouseY=me.getY(); msg= "* " + "mouse at " + mouseX + " , " + mouseY; repaint(); }
public void mouseMoved(MouseEvent me) { msg="Moving mouse at " + me.getX() + " , " + me.getY();
repaint(); } public void paint(Graphics g) { g.drawString(msg, mouseX, mouseY); } public static void
main(String [] args) { MouseEventsDemo M1= new MouseEventsDemo(); M1.setSize(new
Dimension(300,300)); M1.setTitle("MouseEventsDemo"); M1.setVisible(true); } } class MyWindowAdapter
extends WindowAdapter { Public void windowClosing(WindowEvent we) { System.exit(0); } }

https://localhost/dashboard/ques_ans_22517.php 126/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) Error in registering Listener B) All methods of Interface are not implemented C) Implements Wrong
name of interface class D) Required packages are not implemented. Answer - Implements Wrong
name of interface class

Question) Consider following code segment- public void mousePressed(MouseEvent event) {


System.out.println(event.getPoint()); } Following code segement output is-

A) Print value of x and y co-ordinates B) Print value of x co-ordinates C) Print value of y co-ordinates D)
Print value of event object. Answer - Print value of x and y co-ordinates

Question) Find the Error in given code for implementing Mouse motion event handler import java.awt.*;
import java.awt.event.*; public class MouseEventsDemo extends Frame implements MouseMotionListener {
String msg=" " int mouseX=0, mouseY=0; public MouseEventsDemo() { addMouseMotionListener(this);
addWindowListener(new MyWindowAdapter()); } public void mouseMoved(MouseEvent me) { msg="Moving
mouse at " + me.getX() + " , " + me.getY(); repaint(); } public void paint(Graphics g) { g.drawString(msg,
mouseX, mouseY); } public static void main(String [] args) { MouseEventsDemo M1= new
MouseEventsDemo(); M1.setSize(new Dimension(300,300)); M1.setTitle("MouseEventsDemo");
M1.setVisible(true); } } class MyWindowAdapter extends WindowAdapter { Public void
windowClosing(WindowEvent we) { System.exit(0); } }

A) Error in registering Listener B) All methods of Interface are not implemented C) Correct Interface class
not implemented D) Required packages are not implemented. Answer - All methods of Interface
are not implemented

Question) Find the Error in given code for implementing Mouse motion event handler import java.awt.*;
import java.awt.event.*; public class MouseEventsDemo extends Frame implements MouseMotionListener {
String msg="" int mouseX=0, mouseY=0; public MouseEventsDemo() { addWindowListener(new
MyWindowAdapter()); } public void mouseDragged(MouseEvent me) { mouseX=me.getX();
mouseY=me.getY(); msg= "* " + "mouse at " + mouseX + " , "+ mouseY; repaint(); } public void
mouseMoved(MouseEvent me) { msg="Moving mouse at " + me.getX() + " , "+ me.getY(); repaint(); } public
void paint(Graphics g) { g.drawString(msg, mouseX, mouseY); } public static void main(String [] args) {
MouseEventsDemo M1= new MouseEventsDemo(); M1.setSize(new Dimension(300,300));
M1.setTitle("MouseEventsDemo"); M1.setVisible(true); } } class MyWindowAdapter extends WindowAdapter
{ Public void windowClosing(WindowEvent we) { System.exit(0); } }

A) Listener not registered B) All methods of Interface are not implemented C) Correct Interface class not
implemented D) Required packages are not implemented. Answer - Listener not registered

Question) Consider following code segment- 1. public void mouseClicked(MouseEvent event) { 2. // Line 2
3. } Following code segment, identify statement to print co-ordinates -

A) int p = getLocationOnScreen( ); B) Point p = getLocationOnScreen( ); C) int x,y =


getLocationOnScreen( ); D) None of above Answer - Point p = getLocationOnScreen( );

https://localhost/dashboard/ques_ans_22517.php 127/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Find the Error in given code for implementing Mouse motion event handler import java.lang*;
import java.util.event.*; public class MouseEventsDemo extends Frame implements MouseMotionListener {
String msg="" int mouseX=0, mouseY=0; public MouseEventsDemo() { addMouseMotionListener(this);
addWindowListener(new MyWindowAdapter()); } public void mouseDragged(MouseEvent me) {
mouseX=me.getX(); mouseY=me.getY(); msg= "*" + "mouse at " + mouseX + " , " + mouseY; repaint(); }
public void mouseMoved(MouseEvent me) { msg="Moving mouse at " + me.getX() + ", " + me.getY();
repaint(); } public void paint(Graphics g) { g.drawString(msg, mouseX, mouseY); } public static void
main(String [] args) { MouseEventsDemo M1= new MouseEventsDemo(); M1.setSize(new
Dimension(300,300)); M1.setTitle("MouseEventsDemo"); M1.setVisible(true); } } class MyWindowAdapter
extends WindowAdapter { Public void windowClosing(WindowEvent we) { System.exit(0); } }

A) Listener not registered B) All methods of Interface are not implemented C) Correct Interface class not
implemented D) Required packages are not imported Answer - Required packages are not
imported

Question) Which constructor is used to set the grid layout with vertical gap and horizontal gap?

A) GridLayout() B) GridLayout(int rw, int cl) C) GridLayout(int rw, int cl, int hgap, vgap) D) All of the
above Answer - GridLayout(int rw, int cl, int hgap, vgap)

Question) Write the correct code at blank spaces: import java.awt.*; import java.awt.event.*; public class
MouseMotionListenerExample extends Frame implements MouseMotionListener {
MouseMotionListenerExample() { addMouseMotionListener(this); setSize(300,300); setLayout(null);
setVisible(true); } public void ___________(MouseEvent e) { Graphics g=getGraphics();
g.setColor(Color.RED); g.drawOval(e.getX(),e.getY(),20,20); } public void _____________(MouseEvent e)
{} public static void main(String[] args) { new MouseMotionListenerExample(); } }

A) mouseDragged, mouseMoved B) mousePressed,mouseDragged C) mouseClicked,mouseMoved D)


mouseReleased,mouseClicked Answer - mouseDragged, mouseMoved

Question) Find error in given program 1. import java.awt.*; 2. import java.awt.event.*; 3. public class
KeyListenerExample extends Frame implements KeyListener{ Label MyLAbel; 4. TextArea area; 5.
KeyListenerExample(){ 6. MyLabel=new Label(); 7. MyLabel.setBounds(20,50,100,20); 8. area=new
TextArea(); 9. area.setBounds(20,80,300, 300); 10. add(MyLabel);add(area); 11. setSize(400,400); 12.
setLayout(null); 13. setVisible(true); 14. } 15. public void keyPressed(KeyEvent e) { 16.
MyLabel.setText("Key Pressed"); 17. } 18. public void keyReleased(KeyEvent e) { 19. MyLabel.setText("Key
Released"); 20. } 21. public void keyTyped(KeyEvent e) { 22. MyLabel.setText("Key Typed"); 23. } 24. public
static void main(String[] args) { 25. new KeyListenerExample(); 26. } 27. }

A) Listener not registered B) All methods of Interface are not implemented C) Wrong name of Interface
class D) Required packages are not imported Answer - Listener not registered

Question) The ______________ method changes the location of the event.

A) int getX( ) B) Point getPoint( ) C) translatePoint( ) D) isPopupTrigger( ) Answer -


translatePoint( )

https://localhost/dashboard/ques_ans_22517.php 128/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Find error in given program 1 import java.awt.*; 2 import java.awt.event.*; 3 public class
KeyListenerExample extends Frame implements KeyListener{Label MyLAbel; 4 TextArea area; 5
KeyListenerExample(){ 6 MyLabel=new Label(); 7 MyLabel.setBounds(20,50,100,20); 8 area=new
TextArea(); 9 area.setBounds(20,80,300, 300); 10 area.addKeyListener(this); 11 add(MyLabel);add(area);
12 setSize(400,400); 13 setLayout(null); 14 setVisible(true); 15 } 16 public void keyPressed(KeyEvent e) {
17 MyLabel.setText("Key Pressed"); 18 } 19 public void keyReleased(KeyEvent e) { 20
MyLabel.setText("Key Released"); 21 } 22 public static void main(String[] args) { 23 new
KeyListenerExample(); 24 } 25 }

A) Listener not registered B) All methods of Interface are not implemented C) Wrong name of Interface
class D) Required packages are not imported Answer - All methods of Interface are not
implemented

Question) Find error in given program import java.awt.*; import java.awt.event.*; public class
KeyListenerExample extends Frame implements KeyBoardListener { Label MyLAbel; TextArea area;
KeyListenerExample() { MyLabel=new Label(); MyLabel.setBounds(20,50,100,20); area=new TextArea();
area.setBounds(20,80,300, 300); area.addKeyListener(this); add(MyLabel);add(area); setSize(400,400);
setLayout(null); setVisible(true); } public void keyPressed(KeyEvent e) { MyLabel.setText("Key Pressed"); }
public void keyReleased(KeyEvent e) { MyLabel.setText("Key Released"); } public void keyTyped(KeyEvent
e) { l.setText("Key Typed"); } public static void main(String[] args) { new KeyListenerExample(); } }

A) Listener not registered B) All methods of Interface are not implemented C) Implements Wrong name of
Interface class D) Required packages are not imported Answer - Implements Wrong name of
Interface class

Question) ContentHandler , MulticastSocket , URL, SocketImpl are included in --------package

A) .net B) .util C) . io D) .lang Answer - .net

Question) HttpURLConnection , URLConnection , URL are included in --------package

A) .net B) .util C) . io D) .lang Answer - .net

Question) Find error in given program import java.util.*; import java.util.event.*; public class
KeyListenerExample extends Frame implements KeyListener{ Label MyLAbel; TextArea area;
KeyListenerExample() { MyLabel=new Label(); MyLabel.setBounds(20,50,100,20); area=new TextArea();
area.setBounds(20,80,300, 300); area.addKeyListener(this); add(MyLabel);add(area); setSize(400,400);
setLayout(null); setVisible(true); } public void keyPressed(KeyEvent e) { MyLabel.setText("Key Pressed"); }
public void keyReleased(KeyEvent e) { MyLabel.setText("Key Released"); } public void keyTyped(KeyEvent
e) { l.setText("Key Typed"); } public static void main(String[] args) { new KeyListenerExample(); } }

A) Listener not registered B) All methods of Interface are not implemented C) Wrong name of Interface
class D) Required packages are not imported Answer - Required packages are not imported

Question) Consider following code segment- 1. public void textValueChanged(TextEvent e) { 2.


TextComponent tc = (TextComponent) e.getSource(); 3. // Line No. 3 4. } Above segment of code, identify
code a Line No 3 to display text in TextComponent-

A) System.out.println("Typed value in TextComponent "+tc.getText()); B) System.out.println("Typed value in


TextComponent "+tc.paramString()); C) System.out.println("Typed value in TextComponent
"+tc.getSource()); D) System.out.println("Typed value in TextComponent "+tc.getValue()); Answer -
System.out.println("Typed value in TextComponent "+tc.getText());

https://localhost/dashboard/ques_ans_22517.php 129/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Consider following code segment- 1. t=new TextField(20); 2. public void


textValueChanged(TextEvent te) { 3. // Line No. 3 4. } Above segment of code, identify the code at Line No 3
to set the frame title.

A) setTitle(t.getValue()); B) setTitle(te.getText()); C) setTitle(te.getValue()); D) setTitle(t.getText());


Answer - setTitle(t.getText());

Question) Consider following code segment- 1. TextArea typeText, displayText; 2. public void
textValueChanged(TextEvent e) { 3.String str=typeText.getText(); 4.// Line No. 4 5.} Following segment of
code, identify code a Line No 4 to read text from typeText and display to displayText

A) displayText.setText(e.str); B) displayText.setText(e.getText()); C) displayText.setText(str); D)


displayText.setText(e.typeText); Answer - displayText.setText(str);

Question) Fill the blank at line no 5. 1. public class WindowExample extends Frame implements
WindowListener 2. { 3. WindowExample() 4. { 5. _______________ (this); 6. setSize(400,400); 7.
setLayout(null); 8. setVisible(true); 9. }

A) addWindowListener B) addwindow C) WindowListener() D) addwindowlistener Answer -


addWindowListener

Question) -------------------- layout lays out the components in a directional flow.

A) Grid Layout B) Card Layout C) FlowLayout D) BorderLayout Answer - FlowLayout

Question) Identify the incorrect Integer constants for WindowEvent.

A) WINDOW_ACTIVATED B) WINDOW_DEACTIVATED C) WINDOW_LOST_FOCUS D)


WINDOW_GOT_FOCUS Answer - WINDOW_GOT_FOCUS

Question) Write the correct code at blank space: public class ____________ extends Frame implements
WindowListener { WindowExample() { addWindowListener(this); setSize(400,400); setLayout(null);
setVisible(true); } public static void main(String[] args) { new WindowExample(); }

A) addWindowListener B) WindowExample C) Window D) WindowListener Answer -


WindowExample

Question) Which top-level class provides methods to add and remove keyboard and mouse event listeners-

A) Object B) ActionEvent C) EventObject D) Component Answer - Component

Question) The getActionCommand( ) method returns-

A) String B) Object C) int D) void Answer - String

Question) --------------------- class displays a dialog window from which the user can select a file.

A) java.awt.FileDialog B) java.awt.Dialog C) java.awt.File D) All of the above Answer -


java.awt.FileDialog

Question) The getItem( ) method returns-

A) String B) Object C) void D) int Answer - Object

https://localhost/dashboard/ques_ans_22517.php 130/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) Which method used to capture ALT, CTRL, META OR SHIFT keys-

A) getWhen( ) B) getActionCommand( ) C) getModifiers( ) D) getAdjustable( ) Answer -


getModifiers( )

Question) 1.public void textValueChanged(TextEvent e) { 2.TextComponent tc


= (TextComponent) e.getSource(); 3.System.out.println("Typed value in TextComponent " + e.getText()); 4. }
Following segment of code, Identify syntax error-

A) There are syntax errors on line no. 1 B) There are syntax errors on line no. 2 C) There are syntax
errors on line no. 3 D) There are syntax errors on line no. 2 and 3 Answer - There are syntax
errors on line no. 3

Question) 1.Label label; 2.TextField textField=new TextField(); 3.public void keyPressed(KeyEvent ke) { 4.//
Line No 4 5. } Identify code at Line No. 4 to get key code-

A) char keyChar=key.getKeyChar(); B) charkeyChar = textField.getKeyChar(); C) char


keyChar=label.getKeyChar(); D) char keyChar = KeyEvent.getKeyChar(); Answer -
char�keyChar=key.getKeyChar();

Question) Select the interface which define a method actionPerformed()?

A) ComponentListener B) ContainerListener C) ActionListener D) InputListener Answer -


ActionListener

Question) 1.Label label; 2.TextField textField=new TextField(); 3.public void keyPressed(KeyEvent ke) { 4.//
Line No 4 5.} Identify code at Line No. 4 to get key code-

A) char keyChar =KeyEvent. getKeyCode (); B) char keyChar =textField. getKeyCode (); C) char keyChar
=label. getKeyCode (); D) char keyChar =ke. getKeyCode (); Answer - char�keyChar =
ke.getKeyCode ();

Question) The translatePoint( ) method-

A) changes the location of the event. B) changes x co-ordinates of the event. C) changes y co-ordinates
of the event. D) returns the translate co-ordinates. Answer - changes the location of the event.

Question) Select the method of MouseMotionListener Interface.

A) mouseDragged() B) MouseMotionListener() C) MouseClick() D) MousePressed() Answer -


mouseDragged()

Question) Select the interface: Which defines a method itemStateChanged()?

A) ItemState B) ContainerListener C) ActionListener D) ItemListener Answer - ItemListener

Question) How many method define in FocusListener interface

A) one B) two C) four D) seven Answer - two

Question) How many method define in ContainerListener interface.

A) seven B) two C) five D) one Answer - two

https://localhost/dashboard/ques_ans_22517.php 131/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) ------types of exceptions are occurred in networking programming

A) UnknownHostException B) MalformedURLExeption C) Exception D) All of the above Answer -


All of the above

Question) .net,.util,.lang are examples of -------

A) package B) class C) Interface D) Method Answer - package

Question) .net,.util,.lang,.gov, from this -----is a domain

A) .net B) .util C) .lang D) .gov Answer - .gov

Question) From following which is package?

A) .com B) .util C) .gov D) All of the above Answer - .util

Question) Networking classes encapsulate the "socket" paradigm pioneered in the (BSD) Give the
abbreviation of BSD?

A) Berkeley Software Distribution B) Berkeley Socket Distribution C) Berkeley System Distribution D)


None of the above Answer - Berkeley Software Distribution

Question) Datagrams are ------------------ of information passed between machines

A) bundles B) sets C) none of A and B D) Both A and B Answer - bundles

Question) TCP/IP style of networking provides ------------------

A) serialized stream of packet data B) predictable stream of data C) reliable stream of data D) All of the
above Answer - All of the above

Question) TCP includes many complicated algorithms for dealing with-------

A) congestion control on crowded networks B) pessimistic expectations about packet loss C) inefficient
way to transport data D) All of the above Answer - All of the above

Question) -------- constructor specifies only a buffer that will receive data and the size of packet.

A) DatagramPacket(byte data[], int size) B) DatagramPacket(byte data[], int offset, int size) C)
DatagramPacket(byte data[], int offset, int size , InetAddress ipAddress, int port) D) All of the above
Answer - DatagramPacket(byte data[], int size)

Question) DatagramPacket has ----------- methods

A) int getPort() B) byte[] getData() C) int getLength() D) All of the above Answer - All of the
above

Question) What is the output of this program? import java.net.*; class networking { public static void
main(String[] args) throws MalformedURLException { URL obj = new
URL("http://www.sanfoundry.com/javamcq"); System.out.print(obj.getPort()); } }

A) 1 B) 0 C) -1 D) garbage value Answer - -1

https://localhost/dashboard/ques_ans_22517.php 132/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) import java.net.*; class networking { public static void main(String[] args) throws Exception { URL
obj = new URL("http://www.oracle.com"); URLConnection obj1 = obj.openConnection(); int len =
obj1.getContentLength(); System.out.print(len); } }

A) 0 B) 127 C) compile time error D) run time error Answer - 0

Question) Which steps occur when establishing a TCP connection between two computers using sockets?

A) The server instantiates a ServerSocket object, denoting which port number communication is to occur on
B) The server invokes the accept() method of the ServerSocket class. This method waits until a client
connects to the server on the given port C) After the server is waiting, a client instantiates a Socket object,
specifying the server name and port number to connect to D) All of the above Answer - All of the
above

Question) Which of these transfer protocol must be used so that URL can be accessed by URLConnection
class object?

A) http B) https C) Any Protocol can be used D) None of the mentioned Answer - http

Question) What is the output of following program? import java.io.*; import java.net.*; public class
URLDemo { public static void main(String[] args) { try { URL url=new URL("http://www.sanfoundry.com/java-
mcq"); System.out.println("Protocol: "+url.getProtocol()); System.out.println("Host Name: "+url.getHost());
System.out.println("Port Number: "+url.getPort()); } catch(Exception e){System.out.println(e);} } }

A) Protocol: http B) Host Name: www.sanfoundry.com C) Port Number: -1 D) all above mentioned
Answer - all above mentioned

Question) What is the output of this program? import java.net.*; class networking { public static void
main(String[] args) throws Exception { URL obj = new URL("https://www.sanfoundry.com/javamcq");
URLConnection obj1 = obj.openConnection(); System.out.print(obj1.getLastModified); } } Note: Host URL
was last modified on june 18 tuesday 2018 .

A) july B) 18-6-2013 C) Tue 18 Jun 2013 D) Tue Jun 18 2018 Answer - Tue Jun 18 2018

Question) In Uniform Resource Locator (URL), path is pathname of file where information is

A) Stored B) Located C) to be transferred D) Transferred Answer - Located

Question) The class ________is used for accessing the attributes of remote resource.

A) URI B) URLConnection C) URL D) URLLoader Answer - URLConnection

Question) How many forms of constructors URL class have?

A) 1 B) 2 C) 3 D) 4 Answer - 3

Question) How many forms of constructors URLConnection class have?

A) 1 B) 2 C) 3 D) none of the above Answer - none of the above

Question) openConnection() method present in which class?

A) URL B) URLConnection C) InetAddress D) HTTPURLConnection Answer - URL

https://localhost/dashboard/ques_ans_22517.php 133/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

Question) getContentType() method present in which class?

A) URL B) URLDecoder C) URLConnection D) none of the above Answer - URLConnection

Question) getContentLength() method present in which class?

A) URL B) URLConnection C) URLDecoder D) URLNotFoundException Answer -


URLConnection

Question) Which of these classes can be added to a Frame component ?

A) Component B) Window C) Button D) Applet Answer - Button

Question) getDate() method present in which class?

A) URL B) URLDecoder C) URLConnection D) All of the mentioned Answer - URLConnection

Question) Which of the following method of Applet class execute only once ?

A) stop() B) paint() C) start() D) init() Answer - init()

Question) getConnectionTimeout() method present in which class?

A) URL B) URLDecoder C) URLConnection D) URLNotFoundException Answer -


URLConnection

Question) getProtocol() method present in which class?

A) URL B) URLDecoder C) URLConnection D) none of the above Answer - URL

Question) ___________method of DatagramPacket is used to find the port number.

A) port() B) GetPort() C) getPort() D) findPort() Answer - GetPort()

Question) getInetAddress( ) method present in which class?

A) URL B) Socket C) ServerSocket D) none of the above Answer - Socket

Question) getLocalPort( )method present in which class?

A) Socket B) URLDecoder C) URLConnection D) URLNotFoundException Answer - Socket

Question) getQuery() method present in which class?

A) URL B) URLDecoder C) URLConnection D) none of the above Answer - URL

Question) getRef() method present in which class?

A) URLNotFound B) URLDecoder C) URLConnection D) URL Answer - URL

Question) getPath() method present in which class?

A) URL B) URLDecoder C) URLConnection D) none of the above Answer - URL

Question) URLConnection class present in which package?

https://localhost/dashboard/ques_ans_22517.php 134/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) url B) urlconnection C) URL D) .net Answer - .net

Question) getExpiration( ) method present in which class?

A) URL B) URLDecoder C) URLConnection D) none of the above Answer - URLConnection

Question) To create menus on the container which of the following classes are used?

A) Menu B) MenuBar C) MenuItem D) All of the above Answer - All of the above

Question) ---------------------method is used to add the menu items to menus.

A) add() B) addComponent(); C) addMenuItem() D) setItem() Answer - add()

Question) ----------------------method is used to add the menubar to the frame.

A) setMenu() B) setMenuBar() C) addMenuBar() D) All of the above Answer - setMenuBar()

Question) Which of the following components allow multiple selections? A. Checkbox B.Radio buttons
C.Choice D.List

A) A and B B) B and C C) C and D D) A and D Answer - A and D

Question) _____ is immediate super class of Menu class.

A) MenuBar B) MenuItem C) MenuComponent D) Object Answer - MenuItem

Question) Which of the following creates a List with 5 visible items and multiple selection enabled?

A) new List(5,true) B) new List(true,5) C) new List(5,false) D) new List(false,5) Answer - new
List(5,true)

Question) Which of the following may a menu contain? A) separator B) check box C) menu item D) panel

A) A and B B) B and C C) A and D D) A and C Answer - A and C

Question) How could you set the frame surface color to pink ?

A) s.setBackground(Color.pink); B) s.setColor(PINK); C) s.Background(pink); D) s.color=Color.pink


Answer - s.setBackground(Color.pink);

Question) which of the following method is used to retrieve whether checkbox is selected?

A) getState() B) getLabel() C) setState() D) setLabel() Answer - getState()

Question) Which of the following statements are true? A) A Dialog can have a MenuBar. B) Menu extends
MenuItem C) A MenuItem can be added to a Menu. D) A Menu can be added to a Menu.

A) A and B B) B and C C) A and D D) C and D Answer - B and C

Question) write output of following import java.net.*; class networking16 { public static void main(String[]
args) throws MalformedURLException { URL obj = new URL("http://www.sanfoundry.com/javamcq");
System.out.print(obj.toExternalForm()); } }

https://localhost/dashboard/ques_ans_22517.php 135/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php

A) sanfoundry B) sanfoundry.com C) www.sanfoundry.com D) http://www.sanfoundry.com/javamcq


Answer - http://www.sanfoundry.com/javamcq

https://localhost/dashboard/ques_ans_22517.php 136/136

You might also like