0% found this document useful (0 votes)
48 views28 pages

AJP Question Bank

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

AJP Question Bank

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

480 _________ is a protocol for breaking and sending packets to an address across a

network?
A. DNS
B. Proxy server
C. Socket
D. TCP/IP
Answer option d
Marks: 2

498 getLocalHost() method is present in which package


A. java.lang
B. java.util
C. java.net
D. java.awt
Answer optionc
Marks: 2

499 Which is the class present in java.net package used to create packet from byte array
and destination address?
A. DatagramPacket
B. DatagramSocket
C. ServerSocket
D. Socket
Answer optiona
Marks: 2

507 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. 0
B. 1
C. true
D. false
Answer optionc
Marks: 2

520 Which of the following is true for TCP ?


A. TCP is realiable and connection oriented
B. TCP is unrelaible but connection oriented
C. TCP is realiable and connection less
D. none of the these
Answer optiona
Marks: 1

521 What is Socket?


A. End point for communication
B. Combination of IP address and port number
C. Predfined class in java
D. All of these
Answer optiond
Marks: 1
537 Which of the following is true for UDP ?
A. UDP is realiable and connection oriented
B. UDP is unrelaible but connection oriented
C. UDP is unrealiable and connection less
D. none of the these
Answer optionc
Marks: 1

565 What correction should be done in the program to get the correct output
import java.net.*;
import java.io.*;
class url8_5
{
public static void main(String args[])throws MalformedURLException,IOException
{
URL u1=new URL("http://localhost:8080/index.htm");
URLConnection u2=u1.openConnection();
String ct=u2.getContentType();
System.out.println("Content type;"+ct);
InputStream ip=u2.getInputStream();
int c;
while((c=ip.read())!=-1)
{
System.out.print((char)c);
}
}
A. missing semicolon
B. }
C. {
D. all of above
Answer optionb
Marks: 2

480 _________ is a protocol for breaking and sending packets to an address across a
network?
A. DNS
B. Proxy server
C. Socket
D. TCP/IP
Answer optiond
Marks: 2

583 TCP/IP sockets are used to impelement __________ connections.


A. Reliable and persistent
B. Bidirectional and point-to-point
C. Stream-based
D. All of the above
Answer optiond
Marks: 1

584 When a URL object is created __________


A. a connection is automatically established with that URL
B. openConnection() method is used to establish a connection
C. getConnection() method is used to establish a connection
D. makeConnection() method is used to establish a connection
Answer optiona
Marks: 1
605 In the following program choose the correct strings from given options to pass in
URL constructor to get an output without any
exception.
import java.net.*;
class URLDemo
{
public static void main(String args[]) throws MalformedURLException
{
URL hp = new URL("__________");
System.out.println("Protocol: " + hp.getProtocol());
System.out.println("Port: " + hp.getPort());
System.out.println("Host: " + hp.getHost());
System.out.println("File: " + hp.getFile());
}
}
A. http://www.msbte.com/mainsite/index.php
B. http://www.msbte.com:80/mainsite/index.php
C. www.msbte.com/
D. www.msbte.com/mainsite/index.php
A. Only A
B. Only B
C. Either A or B
D. All
Answer optionb
Marks: 2

622 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.
Answer optiond
Marks: 2

625 Which of the following statement is missing in following code:


import java.io.*;
import java.net.*;
public class demo
{
public static void main(String args[]) throws Exception
{
ServerSocket ss = new ServerSocket(8);
DataInputStream in = new DataInputStream(so.getInputStream());
String pass1 = in.readLine();
if(pass1.equals("hi"))
{
System.out.print("\nPassword Is Correct");
PrintStream p1 = new PrintStream(so.getOutputStream());
p1.println("Welcome");
}
else
{
System.out.print("\nWrong Password Entered");
}
}
}
A. int so=ss.wait( );
B. Socket so = ss.accept();
C. ServerSocket so=ss.accept( )
D. ClientSocket so=ss.accept( )
Answer optionb
Marks: 2

112 public InputStream getInputStream() is method of ____________ class


A. Serversocket
B. ClientSocket
C. Socket
D. All of the above
Answer optionc
Marks: 1

113 getOutputStream() returns the output stream of the ________


A. Socket
B. ServerSocket
C. ClientSocket
D. None of the above
Answer optiona
Marks: 1

114 Which of the following statement is correct?


A. The input stream of socket is connected to the output stream of remote socket
B. The output stream of socket is connected to the input stream of remote socket
C. The output stream of socket is connected to the output stream of remote socket
D. A and B
Answer optiond
Marks: 1

115 __________method makes socket object no longer capable of connecting again to


any server
A. send()
B. wait()
C. connect()
D. close()
Answer optiond
Marks: 1

118 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 serve
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 optiond
Marks: 1

119 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 optiona
Marks: 2

120 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 optionc

1. Which of the following is used to call stored procedures on the database?


A. Statement
B. PreparedStatement
C. CallableStatement
D. None of These
Answer optionc

2. Which of the following manages a list of database drivers in JDBC?


A. DriverManager
B. JDBCDriver
C. Connection
D. Statement
Answer optiona

3. Which of the following is used generally used for altering the databases?
A. Boolean execute()
B. ResultSet executeQuery()
C. Int executeUpdate()
D. None of These
Answer c

4. PreparedStatement updateemp = con.prepareStatement


(“insert into emp values(?,?,?)”);
A. The query can be executed using updateemp.executeUpdate() directly
B. Before executing the query need to set values for ? Using setXXX() methods
C. The query can be executed using updateemp.execute() directly
D. The query can be executed using updateemp.executeQuery() directly
Answer optionb

5. String sqlInsert = “insert into books values (3001, ‘Gone Fishing’, ‘Kumar’, 11.11,
11)”;
Int countInserted = stmt.executeUpdate(sqlInsert);
System.out.println(countInserted + “ records inserted.\n”);
What will be output if I execute the code 2 times ?
A. Records inserted
B. 1 records inserted
C. Null records inserted
D. 2 records inserted
Answer optionb

6. Which of the following method is used to insert data into table?


A. executeQuery()
B. executeInsertQuery()
C. executeUpdate()
E. Execute()
Answer optionc

7. Select the missing statement in the program to get the following output.
Import java.sql.*;
Class Demo1
{
Public static void main(String args[]) throws Exception
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
Connection c=DriverManager.getConnection(“jdbc:odbc:student”,” “,” “);
Int r1=11;
String s1=”suhas”;
String str=”insert into studTable values(?,?);
PreparedStatement ps=c.prepareStatement(str);
Ps.setInt(1,r1);
Ps.executeUpdate();
System.out.println(“Data inserted:”);
s.close();
c.close();
}
}
A. Ps.setString(2,s1);
B. Ps.setInt(2,s1);
C. C.setString(2,s1);
D. Ps.setInt(1,s2);
Answer optiona

