Imp Questions AJP

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

Unit-4

1. In following statement rs is an object of _____________ interface of JDBC API.


System.prinln(rs.getString(3)).
(a) RowSet (b) Statement (c) Connection (d) ResultSet
2. Which is main component of JDBC API?
(a) DriverManager (b) Driver (c) Connection (d) All of these
3. How many steps are used to connect any java application with the database using
JDBC ?
(a) 5 (b) 4 (c) 3 (d) 6
4. ODBC minimum SQL grammer contains____
(a) Stored procedure (b) Data, Time and TimeStamp only (c) create or drop View (d)
Insert, update, delete only
5. Which class/interface is used for an SQL statement that is executed frequently?
(a) Statement (b) CallableStatement (c) PreparedStatement (d) None of the above
6. What does the following code do : smt = con.createStatement( )
(a) A PreparedStatement object is created to send SQL commands to database
(b) A Statement object is created to send SQL commands to database.
(c) A CallableStatement is created to send SQL commands to database
(d) A Statement object is created to execute parameterized SQL commands.
7. Which kind of driver converts JDBC calls into calls on the Client API for
Oracle, Sybase, Informix, IBM DB2, or other DBMS
(a) JDBC ODBC bridge + ODBC Driver (b) Native API partly ñ Java Driver
(c) JDBC ñ Net pure Java Driver (d) Native Protocol Pure Java Driver
8. Which method executes an SQL statement that may return multiple results?
(a) executeUpdate( ) (b) executeQuery( ) (c) execute( ) (d) noExecute( )
9. Identify correct syntax of executeQuery( ) of Statement interface.
(a) public static ResultSet executeQuery( ) (b) public ResultSet
executeQuery(String q)
(c) public void executeQuery(String q) (d) public int executeQuery(String q)
10. Native API converts __ into the __ used by DBMS.
(a) JDBC API, Network Protocol (b) JDBC API, Native API calls(c) JDB
(c) API, use calls (d) JDBC API, ODBC API calls
11. Which of the following function is used to find the column count of the
particular ResultSet.
(a) getMetadata( ) (b) metadata( ) (c) getColumnCount( ) (d) getCount( )
12. In JDBC ______________ imports all Java classes that are concern with Database
connectivity.
(a) javax.sql (b) java.mysql (c) java.sql (d) com.sql
13. The __________ package contains classes that help in connecting to a database,
sending SQL statements to the database and
process the query request.
(a) connection.sql (b) db.sql (c) pkg.sql (d) java.sql
14. Which of the following is not a type of JDBC driver?
(a) 100% pure Java Driver (b) JDBC – net pure Java Driver
(c) JDBC – Native API driver (d) JDBC – Native pure Java Driver
15. Database programming using Java throws which of the following exception?
(a) SQLException (b) ClassNotFoundException (c) None of these (d) Both of these
16. 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
17. 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
18. 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
19. 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
20. SQL stands for __________.
(a) Structured Query Language (b) Sequential Query Language
(c) Structured Question Language (d) Sequential Question Language
21. _____________ is a table of data which represents a data from table.
(a) MetaData (b) ResultSetMetaData (c) ResultSet (d) Statement
22. Public class DriverManager extends ____________.
(a) Object (b) String (c) Connection (d) Statement
23. Which of the following method is supported by Statement interface?
(a) public boolean execute(String query) (b) public ResultSet executeQuery(String
query)
(c) public int executeUpdate(String query) (d) All of above
24. The JDBC‐ODBC bridge supports how many concurrent open statements per
connection ?
(a) 1 (b) 0 (c) Does not support conection (d) None of these
25. Select the correct method to create CallableStatement.
(a) CallableStatement prepareCall(String sql)
(b) CallableStatement prepareCall(String sql, int resultset type, int
resultset_concurrency)
(c) CallableStatement prepareCall(String sql, int resultset_type, int
resultset_concurrency, int resultset_holdability)
(d) All of the above
26. Microsoft Access data in _______ file format.
(a) .DAT (b) .MDB (c) .MSSQL (d) .OBJ
27. Which of the following method is used for send SQL statements?
(a) Statement (b) CallableStatement (c) PreparedStatement (d) Both B & C
28. DELETE statement of an SQL is executed by ________.
(a) execute( ) (b) executeQuery( ) (c) executeUpdate( ) (d) executeDelete()
29. The interface to the database is handle by _____.
(a) ODBC (b) JDBC (c) JDBC & ODBC (d) APIs
30. DatabaseMetadata are retrieved through ___________.
(a) getDatabaseMetadata( ) (b) getMetaData( ) (c) getDBMetaData( ) (d)
getDatabaseMeta( )
31. Which method is used to retrieve the ResultSet created?
(a) executeQuery( ) (b) getResultSet( ) (c) getResultSetResult( ) (d) getResult( )
32. Which of the following is used generally for reading the content of the
database?
(a) DabaseData (b) DabaseData (c) ResultSet (d) DatabaseResult.
33. The syntax to create a table named “Course”, should begin with __________.
(a) create new table course (b) create table course (c) table course create (d) new
table course
34. Which of the following contains both date and time?
a) java.io.date b) java.sql.date c) java.util.date d) java.util.dateTime
35. Which of the following is advantage of using JDBC connection pool?
a) Slow performance b) Using more memory c) Using less memory d) Better performance
36. Which of the following is advantage of using PreparedStatement in Java?
a) Slow performance b) Encourages SQL injection c) Prevents SQL injection d) More
memory usage
37. Which one of the following contains date information?
a) java.sql.TimeStamp b) java.sql.Time c) java.io.Time d) java.io.TimeStamp
38. What does setAutoCommit(false) do?
a) commits transaction after each query b) explicitly commits transaction
c) does not commit transaction automatically after each query d) never commits
transaction
39. Which of the following is used to call stored procedure?
a) Statement b) PreparedStatement c) CallableStatment d) CalledStatement
40. Which of the following is used to limit the number of rows returned?
a) setMaxRows(int i) b) setMinRows(int I) c) getMaxrows(int i) d) getMinRows(int i)

