QB CT2 AJP

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

SECOND CLASS TEST 2024– 2025

Covered: CO4,CO5,CO6
SUBJECT: Advance Java Programming
QUESTION BANK (CO COVERED CO 4,5,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. What is the purpose of the `PreparedStatement` interface in JDBC?


a) To connect to the database b) To store query results c) To precompile SQL statements d) To
execute DDL commands

8. Which method is used to establish a connection to the database in JDBC?


a) createConnection() b) openConnection() c) getConnection() d) establishConnection()

9. Which of the following is not a valid SQL data type in JDBC?


a) VARCHAR b) INT c) DOUBLE d) BOOLEAN

10. What is the purpose of the `Statement` interface in JDBC?


a) To connect to the database b) To execute SQL queries c) To precompile SQL statements d)
To store query results

11. In JDBC, which exception is thrown when there is a problem with the SQL syntax?
a) SQLException b) SQLSyntaxException c) SQLQueryException d) SyntaxError

12. Which method is used to execute a query in JDBC and retrieve the results in a `ResultSet`?
a) executeQuery() b) executeUpdate() c) execute() d) executeBatch()

13. What is the purpose of the `Connection` interface in JDBC?


a) To execute SQL queries b) To store query results c) To manage the connection to the database
d) To compile SQL

14. In JDBC, what is the role of the `DriverManager` class?


a) To establish a connection to the database b) To execute SQL queries
c) To manage the result set d) To manage the connection pool database

15. Which of the following is not a JDBC driver?


A. MySQL Connector/J B. PostgreSQL JDBC Driver C. Microsoft SQL Server JDBC Driver D.
ODBC Driver

16. Which of the following is used to create a JDBC connection to a database?


A. DriverManager.getConnection() B. Connection.getConnection()
C. Statement.getConnection() D. PreparedStatement.getConnection()

17. Which of the following is used to execute an SQL query in JDBC?


A. Statement.executeQuery() B. Connection.executeQuery()
C. PreparedStatement.executeQuery() D. ResultSet.executeQuery()

18. Which of the following is used to close a JDBC connection?


A. Connection.close() B. Statement.close() C. PreparedStatement.close() D. ResultSet.close()

19. Which are the session tracking techniques?


i. URL rewriting ii. Using session object
iii.Using response object iv. Using hidden fields
v. Using cookies vi. Using servlet object
A)i, ii, iii, vi B)i, ii, iv, v
C)i, vi, iii, v D)i, ii, iii, v

20.Which of the following is used to execute an SQL query in


JDBC?
A) A. Statement.executeQuery() B)Connection.executeQuery()
C)PreparedStatement.executeQuery( D)ResultSet.executeQuery()
)

21. Which of the following is a benefit of using a PreparedStatement in JDBC?


A. It prevents SQL injection. B. It improves performance. C. Both A and B. D. None of the
above.

22. Which of the following is a JDBC transaction?


A. A sequence of database operations that are treated as a single unit. B. A way to rollback
database changes if an error occurs.
C. Both A and B. D. None of the above.

23 Which of the following is a JDBC connection isolation level?


A. READ UNCOMMITTED B. READ COMMITTED C. REPEATABLE READ
D. SERIALIZABLE E. All of the above
24. Which of the following is a JDBC savepoint?
A. A point in a transaction where you can rollback to if an error occurs.
B. A way to commit a subset of the changes made in a transaction.
C. Both A and B.
D. None of the above.

25. Which of the following is a JDBC batch update?


A) A way to execute multiple SQL statements at once. B) A way to improve the performance of
bulk database operations.
C) Both A and B. D). None of the above.

26.Name the class which is used to create a port where the server will listen.
A)Server B)Socket
C)ServerSocket D) SocketServer

27. 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

28. In Java, which class is commonly used to establish a server socket for network
communication?
A. Socket B. ServerSocket C. DatagramSocket D. InetAddress

29.IPv6 uses _________


A)4 groups of 8 bits each B) 4 group of 8 hexa‐decimal digits
C) 8 groups of 4 digits each D)8 groups of 4 hexa‐decimal digits
each

30.Select the method used to create URL connection.


A)URL Connection B)open Connection
c) URL D) URL Decoder

31. Which Java package provides classes for working with sockets and networking?
A. java.net B. java.io C. java.lang D. java.util