8. Select the proper code for the problem statement given below:
Problem statement:
Develop a program to change the name of student to “suhas” where rollNo=1 in the table
studTable.
A. Import java.sql.*;
Import java.io.*;
Public class updatedemo
{
Public static void main(String[] args)
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
Try
{
Class.forName(“sun.jdbc.odbc.jdbcodbcDriver”);
System.out.println(“driver loaded”);
String url=”jdbc:odbc:abc”;
Connection con=DriverManager.getConnection(url);
System.out.println(“Conncetion Created”);
String s1=”update studTable set name=’sneha’ where rollNo=1”;
PreparedStatement p1=con.prepareStatement(s1);
P1.executeUpdate();
System.out.println(“updated table”);
P1.close();
Con.close();
}
Catch(Exception e)
{
}
}
}
B. Import java.sql.*;
Import java.io.*;
Public class updatedemo
{
Public static void main(String[] args)
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
Try
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
System.out.println(“driver loaded”);
String url=”jdbc:odbc:abc”;
Connection con=DriverManager.getConnection(url);
System.out.println(“Conncetion Created”);
String s1=”update studTable set name=’sneha’ where rollNo=1”;
PreparedStatement p1=con.prepareStatement(s1);
P1.executeUpdate();
System.out.println(“updated table”);
P1.close();
Con.close();
}
Catch(Exception e)
{
}
}
}
C Import java.sql.*;
Import java.io.*;
Public class updatedemo
{
Public static void main(String[] args)
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
Try
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
System.out.println(“driver loaded”);
String url=”jdbc:odbc:abc”;
Connection con=DriverManager.getConnection(url);
System.out.println(“Conncetion Created”);
String s1=”update table studTable set name=’sneha’ where rollNo=1”;
PreparedStatement p1=con.prepareStatement(s1);
P1.executeUpdate();
System.out.println(“updated table”);
P1.close();
Con.close();
}
Catch(Exception e)
{
}
}
}
D. Import java.sql.*;
Import java.io.*;
Public class updatedemo
{
Public static void main(String[] args)
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
Try
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
System.out.println(“driver loaded”);
String url=”jdbc:odbc:abc”;
Connection con=DriverManager.getConnection(url);
System.out.println(“Conncetion Created”);
String s1=”update studTable set name=’sneha’ where rollNo=1”;
PreparedStatement p1=con.prepareStatement(s1);
P1.execute();
System.out.println(“updated table”);
P1.close();
Con.close();
}
Catch(Exception e)
{
}
}
}
Answer optiona