Unit-5
1. What does the acronym "HTTP" stand for in the context of web communication?
A. Hyperlink Transfer Protocol B. Hypertext Transfer Protocol
C. Hyper Transfer Text Protocol D. High-Speed Text Protocol
2. In Java, which class is commonly used to establish a server socket for network
communication?
A. Socket B. ServerSocket C. DatagramSocket D. InetAddress
3. Which Java package provides classes for working with sockets and networking?
A. java.net B. java.io C. java.lang D. java.util
4. Which protocol is typically used for sending email in Java applications?
A. HTTP B. FTP C. SMTP D. POP3
5. Which Java class is used to represent an IP address?
A. IPAdress B. InetAddress C. IPHost D. HostAddress
6. What is the purpose of the "URLConnection" class in Java?
A. To represent a URL connection B. To establish a secure SSL connection
C. To handle HTTP requests and responses D. To encode and decode URLs
7. In Java, which protocol is used for transferring files over the network?
A. HTTP B. FTP C. TCP D. UDP
8. Which Java class is used to read and write binary data over a network stream?
A. BufferedReader B. BufferedWriter C. ObjectInputStream D.DataInputStream
9. What is the role of the "SocketTimeoutException" in Java networking?
A. It indicates a successful network connection.
B. It occurs when a socket is closed gracefully.
C. It signals a timeout when waiting for data on a socket.
D. It represents an error in the socket's IP address.
10. Which Java class allows you to create and manage URL objects?
A. URLBuilder B. URLManager C. URLEncoder D. URLConnection

11. What does HTTP stand for in the context of networking?


