AJP MCQ Question Bank
AJP MCQ Question Bank
php
Java Question
Question) Which package is required for an adapter classes?
A) inheritance B) class C) Class ,Object D) event listener interface Answer - event listener
interface
A) WindowAdapter B) KeyAdapter C) MouseAdapter D) All the above Answer - All the above
A) B) C) D) Answer -
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()); } }
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.
Question) An _________ class listener interface and Event class Listener interface has same name.
Question) An adapter class provides an _________ implementation of all methods in an event listener
interface.
Question) Which of the following method does not belongs to WindowListerner interface?
Question) Which of the following method is invoked when a window is changed from a normal to a
minimized state?
Question) If an adapter class is inherited , there is no need of implementing all the methods of listener
interfaces .
Question) Adapter class can be also used for incorporating ___________property of JAVA.
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.
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) 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) 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 .
Question) __________ is a superclass of all AWT events that are handled by the delegation event model.
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
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) 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) Text Event B) Character Event C) Label Event D) TextField Event Answer - Text Event
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) The abstract class ______________ is a subclass of ComponentEvent and is the superclass for
component input events.
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.
Question) The __________method returns the object that generated the event.
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.
Question) The _________method returns a reference to the component that was added to or removed from
the container.
Question) A class that have no name is known as_______________ inner class in java.
Question) Which are two ways to create Java Anonymous inner class ?
Question) Which event is generates when checkable menu item is selected or deselected?
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.
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(); } }
Question) Since Nested class is a member of its enclosing class Outer, you can use __________ notation
to access Nested class and its members.
A) event class B) class C) adapter classes D) inner classes Answer - inner classes
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?
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"); } } }
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(); } }
Question) Identify the correct adapter name and event name. class MyWindowAdapter extends
________________ { public void windowClosing(_____________ e) { System.exit(0); } }
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; } } }
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.
Question) The ___________ method returns a value that indicates which modifier keys were pressed when
the event was generated.
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) getAllByName() method returns an array of_____________ that represents all of the addresses
that specific host name has
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
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()
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 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
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
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?
Question) JDBC facilitates to store the java objects by using which of the methods of Prepared Statement 1.
setObject () 2. setBlob() 3. setClob()
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.
Question) Can we retrieve a whole row of data at once, instead of calling an individual ResultSet.getXXX
method for each column ?
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
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?
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?
Question) The interface ResultSet has a method, getMetaData(), that returns a/an
A) Data Modification Language B) Data Definition Language C) Data Control Language D) Data
Manipulation Language Answer - Data Manipulation Language
https://localhost/dashboard/ques_ans_22517.php 10/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
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);} } }
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);
Question) All raw data types (including binary documents or images) should be read and uploaded to the
database as an array of
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);} } }
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?
Question) Whose object is to be created to show any number of choices in the visible window?
Question) What is used to store partial data results, as well as to perform dynamic linking, return values for
methods, and dispatch exceptions?
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
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 ...
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 layout of a container can be altered by using which of the following methods
Question) In JDBC _____ imports all java classes concerned with database connectivity.
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
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 ?
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 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) 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) 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
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) 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) }
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) 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) 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) Navigation control is decentralized B) Time consuming C) both a& b D) UI components are not user
friendly Answer - both a& b
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.
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]); } } }
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
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
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.
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.
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(); } }
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?
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?
Question) Which Swing Component classes that are used to Encapsulates a mutually exclusive set of
buttons?
Question) Which method is used to add tooltip text to almost all components of Java swing?
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
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 _______?
https://localhost/dashboard/ques_ans_22517.php 19/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
Question) The default layout manager for the content pane of a swing is :
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) 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
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(String str) creates a label that contains the string specified by str which is _________
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
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
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 ?
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(); }}
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); } }
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); } }
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()); } }
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
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.
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.
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 ?
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
?
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()
https://localhost/dashboard/ques_ans_22517.php 23/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
Question) Socket method called______returns the port number that socket is bound to on local machine
Question) __________________method is needed only when you instantiate the socket using the not
argument constructer.
Question) InetAddress class having method which returns a string that shows the host name and IP
address.
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)
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) 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
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
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
Question) If your application has successfully bound to specified port and is ready for client request
then_________
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
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
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()
Question) Which exception will occur when port is already bound with an application and other application is
requesting for same port?
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
A) 1349 B) port number of local machine C) local host D) localhost/1349 Answer - port number
of local machine
Question) Which constructor of DatagramSocket class is used to create a datagram socket and binds it with
the given port number?
Question) Which exception will occur if specified port number is not available for DatagramSoclet?
Question) Which of the following constructor is used to create datagram socket with port number and host
address
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
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
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) What is the output of following code? DatagramPacket dp =new DatagramPacket(byte[] data,
1024); System.out.println(dp.getLength());
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);} } }
https://localhost/dashboard/ques_ans_22517.php 28/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
https://localhost/dashboard/ques_ans_22517.php 30/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
https://localhost/dashboard/ques_ans_22517.php 31/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
https://localhost/dashboard/ques_ans_22517.php 32/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
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
https://localhost/dashboard/ques_ans_22517.php 33/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
A) Applet Windowing Toolkit B) Abstract Windowing Toolkit C) Absolute Windowing Toolkit D) None of
the above Answer - Abstract Windowing Toolkit
https://localhost/dashboard/ques_ans_22517.php 35/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
https://localhost/dashboard/ques_ans_22517.php 36/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
A) TCP B) UDP C) TCP and UDP D) FTP Answer - TCP and UDP
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
Question) How would you set the color of a graphics context called g to cyan?
Question) Which of the following are passed as an argument to the paint( ) method?
Question) Which of the following methods are invoked by the AWT to support paint and repaint operations?
Question) Which of the following classes have a paint( ) method? a.Canvas b.Image c.Frame d.Graphics
Question) Which of the following are methods of the Graphics class? a.drawRect( ) b. drawImage( )
c.drawPoint( ) d. drawString( )
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.
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?
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);
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); } }
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) 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
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:
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); -------------------- } }
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
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
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) 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) . Label, TabbedPane, CheckBox B) Panel, TabbedPane, List C) TabbedPane, List, Applet D) Applet,
TabbedPane, Pane Answer - Panel, TabbedPane, List
Question) Which of these package contains classes and interfaces for networking?
Question) Label lb=new Label("Advanced Java");Which method is used to obtain output as "Advanced
Java"
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.
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
Question) Which of these is a protocol for breaking and sending packets to an address across a network?
Question) How many ports of TCP/IP are reserved for specific protocols?
Question) Which object can be constructed to show and select any number of choices in the visible
window?
Question) Which method of Choice class is used to return index of the selected item ?
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
A) 8 B) 16 C) 32 D) 64 Answer - 32
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) _____AWT Component is used to select only one item from popup list of textual items
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(); } }
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
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?
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) 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
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) 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"); } }
A) import javax.swing.* B) import java.swing.* C) Both A & B D) None of the above Answer -
import javax.swing.*
Question) Applet class is a subclass of the panel class, which is again a subclass of the__________class
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
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
Question) Which of the following applet tag is legal to embed an applet class named Test into a webpage?
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); ---------------------------------- } }
Question) The___________class is an abstract class that represents the display area of the applet.
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); } }
Question) Which of the following method of applet class is used to clear the screen and calls the paint( )
method
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); } }
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
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
Question) The___________method is defined by the AWT which causes the AWT runtime system to
execute a call to your applet’s update( ) method.
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.
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?
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");
}}}
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.
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.
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) {} } }
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.
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
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
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.
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
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) 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
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) 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 -
https://localhost/dashboard/ques_ans_22517.php 53/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
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) 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
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
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) 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) 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) The elements of a _________ Layout are organized in a top to bottom, left to right pattern.
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) 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
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.
Question) The following specifies the advantages of ____ It is lightweight. It supports pluggable look and
feel. It follows MVC (Model View Controller) architecture.
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?
Question) Which driver is efficient and preferable for using JDBC applications?
Question) Which of the following methods are needed for loading the database driver in JDBC?
Question) ________ is an open source DBMS product that runs on UNIX, Linux and Windows.
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
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(); }}
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(); }}
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) 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.
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.
Question) The _________________ method executes an SQL statement that may return multiple results.
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
https://localhost/dashboard/ques_ans_22517.php 58/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
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) Three tiered B) Multithreaded C) Best for any platform D) All of the above Answer -
Multithreaded
A) Type-4 driver B) Type-1 driver C) Type-2 driver D) Type-3 driver Answer - Type-4 driver
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
A) Grid Layout B) Card Layout C) Border Layout D) Flow Layout Answer - Flow Layout
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) 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
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
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.
Question) Which of the following statements are used to create panel in border layout?
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
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
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
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
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 informs an object that it is bound to or unbound from an HTTP session?
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.
Question) ------------------- class provides methods to handle HTTP requests and responses
Question) Which type of driver converts JDBC calls into network protocol used by database management
system directly?
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
A) 1 B) 2 C) 3 D) 4 Answer - 4
Question) __________ is used when user wants to enter text that is not displayed,such as password.
https://localhost/dashboard/ques_ans_22517.php 62/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
Question) To create radiobutton in Applet which of the following are valid statements ?
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
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?
Question) Which of the following value is not available to align arguments to use in Swing Constants
interface?
Question) Which of the following classes of Java swing extends Applet class?
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 ?
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
A) S B) A C) X D) J Answer - J
Question) The syntax for creating and setting layout manager object is--------------
Question) The Swing is an API for providing graphical user interface for
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) Listeners are created by implementing one or more of the ________________defined by the
java.awt.event package.
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
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.
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) 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 -
https://localhost/dashboard/ques_ans_22517.php 65/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
Question) Which of the following method does not belongs to Choice class.
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
A) 1 B) 2 C) 3 D) 4 Answer - 3
Question) Which are the active controls that support any interaction with the user ?
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
?
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 ?
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) 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.
A) Java shoot B) Java control C) Java Class D) Java Foundation Class Answer - Java
Foundation Class
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
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); } }
Question) -------------- is the class representing event notifications for changes to sessions within a web
application.
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) 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.
Question) _______ method returns the part of this request's URL that calls the servlet.
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.
Question) ________ returns a boolean indicating whether the named response header has already been
set.
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.
Question) ______ interface is implemented by objects that need to be notified when they are bound to or
unbound from an HTTP session.
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.
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) ---------returns the current session associated with this request, or if the request does not have a
session, creates one.
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
A) Socket B) ServerSocket C) Both A and B D) None of the above Answer - Both A and B
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?
https://localhost/dashboard/ques_ans_22517.php 70/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
Question) ______ method returns true if requested session ID is valid in the current session context
Question) ____ method adds field to the header with date value equal to 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
https://localhost/dashboard/ques_ans_22517.php 71/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
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) 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
A) Immediately after creation B) When session is expired C) when current browser session ends. D)
Never Answer - when current browser session ends.
https://localhost/dashboard/ques_ans_22517.php 72/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
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) Parameters of ____ request are included as part of the URL that is sent to the Web Server.
Question) ------------ method returns true if the cookie contains session id.otherwise returns false
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) 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.
https://localhost/dashboard/ques_ans_22517.php 73/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
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
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
A) 20 B) 10 C) 15 D) 5 Answer - 10
Question) ----- is the protocol that web browser and server use to transfer hypertext pages and images
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.
https://localhost/dashboard/ques_ans_22517.php 74/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
Question) A typical __________ program obtains a remote reference to one or more remote objects on a
server and then invokes methods on them.
A) Speed B) Efficient C) Security D) All of the above Answer - All of the above
Question) The Prepared statement _____symbolis a placeholder that is replaced by the input parameter at
seen time
A) ? B) * C) / D) + Answer - ?
A) public OutputStream getOutputStream() B) public synchronized void close() C) public Socket accept()
D) none of the above Answer - public Socket accept()
Question) Unlike User Datagram Protocol (UDP), Transmission Control Protocol (TCP) has Services which
is
Question) Unlike Transmission Control Protocol (TCP), User Datagram Protocol (UDP) has Services which
is
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.
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.
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
__________.
Question) which class is used to create servers that listen for either local or client program?
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) 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.
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 )
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.
Question) A servlet can write a cookie to a user's machine via the addCookie( ) method of the
_____________ interface
Question) Which driver converts JDBC API calls into DBMS-specific client API calls?
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) 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 ?
Question) Which driver allows access to multiple databases using one driver?
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 executes the given SQL statement , which return the single ResultSet object?
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) 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 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.
Question) Which method moves the cursor to the first row of the resultset?
Question) Which of the following method of HttpServletRequest interface is used to return all the cookies
from the browser.
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) retrive name of the user B) access name C) Both of the above. D) None of the above. Answer
- retrive name of the user
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)
https://localhost/dashboard/ques_ans_22517.php 79/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
Question) Which method moves the cursor to the beginning of the resultset that is before first row?
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) 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)
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();
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
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.
Question) Which of the following interface declares the lifecycle method for servlet.
Question) Which of the following method returns the session in which the event occurred?
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) ______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) 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) 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.
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.
Question) The ____________ method is overridden to process any HTTP GET requests that are sent to
this servlet.
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) ________class provides stream to read binary data from the request.
Question) Which of the following interface allows a servlet to get initialization parameters.
Question) Which of the following method returns the value of the initialization parameter named param
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
Question) ___________ methods are dangerous to use because they can corrupt the server's state
machine.
Question) ________returns the port number to which the request was sent.
Question) . ________ returns the host name of the server to which the request was sent.
Question) ______ method returns the name of the scheme used to make this request, for example, http,
https, or ftp.
Question) ________ Returns the fully qualified name of the client or the last proxy that sent the request.
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(); } }
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"); } }
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. }
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
Question) Which method of servlet is/are called several times in its life?
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
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) 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?
Question) _____________ returns the real path that corresponds to the virtual path 'vpath'.
Question) The ________ interface is used to indicate that only a single thread should execute the service()
method of a servlet.
Question) The servlet programmer should implement_______ interface to ensure that servlet can handle
only one request at a time.
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.
Question) Every servlet has it's own ________object and servlet container is responsible for instantiating
this object.
Question) The ServletContext is _______ object and available to all the servlets in the web application.
Question) We cannot set attributes in ________ interface that other servlets can use in their
implementations.
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?
Question) Which of the following method forwards the request from a servlet to another resource (servlet,
JSP file, or HTML file) on the server?
https://localhost/dashboard/ques_ans_22517.php 87/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
Question) Which of the following interface guarantees that no two threads will execute concurrently in the
servlet's service method ?
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) 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>"); } }
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
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) . 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.
Question) A cookie's value can uniquely identify a client, so cookies are commonly used for
___________________.
Question) ________ is removed each time when user closes the browser.
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
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 -
A) public void setMaxAge(int expiry) B) public String getName() C) public String getValue() D) All of
above Answer - All of above
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); } }
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 -
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) 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.
Question) which of the following are the methods in belong to HttpServletRequest interface.
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) 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
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) _______________enables a servlet to read and write the state information that is associated with
an HTTP session.
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(); } }
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")); } }
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) Data Network Service B) Data Name Service C) Domain Network Service D) Domain Name Service
Answer - Domain Name Service
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.
Question) Swing is a ----------------------------, whose components are all ultimately derived from the
javax.swing.JComponent class.
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) 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 -
https://localhost/dashboard/ques_ans_22517.php 94/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
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) 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) 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(); } }
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(); } }
https://localhost/dashboard/ques_ans_22517.php 96/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
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 -
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) To implement swings which package is to be imported from the following options :
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__________
Question) Which of the following GridBagLayout variable defines the external padding (border) around the
component in its display area?
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
Question) What is the name of the Swing class that is used for frames?
Question) Swing is the set of ____________ that provides more powerful & flexible components as
compare to Abstract Window Tooklit (AWT).
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) __________ is a Swing class that allows the user to enter a multipleline of text
https://localhost/dashboard/ques_ans_22517.php 98/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
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
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
A) import, drawString, paint B) extends, paint, drawString C) extends, draw, paint D) include,
drawString, paint Answer - extends, paint, drawString
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) 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
A) mobile enabled B) web based C) window based D) package based Answer - window based
https://localhost/dashboard/ques_ans_22517.php 100/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
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) 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.
A) dialog variable B) Window variable C) Title variable D) Frame Variable Answer - Title variable
A) Push Buttons B) Radio Buttons C) Check boxes D) All of the above. Answer - All of the
above.
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) To create vertical Scrollbar B) To create horizontal Scrollbar C) Both D) all of above Answer -
To create vertical Scrollbar
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"); } } });
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 );
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
https://localhost/dashboard/ques_ans_22517.php 102/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
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.
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
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?
https://localhost/dashboard/ques_ans_22517.php 103/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
Question) Assuming we have a class which implements the ActionListener interface, which method should
be used to register this with a Button? ;
A) 2 B) 5 C) 7 D) 4 Answer - 5
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 mouse motion listener?
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.
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) DatagramPacket(byte data[ ], int size) DatagramPacket(byte data[ ], int offset, int size) are
examples of--------------
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
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.
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.
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.
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) Which method not use to obtain the coordinates of the mouse-
Question) Which of these method are used to register a keyboard event Listener ?
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?
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) When a ------------- Dialog box is active, it blocks user input to all other windows in the program.
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(); } }
Question) Following method returns true if a cookie contains the session ID. Otherwise, returns false.
Question) Which of the following method returns true if the URL contains the session ID. Otherwise, returns
false.
Question) _________ method returns true if the requested session ID is valid in the current session context.
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) 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.
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
Question) Following method returns the time (in milliseconds since midnight, January 1, 1970, GMT) when
this session was created.
Question) Which of the following method invalidates the session and removes it from the context.
Question) Which of the following classes represents event notifications for changes to sessions within a
web application
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()
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)
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(); } }
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(); } }
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. }
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) 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.
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?
Question) Which of the following class is used to apply the grid layout?
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.
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) JDBC driver B) Package C) JDBC Interface D) none of the Above Answer - JDBC driver
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
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
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)
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) The core API in java.sql consists of ___ interfaces, ___ classes, and 4 exception types.
Question) By using which interface one can store images in the database in java
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) 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
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()
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."
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)
A) Type 1 Driver B) Type 2 Driver C) Type 3 Driver D) Type 4 Driver Answer - Type 1 Driver
Question) The -------------------- constructor is used to create FileDialog with specified title.
A) Type 1 Driver B) Type 2 Driver C) Type 3 Driver D) Type 4 Driver Answer - Type 3 Driver
A) Type 1 Driver B) Type 2 Driver C) Type 3 Driver D) Type 4 Driver Answer - Type 4 Driver
A) B) C) D) Answer -
A) B) C) D) Answer -
A) B) C) D) Answer -
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.
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
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
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) Return type for method next(), first() and last() method of resultset is ______________
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
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
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.
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"); } } }
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"); } } }
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); } } }
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.
Question) _____________ interface defines methods that enable user to send SQL queries and receive
data from the database.
Question) Which method moves record cursor to the next row of result set?
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.
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
Question) The Following steps are required to perform 1) Implement the Listener interface and overrides its
methods 2) Register the component with the Listener
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
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?
https://localhost/dashboard/ques_ans_22517.php 122/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
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
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.
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);
A) Uniform Resource Locator B) Uniform Resource Latch C) Universal Resource Locator D) Universal
Resource Latch Answer - Uniform Resource Locator
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.
https://localhost/dashboard/ques_ans_22517.php 123/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
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.
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) Which of these class is used to access actual bits or content information of a URL?
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()); } }
Question) Which of these methods is used to know the full URL of an URL object?
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) 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 correct general form of Mouse Clicked method of Mouse Listener interface.
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
Question) Which of these methods is used to know the type of content used in the URL?
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()); } }
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); } }
Question) Select correct general form of Mouse Entered method of Mouse Listener interface.
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
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 -
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(); } }
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
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) 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
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. 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
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. }
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(); }
Question) Which top-level class provides methods to add and remove keyboard and mouse event listeners-
Question) --------------------- class displays a dialog window from which the user can select a file.
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) 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-
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 ();
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.
https://localhost/dashboard/ques_ans_22517.php 131/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
Question) Networking classes encapsulate the "socket" paradigm pioneered in the (BSD) Give the
abbreviation of BSD?
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
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)
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()); } }
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); } }
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
Question) The class ________is used for accessing the attributes of remote resource.
A) 1 B) 2 C) 3 D) 4 Answer - 3
https://localhost/dashboard/ques_ans_22517.php 133/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
Question) Which of the following method of Applet class execute only once ?
https://localhost/dashboard/ques_ans_22517.php 134/136
12/4/2019 https://localhost/dashboard/ques_ans_22517.php
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) Which of the following components allow multiple selections? A. Checkbox B.Radio buttons
C.Choice D.List
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
Question) How could you set the frame surface color to pink ?
Question) which of the following method is used to retrieve whether checkbox is selected?
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.
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
https://localhost/dashboard/ques_ans_22517.php 136/136