WorksheetsPower Test MCQ
Total questions: 25
Worksheet time: 38mins
Name
Class
Date
1.
What is the difference between a servlet and a JSP in JEE?
a)
Servlets are for handling user requests, while JSPs are for presentation logic.
b)
Servlets are for database access, while JSPs are for user interaction.
c)
Servlets are server-side code, while JSPs are client-side code.
d)
Servlets are for static content, while JSPs are for dynamic content.
2.
Which of the following methods of the javax.servlet.Servlet interface is responsible for initializing the servlet?
a)
init(ServletConfig config)
b)
initialize(ServletConfig config)
c)
start(ServletConfig config)
d)
setup(ServletConfig config)
3.
Which of the following url represents core tag library?
a)
http://java.sun.com/jsp/jstl/core
b)
http://java.sun.com/jsp/jstl/functions
c)
http://java.sun.com/jsp/jstl/fmt
d)
http://java.sun.com/jsp/jstl/sql
4.
In the MVC architecture, what is the primary responsibility of the Model?
a)
Rendering data to the user interface
b)
Handling user inputs and events
c)
Storing and managing application data
d)
Controlling the flow of the application logic
5.
How can you access a request parameter passed from an HTML form in a JSP page?
a)
By directly referencing the parameter name in the HTML code.
b)
Using a custom JSP tag specifically for that parameter.
c)
Employing the request.getParameter("parameterName") method.
d)
Accessing it through a session attribute created in the servlet.
6.
Which of the following is a part of JSTL Formatting Tag Library?
a)
import
b)
forEach
c)
parseDate
d)
endsWith
7.
What is the role of the tag in a JSP page?
a)
To create a new session object.
b)
To forward a request to another servlet.
c)
To create or access a Java bean object for data manipulation.
d)
To iterate through a collection of items.
8.
What is the correct tag symbol of JSP declaration?
a)
<%@ %>
b)
<%= %>
c)
<%! %>
d)
<% %>
9.
Which is the correct program to retrive root path?
a)
request.getContextPath();
b)
context.contextPath
c)
Both A and B
d)
None of the above.
10.
What is the primary purpose of using sessions in a Java web application?
a)
To maintain user state across multiple requests within a single user session.
b)
To manage database connections for efficient data access.
c)
To define security constraints and user roles for authorization.
d)
To handle file uploads and temporary storage of uploaded data.
11.
Which keyword is used to create a subclass in Java?
a)
super
b)
this
c)
extends
d)
subclass
12.
Which of the following statements accurately describes Servlet Filters?
a)
Servlet Filters are used to modify the response content before sending it back to the client.
b)
Servlet Filters are primarily used to replace servlets in processing client requests.
c)
Servlet Filters can only intercept requests and cannot manipulate responses.
d)
Servlet Filters are configured using the web.xml file and cannot be programmatically controlled.
13.
How can you retrieve a cookie sent by the client in a Java servlet?
a)
Using the getCookies() method of the HttpServletResponse object.
b)
By parsing the HTTP header information directly.
c)
By iterating through system environment variables.
d)
Using the getCookies() method of the HttpServletRequest object
14.
Which of the following is NOT a common approach for managing state in a Java web application?
a)
Session Management
b)
Application Scope Attributes
c)
Hidden Form Fields
d)
Client-Side Cookies
15.
Select the correct approach to declare mysql localhost path in DriverManager.getConnection() method.
a)
mysql://localhost:3306/databaseName
b)
jdbc:oracle://localhost:3306/databaseName
c)
oracle://localhost:3306/databaseName
d)
jdbc:mysql://localhost:3306/databaseName
16.
Which method is used to execute a query that retrieves data from a database?
a)
int result = statement.executeUpdate(query);
b)
Connection connection = statement.executeQuery(query);
c)
ResultSet resultSet = statement.executeQuery(query);
d)
Statement statement = connection.prepareStatement(query);
17.
What is the primary purpose of using JSTL in JSP pages?
a)
To establish database connections and perform database operations.
b)
To provide a set of standardized tags for common tasks like iteration and conditional logic.
c)
To define custom tags for reusable components specific to your application.
d)
To directly access and manipulate the servlet container lifecycle.
18.
What is the benefit of using the tag for conditional logic in a JSP page?
a)
It offers a more concise syntax compared to scriptlets with if statements.
b)
It provides built-in security features to prevent code injection vulnerabilities.
c)
It automatically performs null checks on variables used in the condition.
d)
All of the above (a, b, and c).
19.
Which is the accurate approach to create a final variable?
a)
public static String VARIABLE_NAME = "value";
b)
public static final String VARIABLENAME = "value";
c)
public static final String VARIABLE_NAME = "value";
d)
public final String VARIABLENAME = "value";
20.
What does the shown program does?
- chain.doFilter(request, response);
a)
It revokes the request filter
b)
It invokes the AuthenticationFilter class.
c)
It allows access to requested resource
d)
It prevents user to access requested resource
21.
Which of the following requests is best suited for executing an update query?
a)
GET request
b)
POST request
c)
DELETE request
d)
PUT request
22.
Which of the following statements is most accurate about asynchronous workflows in Java?
a)
They block the main thread until all tasks are completed.
b)
They allow tasks to be executed concurrently without blocking the main thread.
c)
They are always slower than synchronous workflows.
d)
They cannot be used with I/O operations.
23.
Which of the following annotations is used to define a URL pattern in a Java servlet?
a)
@RequestMapping
b)
@WebServlet
c)
@GetMapping
d)
@Controller
24.
Which of the following SQL statements correctly uses the LIKE operator to find all customers with names starting with "Aaryan"?
a)
SELECT * FROM Customers WHERE Name = 'Aaryan%';
b)
SELECT * FROM Customers WHERE Name LIKE 'Aaryan%';
c)
SELECT * FROM Customers WHERE Name = '%Aaryan';
d)
SELECT * FROM Customers WHERE Name CONTAINS 'Aaryan';
25.
How can you retrieve the username and product name from orders placed by users who live in "Kathmandu"?
a)
SELECT o.Username, p.ProductName FROM Users u JOIN Orders o ON u.UserID = o.UserID JOIN Products p ON o.ProductID = p.ProductID WHERE u.State = 'Kathmandu';
b)
SELECT * FROM Users WHERE State = 'Kathmandu';
c)
SELECT o.OrderID, p.ProductID FROM Orders o JOIN Products p ON o.ProductID = p.ProductID;
d)
This cannot be achieved with a single query.
100 %
