0% found this document useful (0 votes)
52 views27 pages

Full 60 MCQ Oop JSP JSTL JDBC

The document contains a series of questions and answers related to Java programming, covering topics such as OOP principles, JSP, JSTL, JDBC, SQL, and MVC architecture. Each question is followed by multiple-choice options, with the correct answer provided. It serves as a study guide for individuals preparing for Java-related assessments or interviews.

Uploaded by

burakdeniz810
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)
52 views27 pages

Full 60 MCQ Oop JSP JSTL JDBC

The document contains a series of questions and answers related to Java programming, covering topics such as OOP principles, JSP, JSTL, JDBC, SQL, and MVC architecture. Each question is followed by multiple-choice options, with the correct answer provided. It serves as a study guide for individuals preparing for Java-related assessments or interviews.

Uploaded by

burakdeniz810
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/ 27

Section 1: Questions Only

1. Which OOP principle focuses on wrapping data and methods together?

A. Inheritance

B. Polymorphism

C. Encapsulation

D. Abstraction

2. What does method overriding achieve in Java?

A. Compile-time polymorphism

B. Hiding parent method

C. Run-time polymorphism

D. Data hiding

3. Which keyword is used for inheritance in Java?

A. implements

B. inherits

C. extends

D. override

4. Which of the following is an example of abstraction?

A. A class with private variables

B. An interface with only method signatures

C. Method overloading

D. Object instantiation

5. Which concept allows multiple methods with the same name but different parameters?

A. Overriding

B. Overloading

C. Encapsulation
D. Inheritance

6. Which of the following is a directive tag in JSP?

A. <jsp:include>

B. <%@ page import="java.util.*" %>

C. <%= user.getName() %>

D. <%! int count; %>

7. What is the output of <%= 5 + 3 %> in a JSP file?

A. Nothing

B. 53

C. 8

D. Compilation error

8. Where is the Java code written inside <%! ... %> stored?

A. Inside a method

B. Inside a loop

C. At class level

D. In a JSP comment

9. What does <jsp:include> do?

A. Includes another JSP page dynamically

B. Comments a section

C. Declares a variable

D. Displays a message

10. What will <%@ include file="header.jsp" %> do?

A. Include header.jsp at runtime

B. Include header.jsp at compile-time

C. Forward request

D. None of the above


11. What does <c:forEach> do?

A. Conditionally executes block

B. Imports files

C. Loops over a collection

D. Handles exceptions

12. What tag library URI is used for core JSTL?

A. http://java.sun.com/jstl/sql

B. http://java.sun.com/jsp/jstl/core

C. jstl:core

D. core:jstl

13. How can you access a JavaBean property in EL?

A. ${bean.property}

B. ${bean->property}

C. <%= bean.property %>

D. bean.property

14. Which JSTL tag is used for conditional operations?

A. <c:loop>

B. <c:check>

C. <c:if>

D. <c:condition>

15. Which of these is valid for checking null in JSTL?

A. ${empty user}

B. ${null user}

C. <% user == null %>

D. ${user eq null}

16. What is the first step to use JDBC?


A. Execute SQL query

B. Load the driver

C. Create a connection

D. Close connection

17. Which interface is used to execute parameterized SQL queries?

A. Statement

B. PreparedStatement

C. CallableStatement

D. QueryInterface

18. What does executeQuery() return?

A. ResultSet

B. Boolean

C. int

D. void

19. What is the purpose of DriverManager.getConnection()?

A. Close connection

B. Connect to database

C. Execute query

D. Get driver

20. Which JDBC statement is used for insert, update, and delete operations?

A. executeQuery()

B. executeUpdate()

C. executeInsert()

D. run()

21. Which method is used to invalidate a session in JSP?

A. closeSession()
B. endSession()

C. invalidate()

D. terminate()

22. What is stored using cookies in web applications?

A. Session IDs

B. User data

C. Page content

D. IP addresses

23. Which class is used to create a cookie in JSP?

A. javax.servlet.Cookie

B. javax.http.Cookie

C. java.net.Cookie

D. javax.servlet.http.Cookie

24. How can you get a session in a servlet?

A. request.getSession()

B. response.getSession()

C. context.getSession()

D. servlet.getSession()

25. What happens when session.invalidate() is called?

A. Resets session timeout

B. Deletes session

C. Freezes session

D. Logs out user

26. What is the role of a filter in a Java web application?

A. Format data

B. Validate form
C. Intercept requests

D. Manage errors