32.The URLConnection class can be used to read and write data to the specified
resource referred by the URL?
A) True B)False

33.URL is an acronym for?


A)Uniform Resource Locator B)Unified Resource Locator
C)Uniform Restore Locator D)Unified Restore Locator

34.Which of the following is not a type of JDBC driver?


A)100% pure Java Driver (c) B)JDBC–net pure Java Driver
C)JDBC- Native API driver D)JDBC–Native pure Java Driver
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

37. 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

38. Which protocol is typically used for sending email in Java applications?
A. HTTP B. FTP C. SMTP D. POP3

39.Database programming using Java throws which of the following exception?


A)SQLException B)ClassNotFoundException
C) None of these D) Both of these

40.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

41.Which of the following is used to close a JDBC connection?


A)Connection.close() B)Statement.close()
C)PreparedStatement.close() D)ResultSet.close()

42. Which Java class is used to represent an IP address?


A. IPAdress B. InetAddress C. IPHost D. HostAddress

43.Which of these is a full form of DNS?


A.Data Network Service B.Data Name Service
C.Domain Network Service D.Domain Name Service

44.Which is main component of JDBC API?


A)DriverManager B)Driver
C)Connection D) All of these

45.Which of the following is NOT a valid method of managing session tracking in


servlets?
A)Using cookies B) Using URL rewriting
C)Using session IDs d D) Using request attributes

46.Servlets handle multiple simultaneous requests by using threads.


A) true B) false
C) None D) All

47.What is the purpose of the `HttpServletResponse.sendError()` method?


A)To send a redirect response B)To send an error response with a
specified status
C)To send an error response with a status D) To send a response with no content
code of 200 OK

48.Which HTTP methods can a servlet handle?

A)GET and POST B) b) GET, POST, PUT, and DELETE


C) GET, POST, and UPDATE D)GET, POST, DELETE, and MODIFY
49.Which package provides the classes for servlets?
A) a) javax.servlet B) java.servlet
C) javax.server D)java.server

50.How constructor can be used for a servlet?


A)Initialization B)Constructor function
C) Initialization and Constructor function D)Setup() method

51. Check whether the following code is correct or not?


import javax.net.*;
public class Net1
{
public static void main(String args[])throws Exception
{
URL u=new URL("https://www.google.com");
System.out.println("Protocol: "+u.getProtocol());
System.out.println("Port: "+u.getPort());
System.out.println("Host: "+u.getHost());
System.out.println("File: "+u.getFile());
System.out.println("Ref: "+u.getRef());
System.out.println("Exit: "+u.getExternalForm());
}
}
a. Correct b. Incorrect

52.What is the difference between servlets and applets?


i. Servlets execute on Server; Applets execute on browser
ii. Servlets have no GUI; Applet has GUI
iii. Servlets creates static web pages; Applets creates dynamic web pages
iv. Servlets can handle only a single request; Applet can handle multiple requests
A)i, ii, iii are correct B) i, ii are correct
C)i, iii are correct D)i, ii, iii, iv are correct
53. Check out whether the following code contains error(s) or not.
import javax.net.*;
public class Net1
{
public static void main(String arg[])throws MaiformedURLException
{
URL u=new URL("https://www.google.com");
System.out.println("Protocol: "+u.getProtocol());
System.out.println("Port: "+u.getPort());
System.out.println("Host: "+u.getHost());
System.out.println("File: "+u.getFile());
System.out.println("Ref: "+u.getRef());
System.out.println("Exit: "+u.getExternalForm());
}
}
a. No Errors Present b.Errors Present
54. Check out whether the following code contains error(s) or not.
import java.io.*;
import java.net.*;
import java.util.Date;
public class URLINFORMATION
{
public static void main(String args[])
{
URL =new URL("http://www.msbte.com");
URLConnection con = url.openConnection();
System.out.println("");
System.out.println(url);
System.out.println("Date:"+new Date(con.getDate()));
System.out.println("Content-Type"+con.getContentType());
System.out.println("Expiers:"+con.getExpiration());
System.out.println("Last-Modified:"+new Date(con.getLastModified()));
int len = con.getContentLength();
System.out.println("Content-Length:"+len);
}
}
a. In URLConnection Line b. In URlCreation Line
c. Both (a) and (b) d. None

You might also like