a) Hyper Transfer Text Protocol b) Hypertext Transfer Protocol
c) Hyperlink Text Transfer Protocol d) Hypertext Transmission Protocol
12. Which Java class is used for creating network sockets?
a) Socket b) ServerSocket c) DatagramSocket d) InetAddress
13. Which protocol is commonly used for sending email in Java applications?
/60
a) FTP b) SMTP c) HTTP d) Telnet
14. In Java, which class is used to represent an IP address?
a) IP b) IPAddress c) InetAddress d) InetAddressUtils
15. Which Java library is commonly used for making HTTP requests?
a) java.net b) javax.servlet c) java.http d) java.httpclient
16. What does DNS stand for?
a) Dynamic Network System b) Domain Name System c) Data Network Service d) Digital
Network Security
17. Which port is commonly used for HTTP communication?
a) 21 b) 80 c) 443 d) 8080
18. Which Java class is used for handling UDP (User Datagram Protocol)
communication?
a) DatagramSocket b) UDPSocket c) DatagramConnection d) UDPConnection
19. Which Java class is used for reading from and writing to streams?
a) Stream b) InputStream c) OutputStream d) StreamReader
20. What is the primary purpose of a firewall in a network?
a) To increase network speed b) To block all incoming and outgoing traffic
c) To protect the network from unauthorized access and threats d) To reroute
network traffic
21. Which Java method is used to establish a connection to a remote server using
TCP/IP?
a) connect() b) open() c) accept() d) bind()
22. Which protocol is used for secure communication over the internet?
a) SSL b) HTTP c) FTP d) Telnet
23. What is the purpose of the InetAddress class in Java?
a) To represent IP addresses b) To establish socket connections c) To send emails
d) To read from files
24. Which of the following is not a valid IP address format?
a) 192.168.1.1 b) 300.200.100.50 c) 10.0.0.1 d) 172.16.0.0
25. Which Java class is used for creating a server socket?
a) SocketServer b) ServerSocket c) TCPServer d) NetworkServer
26. In Java, which protocol is commonly used for sending and receiving email?
a. FTP b. SMTP c. HTTP d. POP3
27. What is the purpose of the HttpURLConnection class in Java?
a. To connect to a database b. To establish a secure connection
c. To work with HTTP connections d. To create a UDP socket
28. Which Java class is used for reading and writing data to a network socket?
a. ServerSocket b. Socket c. DatagramSocket d. InputStreamReader
29. In Java networking, what is the purpose of the InetAddress.getByName() method?
a. To get the IP address of a domain name b. To retrieve the host's hostname
c. To set the local host's IP address d. To create a new InetAddress object
30. What is the role of the java.net.URL class in networking?
a. To read and write files locally b. To manage database connections
c. To represent a Uniform Resource Locator d. To encrypt data during transmission
31.Which Java package is commonly used for socket programming?
a. java.sql b. java.io c. java.util d. java.net
32. Which exception is typically thrown when a network operation fails in Java?
a. NetworkException b. IOException c. MalformedURLException d. DataFormatException
33. Which Java class is commonly used to establish a client-server connection for
network communication?
a) Socket b) Datagram c) URLConnection d) HttpRequest
34. Which of these class is used to encapsulate IP address and DNS?
a) DatagramPacket b) URL c) InetAddress d) ContentHandler
35. Which class is used to create servers that listen for either local client or
remote client programs?
a. ServerSockets b. httpServer c. httpResponse d. None of the above
36. What does IP stand for in networking?*
a. Internet Protocol b. Internet Port c. Internal Protocol d. Internet Portability
37. Which class in Java allows you to create a client socket?
a. ServerSocket b. Socket c. DatagramSocket d. InetAddress
38. Which socket type is used for UDP communication in Java?
a. DatagramSocket b. ServerSocket c. Socket d. MulticastSocket
39. What is the main advantage of TCP over UDP in networking?
a. Lower latency b. Connection-oriented c. Suitable for broadcasting d. Simple
error handling
40. Which of these class is used to encapsulate IP address and DNS?
a) DatagramPacket b) URL c) InetAddress d) ContentHandler