27. Which method in Filter is called for cleanup?

A. destroy()

B. init()

C. doFilter()

D. reset()

28. What interface must be implemented to create a filter?

A. Servlet

B. Filter

C. Request

D. Handler

29. How are filters configured?

A. web.xml

B. Java class

C. filter.xml

D. servlet.xml

30. What is the purpose of filter chaining?

A. Skip filter logic

B. Pass request to next filter

C. End response

D. Exit filter

31. What does the SQL SELECT statement do?

A. Inserts new record

B. Updates record

C. Fetches data
D. Deletes table

32. Which SQL keyword is used to sort result set?

A. GROUP BY

B. ORDER BY

C. FILTER

D. WHERE

33. Which clause is used to filter records in SQL?

A. ORDER BY

B. GROUP BY

C. WHERE

D. SELECT

34. What is the default sorting order of ORDER BY?

A. Descending

B. Random

C. Ascending

D. Custom

35. Which SQL command is used to update data in a table?

A. MODIFY

B. UPDATE

C. CHANGE

D. SET

36. What is the use of @WebServlet annotation?

A. Define a servlet

B. Register servlet

C. Connect DB

D. Create UI
37. What does @Override indicate in Java?

A. Ignore method

B. Inherit method

C. Mark override method

D. Extend class

38. What is the purpose of @WebFilter annotation?

A. Declare servlet

B. Configure filter

C. Map REST path

D. Create thread

39. Which annotation is used for RESTful resource path?

A. @Path

B. @Rest

C. @Route

D. @URI

40. What does @GET annotation specify in REST API?

A. Creates a resource

B. Sends form

C. Defines GET method

D. Deletes resource

41. What is a RESTful web service?

A. Web app with UI

B. Web service using REST

C. SOAP based service

D. Static content

42. Which HTTP method is used to create a resource?


A. GET

B. PUT

C. POST

D. DELETE

43. What is the MIME type for JSON data?

A. text/xml

B. application/json

C. application/xml

D. text/html

44. What status code represents success in REST?

A. 200

B. 404

C. 500

D. 403

45. What is URI in REST API?

A. Resource ID

B. Request path

C. Service method

D. Java object

46. What does the Model represent in MVC?

A. Database connection

B. View logic

C. Business logic

D. User interface

47. What is the purpose of the Controller in MVC?

A. Manage view
B. Control flow

C. Store data

D. Display UI

48. Where does the View in MVC reside in JSP projects?

A. Controller

B. Servlet

C. HTML file

D. JSP page

49. Which part of MVC handles user input?

A. Model

B. View

C. Controller

D. Servlet

50. Which layer in MVC interacts with the database?

A. View

B. Controller

C. DAO

D. Frontend

51. What is a servlet?

A. Java bean

B. HTML tag

C. Java class for HTTP

D. XML file

52. Which method is called when servlet is first loaded?

A. doGet()

B. init()
C. service()

D. doPost()

53. What is the default HTTP method called in a servlet?

A. doPost()

B. destroy()

C. service()

D. doGet()

54. What is the web.xml file used for?

A. Define UI

B. Servlet mapping

C. HTML structure

D. View design

55. Which method is called to send response back to client?

A. doPost()

B. out.print()

C. response.send()

D. response.getWriter().write()

56. What does CRUD stand for?

A. Create, Read, Update, Delete

B. Create, Run, Upload, Download

C. Copy, Replace, Undo, Delete

D. Compile, Run, Update, Debug

57. Which SQL command is used for deleting data?

A. ERASE

B. REMOVE

C. DELETE
D. CLEAR

58. Which JDBC method is used to insert data?

A. createQuery()

B. execute()

C. addRecord()

D. executeUpdate()

59. What is required for establishing JDBC connection?

A. Driver

B. Servlet

C. XML

D. View

60. Which SQL keyword is used to insert new record?

A. PUT

B. CREATE

C. UPDATE

D. INSERT INTO
Section 2: Questions with Answers

1. Which OOP principle focuses on wrapping data and methods together?

A. Inheritance

B. Polymorphism

C. Encapsulation

D. Abstraction

Answer: C. Encapsulation

2. What does method overriding achieve in Java?

A. Compile-time polymorphism

B. Hiding parent method

C. Run-time polymorphism

D. Data hiding

Answer: C. Run-time polymorphism

3. Which keyword is used for inheritance in Java?

A. implements

B. inherits

C. extends

D. override

Answer: C. extends

4. Which of the following is an example of abstraction?

