1. Which of these package contains classes and interfaces for networking?
a) java.io b) java.util
c) java.net d) java.network
2. Which of these class is used to encapsulate IP address and DNS?
a) DatagramPacket b) URL
c) InetAddress d) ContentHandler
3. What does getHostAddress() of InetAddress class terurn?
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 D.
d) Returns a string that represents a host name associated with Inetaddress Answer
4. Which of these class is used to create servers that listen for either local or remote
client programs?
a) httpserver b) ServerSocket
c) DatagramSocketd d) Socket
5. Class.forName("------------------------ ")
a) sun.jdbc.JdbcOdbcDriver b) sun.odbc.JdbcOdbcDriver
c) sun.jdbc.odbc.JdbcOdbcDriver d) None of the above
6. Which of the following encapsulates an SQL statement which is passed to be
parsed, compiled, planned and executed?
a) DriverManager b) Connection
c) JDBC Driver d) Statement
7. 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
8. Complete following server code for accepting client request?
import java.io.*;
import java.net.";
public class MyServer
{
public static void main(String[] args)
{
try
Page 1 of 8
{
ServerSocket ss=new ServerSocket(6666);
DataInputStream dis=new DataInputStream(s.getInputStream());
String str(String)dis.readUTF();
System.out.println("message= "+str);
ss.close();
}
catch(Exception e)
{
System.out.println(e);
}
} }
a) Socket s-ss.accept(); b) ss.accept();
c) Socket s; s.accept() d) Socket s-accept();
9. ServerSocket class has one of the following constructor
a) ServerSocket(int port) b) ServerSocket(String host, int port)
c) ServerSocket(int port, InetAddress add) d) ServerSocket(InetAddress add, int port)
10. Which of the following type of JDBC driver, uses database native protocol?
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
11. Which packages contains JDBC classes?
a) java.jdbc b) java.jdbc.sql
c) java.sql d) java.rdb
12. Consider the following code. What will be student table data after executing 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();
Page 2 of 8
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.
13. 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)+""ers.getDouble(3));
}
s.close();
c.close();
}
}
a) Missing semicolon b)Missing {
c) Missing } d) Missing package statement
14. ODBC stands for?
a) Open database concept b) Open database connectivity
c) Open database communications d) None of the above
15. Which of the following is used generally for reading the content of the database?
a) boolean execute() b) ResultSet executeQuery()
c) int executeUpdate() d) None of the above\
Page 3 of 8
16. The java specification defines an application programming interface for
communication between web server and application program.
a) Randomize b) Program
c) Servlet d) Server
17. A is a small piece of information that is persisted between the
multiple client requests.
a) Cookie b) Session
c) HTTPServlet d) Datagram
18. Apache Tomcat is .
a) Servlet b) Java Program
c) API d) Web server capable of running Java programs
19. Which of the following are interfaces in javax.servlet.http package?
a) HttpServletRequest b) HttpServletResponse
c) HttpSession d) All of the above
20. A servlet is an instance of .
a) the HttpServlet class b) Cookies
c) Sessions d) None of the Above
21. Given an HttpServletRequest request and HttpServletResponse response
instances. Which sets a cookie “username” with the value “joe” in a servlet?
a) request.addCookie(new Cookie(“username” ,“joe));
b) response.addCookie(new Cookie(“username” ,“joe”));
c) request.addCookie(“username” , “joe);
d) request.addCookie(“username” , “joe);
22. Which of the following is the default HttpRequest method?
a) doGet( ) b) doPost( )
c) doTrace( ) d) doPut( )
23. Which of the following is true about destroy() method of servlet?
a) It is called only once
b) Servlet object is marked for garbage collection after called destroy() method.
c) The servlet is terminated by calling the destroy() method.
d) All of Above
24. Identify the missing statement at line no. 6.
1 import java.io.";
2 import javax.servlet.*;
3 public class First extends GenericServlet{
Page 4 of 8
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>");
}}
a) PrintWriter out = res.getWriter();
b) PrintWriter in = res.getWriter()
c) PrintWriter out res.putWriter();
d) PrintWriter in = res.putWriter()
25. In following Java program fill statement showing ***.
Select any one option fro given options
import java.io.*;
importjavax.servlet.*;
importjavax.servlet.http.*;
public class p172 extends HttpServlet
{ public void doPost(HttpServletRequestrequest,HttpServletResponse response)
throwsServletException,IOException
{
PrintWriter z;
z=new PrintWriter(response.getOutputStream());
String x=request.getParameter("data");
String y=request.getParameter("data");
String a=request.getParameter("data");
String b=request.getParameter("data");
Cookie c=new Cookie("MyCookie",x);
response.addCookie(c);
*******
z.println("<b>mycookie has been set to");
z.println(x);
z.close();
} }
a) response.setContentType("text/html");
b) response.ContentType("text/html");
c) request.setContentType("text/html");
d) response.getContentType("text/html");
Page 5 of 8
26. A server socket can connect to clients.
(a) 1
(b) 2
(c) 10
(d) multiple
27. Resolver in DNS system maps .
(a) Domain name to IP address
(b) IP address to domain name
(c) Domain name to MAC address
(d) MAC address to IP address
28. If a program consists of three classes, then after compilation how many class files
will be created by the compiler?
(a) one
(b) three
(c) uncountable
(d) zero
29. Which of the following is not a method of Security class?
(a) socketPermission( )
(b) filePermission( )
(c) dataPermission( )
(d) None of above
30 TCP does not supports Multicasting and Broadcasting because .
(a) It supports full duplex communication.
(b) It provides error control.
(c) It provides flow control
(d) It is connection oriented protocol
31. Which of the following is true about TCP protocol?
(a) is reliable and connection oriented
(b) is unreliable but connection oriented
(c) is reliable and connectionless
(d) None of these
32. In the below statement, which type of query can be used with executeUpdate( ) method.
statement.executeUpdate(query here)
(a) Insert, Update, Delete
(b) Insert, Select, Delete
(c) Only Select
(d) Any Query
33. What is purpose of next( ) method?
(a) to retain the next element in a series.
(b) to retain next table.
(c) to retain next record in a series.
(d) None of the above
Page 6 of 8
34. Native – protocol pure Java Driver converts into the directly.
(a) JDBC calls, network protocol
(b) ODBC class, network protocol
(c) ODBC class, user calls
(d) JDBC calls, user calls
35. Choose the correct syntax for getConnection( ) method.
(a) public static Connection getConnection(String url, String password) throws SQLException
(b) public static Connection getConnection(String name, String password) throws SQLException
(c) public static Connection getConnection(String url, String name, String password) throws
SQLException
(d) public static Connection getConnection(String url, String name) throws SQLException
36. SQL stands for .
(a) Structured Query Language
(b) Sequential Query Language
(c) Structured Question Language
(d) Sequential Question Language
37. is a table of data which represents a data from table.
(a) MetaData
(b) ResultSetMetaData
(c) ResultSet
(d) Statemen
38. To send binary output in the response, the following method of HttpServlet response many be
used to get the appropriate Writer/Stream object.
(a) getStream( )
(b) getOutputStream( )
(c) getBianaryStream( )
(d) getWriter( )
39. is the first Phase of Servlet Life cycle.
(a) service( )
(b) init( )
(c) destroy( )
(d) Both B & C
40. How many copies of a JSP page can be in memory at a time?
(a) 1
(b) 2
(c) 3
(d) Unlimited
41. Which method is used to specify before any lines that used the PrintWriter?
(a) setPageType( )
(b) setContextType( )
(c) setContentType( )
(d) setResponseType( )
42. is used to read data from a client request.
(a) ServletResponse
Page 7 of 8
(b) ServletRequest
(c) Servlet
(d) ServletConf
Page 8 of 8