Unit-6
1. What is a servlet in Java?
a) A type of coffee b) A server-side Java program c) A type of Java class d) A type
of Java exception
2. Which package provides the classes for servlets?
a) javax.servlet b) java.servlet c) javax.server d) java.server
3. Which HTTP methods can a servlet handle?
a) GET and POST b) GET, POST, PUT, and DELETE
c) GET, POST, and UPDATE d) GET, POST, DELETE, and MODIFY
4. In which method should you override to handle GET requests in a servlet?
a) doGet() b) doPost() c) doRequest() d) handleGet()
5. Which of the following is not a servlet life cycle method?
a) init() b) service() c) destroy() d) run()
6. What is the purpose of the `init()` method in a servlet?
a) To perform cleanup tasks before the servlet is destroyed b) To handle client
requests
c) To initialize the servlet before serving client requests d) To redirect requests
to other servlets
7. Which method is responsible for destroying a servlet?
a) finalize() b) destroy() c) close() d) cleanup()
8. What is the default scope of a servlet?
a) Request b) Session c) Application d) Page
9. Which object represents a client's request to the servlet container?
a) HttpServletRequest b) HttpServletResponse c) ServletContext d) HttpSession
10. Which method can be used to send a response to the client in a servlet?
a) getRequest() b) sendResponse() c) getResponse() d)
HttpServletResponse.getWriter()
11. How can you obtain the value of a request parameter in a servlet?
a) Using the `request.getAttribute()` method b) Using the `request.getParameter()`
method
c) Using the `request.getSession()` method d) Using the `request.getAttribute()`
method
12. What is the default URL mapping for a servlet in web.xml?
a) /servlet/* b) /servlets/* c) /app/* d) /servlet-name/*
13. What is the purpose of the `web.xml` file in a servlet application?
a) To configure servlet mappings b) To define servlet classes
c) To specify HTML templates d) To store database connection details
14. Which HTTP status code indicates that a resource is not found?
a) 200 OK b) 302 Found c) 404 Not Found d) 500 Internal Server Error

/ 63
15. Which interface must a servlet implement to handle session events?
a) HttpSessionListener b) HttpSessionAttributeListener
c) ServletContextListener d) ServletRequestListener
16. How can you store session data in a servlet?
a) Using the `HttpServletRequest` object b) Using the `ServletContext` object
c) Using the `HttpSession` object d) Using the `HttpServletResponse` object
17. What is the purpose of the `ServletContext` in a servlet application?
a) To store session data b) To manage the servlet life cycle
c) To share data among servlets d) To store servlet configuration parameters
18. How can you set an attribute in the `ServletContext` in a servlet?
a) Using the `setContextAttribute()` method b) Using the `setAttribute()` method
c) Using the `addAttribute()` method d) Using the `context.set()` method
19. What is the purpose of the `RequestDispatcher` interface in servlets?
a) To send an HTTP request to another server
b) To include the content of another resource in the response
c) To forward the request to another resource within the same servlet context
d) To send a response to the client
20. Which of the following is NOT a valid way to create a servlet in Java?
a) Extending the `HttpServlet` class b) Implementing the `Servlet` interface
c) Using the `new` keyword d) Extending the `GenericServlet` class
21. What is a servlet filter used for?
a) To process requests before they reach a servlet b) To filter out invalid HTTP
methods
c) To filter out client IP addresses d) To filter out invalid session data
22. Which of the following is true about servlet filters?
a) Filters can only be used with servlets and not with JSP.
b) Filters can modify the response but not the request.
c) Filters cannot change the order of execution of servlets.
d) Filters can be configured in the web.xml file.
23. What is the purpose of the `doFilter()` method in a servlet filter?
a) To forward the request to another servlet b) To send a response to the client
c) To process the request and response d) To destroy the filter
24. How can you invalidate a session in a servlet?
a) session.invalidate() b) session.invalidateSession() c) session.destroy() d)
session.remove()
25. Which of the following is NOT a valid method of communication between servlets?
a) Using the `ServletContext` b) Using the `HttpServletResponse`
c) Using the `RequestDispatcher` d) Using HTTP sessions
26. What is the purpose of the `javax.servlet.annotation.WebServlet` annotation?
a) To define a servlet class b) To configure servlet mappings c) To specify request
parameters d) To declare a servlet filter
27. Which HTTP method is used to retrieve data from the server in a safe and
idempotent way?
a) GET b) POST c) PUT d) DELETE
28. Which method is called when a session is created in a servlet?
a) sessionCreated() b) sessionInitialized() c) initSession() d) createSession()
29. How can you obtain the session ID in a servlet? a)
session.getSessionID() b) session.getID() c) session.getId() d)
session.getSessionId()
30. What is the purpose of the `ServletContext.getAttribute()` method?
a) To retrieve a session attribute b) To retrieve a request attribute
c) To retrieve a servlet context attribute d) To retrieve a response attribute
31. What is the purpose of the `HttpServletRequest.setAttribute()` method?
a) To set a session attribute b) To set a request attribute
c) To set a servlet context attribute d) To set a response attribute
32. Which of the following is NOT a valid HTTP status code?
a) 200 OK b) 300 Redirect c) 400 Bad Request d) 500 Internal Server Error
33. What is the purpose of the `ServletContext.getInitParameter()` method?
a) To retrieve a servlet's initialization parameter b) To retrieve a session
attribute
c) To retrieve a request attribute d) To retrieve a servlet context attribute
34. What is the purpose of the `HttpServletResponse.setContentType()` method?
a) To set the HTTP response status code b) To set the content length of the
response
c) To set the content type of the response d) To send a redirect response
35. Which of the following is NOT a valid content type for an HTTP response?
a) text/html b) application/json c) image/png d) audio/mp3
36. What is the purpose of the `ServletContext.getContextPath()` method?
a) To retrieve the context path of a servlet b) To retrieve the context path of a
session
c) To retrieve the context path of a request d) To retrieve the context path of the
servlet container
40. What is the purpose of the `HttpServletResponse.setStatus()` method?
a) To set the HTTP response status code b) To set the content type of the response
c) To set the character encoding of the response d) To set the content length of
the response

You might also like