A. A class with private variables

B. An interface with only method signatures

C. Method overloading

D. Object instantiation

Answer: B. An interface with only method signatures


5. Which concept allows multiple methods with the same name but different parameters?

A. Overriding

B. Overloading

C. Encapsulation

D. Inheritance

Answer: B. Overloading

6. Which of the following is a directive tag in JSP?

A. <jsp:include>

B. <%@ page import="java.util.*" %>

C. <%= user.getName() %>

D. <%! int count; %>

Answer: B. <%@ page import="java.util.*" %>

7. What is the output of <%= 5 + 3 %> in a JSP file?

A. Nothing

B. 53

C. 8

D. Compilation error

Answer: C. 8

8. Where is the Java code written inside <%! ... %> stored?

A. Inside a method

B. Inside a loop

C. At class level

D. In a JSP comment

Answer: C. At class level

9. What does <jsp:include> do?


A. Includes another JSP page dynamically

B. Comments a section

C. Declares a variable

D. Displays a message

Answer: A. Includes another JSP page dynamically

10. What will <%@ include file="header.jsp" %> do?

A. Include header.jsp at runtime

B. Include header.jsp at compile-time

C. Forward request

D. None of the above

Answer: B. Include header.jsp at compile-time

11. What does <c:forEach> do?

A. Conditionally executes block

B. Imports files

C. Loops over a collection

D. Handles exceptions

Answer: C. Loops over a collection

12. What tag library URI is used for core JSTL?

A. http://java.sun.com/jstl/sql

B. http://java.sun.com/jsp/jstl/core

C. jstl:core

D. core:jstl

Answer: B. http://java.sun.com/jsp/jstl/core

13. How can you access a JavaBean property in EL?

A. ${bean.property}
B. ${bean->property}

C. <%= bean.property %>

D. bean.property

Answer: A. ${bean.property}

14. Which JSTL tag is used for conditional operations?

A. <c:loop>

B. <c:check>

C. <c:if>

D. <c:condition>

Answer: C. <c:if>

15. Which of these is valid for checking null in JSTL?

A. ${empty user}

B. ${null user}

C. <% user == null %>

D. ${user eq null}

Answer: A. ${empty user}

16. What is the first step to use JDBC?

A. Execute SQL query

B. Load the driver

C. Create a connection

D. Close connection

Answer: B. Load the driver

17. Which interface is used to execute parameterized SQL queries?

A. Statement

B. PreparedStatement
C. CallableStatement

D. QueryInterface

Answer: B. PreparedStatement

18. What does executeQuery() return?

A. ResultSet

B. Boolean

C. int

D. void

Answer: A. ResultSet

19. What is the purpose of DriverManager.getConnection()?

A. Close connection

B. Connect to database

C. Execute query

D. Get driver

Answer: B. Connect to database

20. Which JDBC statement is used for insert, update, and delete operations?

A. executeQuery()

B. executeUpdate()

C. executeInsert()

D. run()

Answer: B. executeUpdate()

21. Which method is used to invalidate a session in JSP?

A. closeSession()

B. endSession()

C. invalidate()
D. terminate()

Answer: C. invalidate()

22. What is stored using cookies in web applications?

A. Session IDs

B. User data

C. Page content

D. IP addresses

Answer: B. User data

23. Which class is used to create a cookie in JSP?

A. javax.servlet.Cookie

B. javax.http.Cookie

C. java.net.Cookie

D. javax.servlet.http.Cookie

Answer: D. javax.servlet.http.Cookie

24. How can you get a session in a servlet?

A. request.getSession()

B. response.getSession()

C. context.getSession()

D. servlet.getSession()

Answer: A. request.getSession()

25. What happens when session.invalidate() is called?

A. Resets session timeout

B. Deletes session

C. Freezes session

D. Logs out user


Answer: B. Deletes session

26. What is the role of a filter in a Java web application?

A. Format data

B. Validate form

C. Intercept requests

D. Manage errors

Answer: C. Intercept requests

27. Which method in Filter is called for cleanup?

A. destroy()

B. init()

C. doFilter()

D. reset()

Answer: A. destroy()

28. What interface must be implemented to create a filter?

A. Servlet

B. Filter

C. Request

D. Handler

Answer: B. Filter

29. How are filters configured?

A. web.xml

B. Java class

C. filter.xml

D. servlet.xml

Answer: A. web.xml
30. What is the purpose of filter chaining?

A. Skip filter logic

B. Pass request to next filter

