AJP
CLASS TEST – II
QUESTION BANK
Which class is used to encapsulate both the numerical IP address and the
domain name for that address?
a) InetAddress
b) SocketAddress
c) IPAdress
d) DNSSockets
________ points to a resource on the World Wide Web
a)Uniform Resource Locator(URL)
b)Inet Address
c)ServerSocket
d)TCP/IP
Which are the two constructors used to create client sockets?
a)Socket(String hostName) ,Socket(InetAddress ipAddress, int port)
b)Socket(String hostName, int port) ,Socket(InetAddress ipAddress)
c)Socket(String hostName, int port), Socket(InetAddress ipAddress, int port)
d)None of the above
The _____ method returns the InetAddress object that represents the local host.
a) getByName(String hostName)
b) getLocalHost()
c) getAllByName(String hostName)
d) None of the above
The _____ method returns the InetAddress object that represents the local host.
a)getByName(String hostName)
b)getLocalHost()
c)getAllByName(String hostName)
d)None of the above
______ is simply an entity that wants to gain access to a particular server.
a.Client
b. server
c. network
d. package
A _____ is a numbered socket.
a. port
b. switch
c. URL
d. none of the above
Choose the correct output
import java.net.*;
class myURL2
{
Public static void main(String args[]) throws MalformedURLException
{
URL u=new URL("http://www.msbte.com");
System.out.println("Protocol="+u.getProtocol());
System.out.println("Host Name="+u.getHost());
System.out.println("Port Number="+u.getPort());
System.out.println("File Name="+u.getFile());
}
}
a) Protocol=http Host Name=www.msbte.com Port Number= -1 File Name=
b)Protocol=http Host Name=www.msbte.com Port Number= -1
c)Protocol=http Host Name=www.msbte.com File Name=
d)Protocol=http Host Name=www.msbte.com Port Number= 1 File Name=
A URL specification is based on _________ components.
a)Five
b)Two
c)Three
d)Four
The _______ method returns an InetAddress for a host name passed to it.
a) getByName(String hostName)
b) getLocalHost()
c) getAllByName(String hostName)
d) None of the above
Which are the four components of URL?
a) Protocol,Server name or IP Address,Port Number
b) Protocol,Server name or IP Address,Port Number, File Name or directory name
c)Protocol,Server name or IP Address,Port Number,Host name
d)None of these
Calling ServerSocket() constructor with port value 'zero' means _____________.
a)ue a port number that is automatically allocated.
b)use a local port
c)use server port
d)None of above
URL class has several constructors; each can throw a _____________________.
a)MalformedURLException
b)IOException
c)URLException
d)SocketException
What is return type of getAddress() method of InetAddress class?
a)byte[]
b)String[]
c)Array[]
d)Double
Choose the correct output
import java.net.*;
class networking
{
Public static void main(String args[])throws UnknownHostException
{
InetAddress obj1 =InetAddress.getByName("msbte.com");
InetAddress obj2 =InetAddress.getByName("msbte.com"); boolean x =
obj1.equals(obj2); System.out.print(x);
}
}
a)true
b)false
c)1
d)-1
For execution of INSERT SQL query in JDBC, ............. method must be used.
a) executeUpdate()
b) executeStatement()
c) executeQuery()
d) Execute()
JDBC is a --------------------- interface, which means that it is used to invoke SQL
commands directly.
a) high level
b) low level
c) middle level
d) top level
What is the output of this program?
import java.net.*;
class netdemo1
{
public static void main(String args[]) throws UnknownHostException
{
InetAddress Address = InetAddress.getByName("cisco.com");
System.out.println(Address.getHostName());
}
}
a) cisco
b) cisco.com
c) www.cisco.com
d) None of the mentioned
Which of the following is not a function of JDBC
a) Allows Java programs to execute SQL Statements
b) Allows Java programs to retrive the results of the SQL Statements
c) Allows Java programs to manipulate the design of the application
d) Allows Java programs to send user defined requests to the database
The ............................. Naming service is used to provide a logical name for the DataSource
to make a connection.
a. Java Database Connectivity (JDBC)
b. Java Naming anfd Directory Interface (JNDI)
c. Open Database Connectivity (ODBC)
d. Domain Name Server
ODBC Drivers are platform _______________
a) Dependent
b) Independent
c) Both a and b
d) None
ODBC requires configuring _______ which represents the target database.
a) Data String Name
b) Data Source Name
c) Domain Name
d) Database name
Which method is of the connection object is used to get the object of the
PreparedStatement interface?
a. executeStatement()
b. updateStatement()
c. preparedStatement()
d. getStatement()
............................... Sub class of statement interface.
a. Statement Interface
b. PreparedStatement Interface
c. CallableStatement Interface
d. PreparedStatement Class
What is connection interface?
a) It is a standard type that defines an abstraction to access the session established with
database server.
b) It is used to create Connection Object that provides an entry point for database
connectivity.
c) both a and b
d) none of the above
class.forName() method throws
a) NotFoundException
b) ClassNotFoundException
c) SQLException
d) Cant Throws any exception
The JDBC-ODBC Bridge driver translates the JDBC API to the ODBC API and used
with ________
a) JDBC drivers
b) ODBC drivers
c) Both A and B
d) None of the above
Three methods are central to the life cycle of a servlet ___________, __________
and________ .
a)init(), main(), run()
b)init(), service(), destroy()
c)init(), run(), stop()
d)init(), start(), stop()
CallableStatement is used to execute_________________
a) stored procedure
b) Statement
c) Prepared Statement
d) Procedure
In the three tier model the middle tier of the services acts as a mediator between ______ and
___.
a) Java application and databases
b) Client and Server
c) Java application and client
d) Java application and server
Methods of ResultSet() throws ____________
a) IOException
b) Exception
c) DatabaseException
d) SQLException
Name the type number of driver belongs to JDBC ODBC Bridge driver?
a) Type 1
b) Type 2
c) Type 3
d) Type 4
Where the object of ResultSet maintains a cursor?
a) Second Row
b) First Row
c) Last Row
d) Middle Row
which of the following function is used to find the column count of the particular
ResultSet ?
a) getColumnCount()
b) getRow
c) getcolumnCount()
d) getcolumncount()
Which type of driver is unqiue in JDBC?
a) Native Protocol Pure-Java Driver
b) JDBC-Native API
c) Native API partly Java driver
d) JDBC-ODBC Bridge Driver
Which of the following method Write s and stack the trace for e to the server log?
a) void log(Exception e, String s)
b) void log( String s)
c) void log()
d) None of these
------------ method returns true if the cookie contains session id.Otherwise returns false.
a)Boolean isRequestedSessionIdFromCookie()
b) Boolean isRequestedSessionId()
c) Boolean isSessionIdFromCookie()
d)None of the above
We can set attributes in __________ that other servlets can use in their implementation.
a) ServletConfig
b) ServletContext
c) ServletRequest
d) none of these
------------------ class provides methods to handle HTTP requests and responses
a)HttpServlet
b)Cookie
c)HttpSessionEvent
d)None of the above
-------------- class encapsulates session-changed event
a)HttpServlet
b)Cookie
c)HttpSessionEvent
d)None of the above
The servlet is invoked when a form on a Web page is submitted.
a)True
b)False
-------------- class encapsulates session-changed event
a) HttpServlet
b) Cookie
c) HttpSessionEvent
d) None of the above
Which method adds cookie to the HTTP response
a) void addCookie()
b) void addCookie(Cookie cookie)
c) void addCookie(String cookie)
d) void addCookie(int i)
________ method returns the string equivalent of the client hostname.
a) String getRemoteHost()
b)String getRemoteAddr()
c) String getProtocol()
d) None of these
Which method is used to specify before any lines that uses the PrintWriter?
a)SetPageType()
b) setContentType()
c)setContextType()
d)setResponseType()
We cannot set attributes in ________ interface that other servlets can use in their
implementations.
A)ServletConfig
b) ServletContext
c)ServletRequest
d) both a & b
Generic servlet is the super class of all servlets.
a) True
b) False
Servlet runs each request in a __________ ?
a) OS shell
b)JVM
c)Separate thread
d)JRE
----------------- allows session data to be read and written
a)HttpServletRequest
b)HttpServlet
c)HttpSession
d)HttpSessionBindingListener
Consider the following program which class should be extended?
import java.io.*;
import javax.servlet.*;
public class First extends ************{
public void service(ServletRequest req,ServletResponse res)
throws IOException,ServletException{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.print("<html><body>");
out.print("<b>hello generic servlet</b>");
out.print("</body></html>");
}
}
a) HttpServlet
b) GenericServlet
c)Servlet
d) None of These
Which method returns copy of this object?
a)getclone()
b)clone()
c)setclone()
d)None of these
Which class allows state information to be stored on a client machine?
a) Cookie
b)HttpServlet
c)HttpSession
d)None of these
Which method returns the URL?
a)getURL()
b)URL()
c)getRequestURL()
d)None of the above
Which method performs an HTTP DELETE?
a) void doDelete(HttpServletRequest req,HttpServletResponse res) throws IOException,
ServletException
b) void Delete(HttpServletRequest req,HttpServletResponse res) throws IOException,
ServletException
c) void doDelete(HttpRequest req,HttpServletResponse res) throws IOException,
ServletException
d) void doDelete(HttpRequest req,HttpResponse res) throws IOException, ServletException
Which of the following code can be used to send an error response to the client using the
specified status code and error message?
a) request.sendError(statusCode,message)
b) response.sendError(statusCode,message)
c) header.sendError(statusCode,message)
d) None of the above