9. Which of the following is a following statement is a prepared statements ?


A. Insert into department values(?,?,?)
B. Insert into department values(x,x,x).
C. SQLSetConnectOption(conn, SQL AUTOCOMMIT, 0)
D. SQLTransact(conn, SQL ROLLBACK)
Answer optiona

10.Which of the following header must be included in java program to establish


database connectivity using JDBC ?
A. Import java.sql.*;
B. Import java.sql.odbc.jdbc.*;
C. Import java.jdbc.*
E. Import java.sql.jdbc.*;
Answer optiona

11.Which JDBC driver Type(s) can you use in a three tier architecture and if the web
server and the DBMS are running on the same machine
A. Type-1
B. Type-2
C. Type3 and 4
D. All of above
Answer optiond

12. 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” + “ \t “ + “Roll_No” + “ \t “ + “Avg”);
While(rs.next())
{
System.out.println(rs.getString(1)+” \t “+rs.getInt(2)+” \t \t”+rs.getDouble(3));
}
s.close();
c.close();
}
}
A. Missing Semicolon
B. Mising {
C. Mising }
D. Missing Statement
Answer d

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” + “ \t “ + “Roll_No” + “ \t “ + “Avg”);
While(rs.next())
{
System.out.println(rs.getString(1)+” \t “+rs.getInt(2)+” \t \t”+rs.getDouble(3));
}
s.close();
c.close();
}
}
A. Missing Semicolon
B. Missing {
C. Missing }
D. Missing package statement
Answer d

14.In the following JDBC drivers which Is known as partially java driver?
A. JDBC-ODBC Bridge driver
B. Native-API Driver
C. Network Protocol Driver
D. Thin driver
Answer optionb

15.What are types of JDBC driver?


A. JDBC-ODBC bridge
B. JDBC native API
C. Pure java JDBC network
D. All the above
Answer optiona

16. Which of the following is not a component/class of JDBC API?


A. Statement
B. ResultSet
C. SQLException
D. ConnectionPool
Answer optiond

17. If user wants to deal with database stroed procedure then which interface is used?
A. Statement
B. PreparedStatement
C. CallableStatement
D. All of the mentioned
Answer option c

18. Which of the following type of JDBC driver should be used when you are accessing
one type of database, such as Oracle, Sybase, or IBM?
A. Type 1
B. Type 2
C. Type 3
D. Type 4
Answer option d
19. Filling the correct statement:
Import java.sql.*;
Public class createT
{
Public static void main(String a[])
{
Try
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
System.out.println(“Driver Loaded”);
String url=”jdbc:odbc:java”;
Connection con=DriverManager.getConnection(url);
System.out.println(“ Connection to DataBase created”);
Statement stmt=con.createStatement();
String query = “create table employee1(emp_id int,emp_name char)”;
PreparedStatement ps = con.prepareStatement(query)
System.out.println(“table created”);
Ps.close();
Con.close();
}
Catch(SQLException e)
{
e.printStackTrace();
}
Catch(Exception e)
{
e.printStackTrace();
}
}
}
A. Ps.executeUpdate();
B. Ps.executeQuery();
C. Ps.Update()
D. Ps.EXECUTEUPDATE()
Answer optiona

20. Which of the following is also called as Type-I driver


A. Native-API Partly-Java driver
B. JDBC-ODBC Bridge driver
C. JDBC-Net Pure-Java driver
D. Native Protocol 100% Pure-Java driver
Answer optionb

501 Servlets only needs be loaded once, while CGI programs needs to be load for every
request so that servlet should perform faster than
CGI
A. True
B. False
C. only B is correct
D. None of these
Answer optiona
Marks: 2

512 Choose the missing statement in the given method syntax


public void doGet(HttpServletRequest request, HttpServletResponse response) throws
____________
A. ServletException,IOException
B. URLMalformedException
C. SecurityException
D. SQLException
Answer optiona
Marks: 2

513 Which packages needs to be imported to execute the given program