C. End response

D. Exit filter

Answer: B. Pass request to next filter

31. What does the SQL SELECT statement do?

A. Inserts new record

B. Updates record

C. Fetches data

D. Deletes table

Answer: C. Fetches data

32. Which SQL keyword is used to sort result set?

A. GROUP BY

B. ORDER BY

C. FILTER

D. WHERE

Answer: B. ORDER BY

33. Which clause is used to filter records in SQL?

A. ORDER BY

B. GROUP BY

C. WHERE

D. SELECT

Answer: C. WHERE

34. What is the default sorting order of ORDER BY?


A. Descending

B. Random

C. Ascending

D. Custom

Answer: C. Ascending

35. Which SQL command is used to update data in a table?

A. MODIFY

B. UPDATE

C. CHANGE

D. SET

Answer: B. UPDATE

36. What is the use of @WebServlet annotation?

A. Define a servlet

B. Register servlet

C. Connect DB

D. Create UI

Answer: B. Register servlet

37. What does @Override indicate in Java?

A. Ignore method

B. Inherit method

C. Mark override method

D. Extend class

Answer: C. Mark override method

38. What is the purpose of @WebFilter annotation?

A. Declare servlet
B. Configure filter

C. Map REST path

D. Create thread

Answer: B. Configure filter

39. Which annotation is used for RESTful resource path?

A. @Path

B. @Rest

C. @Route

D. @URI

Answer: A. @Path

40. What does @GET annotation specify in REST API?

A. Creates a resource

B. Sends form

C. Defines GET method

D. Deletes resource

Answer: C. Defines GET method

41. What is a RESTful web service?

A. Web app with UI

B. Web service using REST

C. SOAP based service

D. Static content

Answer: B. Web service using REST

42. Which HTTP method is used to create a resource?

A. GET

B. PUT
C. POST

D. DELETE

Answer: C. POST

43. What is the MIME type for JSON data?

A. text/xml

B. application/json

C. application/xml

D. text/html

Answer: B. application/json

44. What status code represents success in REST?

A. 200

B. 404

C. 500

D. 403

Answer: A. 200

45. What is URI in REST API?

A. Resource ID

B. Request path

C. Service method

D. Java object

Answer: B. Request path

46. What does the Model represent in MVC?

A. Database connection

B. View logic

C. Business logic
D. User interface

Answer: C. Business logic

47. What is the purpose of the Controller in MVC?

A. Manage view

B. Control flow

C. Store data

D. Display UI

Answer: B. Control flow

48. Where does the View in MVC reside in JSP projects?

A. Controller

B. Servlet

C. HTML file

D. JSP page

Answer: D. JSP page

49. Which part of MVC handles user input?

A. Model

B. View

C. Controller

D. Servlet

Answer: C. Controller

50. Which layer in MVC interacts with the database?

A. View

B. Controller

C. DAO

D. Frontend
Answer: C. DAO

51. What is a servlet?

A. Java bean

B. HTML tag

C. Java class for HTTP

D. XML file

Answer: C. Java class for HTTP

52. Which method is called when servlet is first loaded?

A. doGet()

B. init()

C. service()

D. doPost()

Answer: B. init()

53. What is the default HTTP method called in a servlet?

A. doPost()

B. destroy()

C. service()

D. doGet()

Answer: D. doGet()

54. What is the web.xml file used for?

A. Define UI

B. Servlet mapping

C. HTML structure

D. View design

Answer: B. Servlet mapping


55. Which method is called to send response back to client?

A. doPost()

B. out.print()

C. response.send()

D. response.getWriter().write()

Answer: D. response.getWriter().write()

56. What does CRUD stand for?

A. Create, Read, Update, Delete

B. Create, Run, Upload, Download

C. Copy, Replace, Undo, Delete

D. Compile, Run, Update, Debug

Answer: A. Create, Read, Update, Delete

57. Which SQL command is used for deleting data?

A. ERASE

B. REMOVE

C. DELETE

D. CLEAR

Answer: C. DELETE

58. Which JDBC method is used to insert data?

A. createQuery()

B. execute()

C. addRecord()

D. executeUpdate()

Answer: D. executeUpdate()

59. What is required for establishing JDBC connection?


A. Driver

B. Servlet

C. XML

D. View

Answer: A. Driver

60. Which SQL keyword is used to insert new record?

A. PUT

B. CREATE

C. UPDATE

D. INSERT INTO

Answer: D. INSERT INTO

You might also like