public class First extends GenericServlet{
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. import java.io.*;
import javax.servlet.*;
B. import java.io.*;
C. import javax.servlet.*;
D. import java.lang.*;
Answer optiona
Marks: 2

514 Which method returns the current session associated with this request, or if the
request does not have a session, creates one?
A. getSession()
B. getServletPath()
C. getCookies()
D. getPathInfo()
Answer optiona
Marks: 2
515 Which are the methods of servlet life cycle?
A. init(),destroy()
B. init(),service(),destroy()
C. init(),end()
D. init(),start(),destroy()
Answer optionb
Marks: 2

540 Where the servlets run?


A. on client side
B. on server side
C. on proxy side
D. on database side
Answer optionb
Marks: 1

541 Which method is called on every servlet request ?


A. init()
B. doGet()
C. doPost()
D. service()
Answer optiond
Marks: 1

546 Which method of the servlet is/are called several times in its life?
A. init()
B. service()
C. destroy()
D. Both (i) and (ii)
Answer optionb
Marks: 2

550 The values of <servlet-name> and <servlet-class> in web.xml file 􀀁􀀁


A. must be same
B. must not be same
C. may be same
D. none of these
Answer optionc
Marks: 2

561 Select the package used to import the abstract class


HttpServlet and interfaces HttpServletRequest and HttpServletResponse
A. import javax.servlet.http.*
B. import javax.servlet.*
C. import java.io.*
D. none of the above
Answer optiona
Marks: 2

571 Choose missing statements in following code from given options


public class HelloWorld extends HttpServlet
{p
rivate String message;
public void init()
throws ServletException
{
message ="Hello World";
}p
ublic void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out= response.getWriter();
out.println("<h1>"+ message +"</h1>");
}}
publicvoid destroy()
{}
A.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
B. import java.Vector.* ; import java.Thread.*; import javax.servlet.*;
C. import javax.servlet.http.*; import java.String.*; import java.Vector;
D. import javax.servlet.http.*; import java.Thread.*; import javax.Client.*;
Answer optiona
Marks: 2

572 Select the missing statement to get the correct output


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SessionIdServlet extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException
{
response.setContentType("text/html");
printWriter pw=response.getWriter();
HttpSession session=request.getSession();
String id=session.getId();
pw.println("Session Id is:"+ id)
}
A. missing semicolon,missing }
B. missing semicolon
C. missing }
D. missing semicolon,missing {
Answer optiona
Marks: 2

573 Select the missing statement to get correct output


public class welcomeservelet extends GenericServlet
{p
ublic void service(ServletRequest request,ServletResponce response)
throws ServletException,IOException
{r
esponse.setContentType("text/html");
printWriter pw =response.getWriter();
pw.println("<B>welcome to servlet!");
pw.close();
}}
A. import java.io.*; import javax.servlet.*;
B. import java.io.*;
C. import java.servlet.*;
D. none of the above
Answer optiona
Marks: 2

589 Which method are central to life cycle of a servlet?


A. init(), service() and destroy()
B. init(), paint() and destroy()
C. init(), start() and stop()
D. init(), service() and paint()
Answer optiona
Marks: 1

590 A cookie is stored on __________ and contains state information.


A. client machine
B. web server
C. dns server
D. All of the above
Answer optiona
Marks: 1

591 If an expiration date is not explicitly assigred to a cookie __________


A. it is permanently stored
B. it is never stored
C. it is deleted when the current browser session ends
D. it is deleted when internet access is lost
Answer optionc
Marks: 1

596 Following are the life cycle methods of servlet:


1. service()
2. init()
3. destroy()
Select the correct sequence in which these methods are executed during life cycle of a
particular servlet.
A. 1, 2,3
B. 2, 1,3
C. 2, 3,1
D. 1, 3, 2
Answer optionb
Marks: 2

597Cookies and Sessions can be created and used with:


A. Generic servlets
B. Http servlets
Select correct option from following.
A. Both A and B
B. Only A
C. Only B
D. None of the above
Answer optionc
Marks: 2

611 Consider the following program. Fill the missing(*******) statement.


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SessionIdServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws
ServletException, IOException
{
**************
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.print("<B>");
pw.print("Your session Id:"+hs.getId());
}
}
A. HttpSession hs = response.setSession(true);
B. HttpSession hs = request.getSession(true);
C. HttpSession hs = request.addSession();
D. HttpSession hs = reponse.insertSession();
Answer optionb
Marks: 2

612 Choose the missing statements in following code from given options.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class WritingCookies extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws
ServletException, IOException
{
Cookie cookie = new Cookie("dept-codes","CO-CD-CM-IF");
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("One cookie is set.");
pw.close();
}
}
A. response.insertCookie(cookie);
B. response.addNewCookie(cookie);
C. response.setCookie(cookie);
D. response.addCookie(cookie);
Answer optiond

You might also like