0% found this document useful (0 votes)
10 views

Java Server and Servlet MCQ Questions

Java servlet
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Java Server and Servlet MCQ Questions

Java servlet
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Java Server and Servlet MCQ Questions | Java Program MCQs

1.

What is a servlet in Java?

A.A Java program that runs on the server to handle client requests

B.A type of coffee bean

C.A Java class used for file I/O

D.A Java keyword

2.

Which of the following is a valid method in the `HttpServlet` class in Java?

A.`handleRequest()`

B.`runServlet()`

C.`execute()`

D.`doGet()`

3.

What is the purpose of the `web.xml` file in a Java web application?

A.To define JavaBean properties

B.To execute SQL queries

C.To configure servlet mappings and other web application settings

D.To create JavaBeans

4.

In Java Servlets, what is the purpose of the `HttpServletRequest` object?

A.To create JavaBean properties

B.To encapsulate the client's request information

C.To manage JavaBean events

D.None of These

5.

Which of the following is true about session management in Java Servlets?

A.Sessions are managed using SQL queries

B.Sessions are not supported in Java Servlets

C.Sessions can be maintained using cookies or URL rewriting


D.Sessions can only be managed using cookies

6.

What is the role of the `HttpServletResponse` object in Java Servlets?

A.To execute SQL queries

B.To create JavaBeans

C.To manage JavaBean properties

D.To encapsulate the response sent to the client

7.

Which HTTP method is typically used for retrieving data from a server in Java Servlets?

A.`GET`

B.`POST`

C.`PUT`

D.`DELETE`

8.

In Java Servlets, what is the purpose of the `ServletContext` object?

A.To execute SQL queries

B.To manage JavaBean lifecycle

C.To define JavaBean properties

D.To provide access to application-wide resources

9.

What is the purpose of the `doPost()` method in Java Servlets?

A.To handle HTTP GET requests

B.To define JavaBean properties

C.To handle HTTP POST requests

D.To manage JavaBean events

10.

In Java Servlets, what is the primary function of the `RequestDispatcher` interface?

A.To manage JavaBean properties

B.To forward a request from one servlet to another

C.To execute SQL queries

D.None of These
11.

What is the role of the `init()` method in Java Servlets?

A.To handle HTTP requests

B.To create JavaBean properties

C.To initialize the servlet

D.To define JavaBean lifecycle

12.

Which of the following is true about servlet containers (e.g., Tomcat)?

A.They are used for creating JavaBeans

B.They are responsible for executing SQL queries

C.They handle JavaBean properties

D.They manage the lifecycle of servlets

13.

What does the term "URL mapping" refer to in Java Servlets?

A.Associating a URL pattern with a servlet

B.Mapping a URL to a JavaBean

C.Mapping a URL to a database table

D.Mapping a URL to a Java class

14.

Which of the following is NOT a standard HTTP status code in Java Servlets?

A.`500 Internal Server Error`

B.`403 Forbidden`

C.`200 OK`

D.`404 Not Found`

15.

What is the purpose of the `web.xml` `` element in a Java web application?

A.To define JavaBean properties

B.To execute SQL queries

C.To map a URL pattern to a servlet

D.To create JavaBeans


16.

What is a servlet container in Java web applications?

A.A database for JavaBeans

B.Software that manages the execution of servlets

C.A Java keyword

D.None of These

17.

In Java Servlets, what is the purpose of the `doFilter()` method in the `Filter` interface?

A.To create JavaBeans

B.To execute SQL queries

C.To perform filtering tasks on requests and responses

D.To define JavaBean properties

18.

What is the purpose of the `context-param` element in the `web.xml` file of a Java web
application?

A.To define JavaBean properties

B.To execute SQL queries

C.To create JavaBeans

D.To define context-specific parameters

19.

Which Java package contains the core classes and interfaces for servlets?

A.`javax.servlet`

B.`java.beans`

C.`java.jdbc`

D.`java.db`

20.

What is the role of the `HttpSession` interface in Java Servlets?

A.To create JavaBeans

B.To execute SQL queries

C.To define JavaBean properties

D.To provide session management capabilities


21.

Which HTTP method is used for updating data on the server in Java Servlets?

A.`GET`

B.`PUT`

C.`POST`

D.`DELETE`

22.

In Java Servlets, what is the purpose of the `HttpServletRequestWrapper` class?

A.To manage JavaBean events

B.To wrap an existing `HttpServletRequest`

C.To execute SQL queries

D.None of These

23.

What is the purpose of the `init-param` element in the `web.xml` file of a Java web application?

A.To create JavaBeans

B.To execute SQL queries

C.To define initialization parameters for a servlet

D.To define JavaBean properties

24.

Which of the following is true about session tracking in Java Servlets?

A.Sessions can only be tracked using cookies

B.Sessions are not supported in Java Servlets

C.Sessions are tracked using SQL queries

D.Sessions can be tracked using cookies, URL rewriting, and hidden form fields

25.

In Java Servlets, what is the purpose of the `HttpServletResponseWrapper` class?

A.To wrap an existing `HttpServletResponse`

B.To create JavaBeans

C.To manage JavaBean properties

D.To execute SQL queries

26.
What is the primary function of the `destroy()` method in Java Servlets?

A.To handle HTTP requests

B.To create JavaBean properties

C.To define JavaBean lifecycle

D.To clean up resources and finalize the servlet

27.

What is the purpose of the `web.xml` `` element in a Java web application?

A.To define JavaBean properties

B.To execute SQL queries

C.To define a filter that can be applied to servlet requests and responses

D.To create JavaBeans

28.

In Java Servlets, what is the purpose of the `HttpServletResponseWrapper` class?

A.To manage JavaBean properties

B.To wrap an existing `HttpServletResponse`

C.To execute SQL queries

D.None of These

29.

What does the term "servlet context" refer to in Java Servlets?

A.The context in which JavaBean properties are defined

B.The context in which SQL queries are executed

C.The environment in which a servlet runs

D.The context in which JavaBeans are created

30.

In Java Servlets, what is the purpose of the `javax.servlet.Filter` interface?

A.To define JavaBean properties

B.To execute SQL queries

C.To create JavaBeans

D.To perform filtering tasks on requests and responses

31.

Which part stores the program arguments and startup parameters?


A.debug configuration

B.run configuration

C.launch configuration

D.project configuration

32.

What is the storage capacity of single cookie?

A.2048 MB

B.2048 bytes

C.4095 bytes

D.4095 MB

33.

Which of the following code is used to get an attribute in a HTTP Session object in servlets?

A.session.getAttribute(String name)

B.session.alterAttribute(String name)

C.session.updateAttribute(String name)

D.session.setAttribute(String name)

34.

How is the dynamic interception of requests and responses to transform the information done?

A.servlet container

B.servlet config

C.servlet context

D.servlet filter

35.

What is debugging an application which runs on another java virtual machine on another
machine?

A.virtual debugging

B.remote debugging

C.machine debugging

D.compiling debugging

36.

Which of the following code retrieves the body of the request as binary data?
A.DataInputStream data = new InputStream()

B.DataInputStream data = response.getInputStream()

C.DataInputStream data = request.getInputStream()

D.DataInputStream data = request.fetchInputStream()

37.

Which key helps to step out of the caller of currently executed method?

A.F3

B.F5

C.F7

D.F8

38.

Which of the below is not a javascript framework for UI?

A.Vaadin

B.AngularJS

C.KendoUI

D.Springcore

39.

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

40.

What happens when the value of variable change?

A.changed value pop on the screen

B.variable changes are printed in logs

C.dump of variable changes are printed on the screen on end of execution

D.variable tab shows variables highlighted when values change


41.

How can we take input text from user in HTML page?

A.input tag

B.inoutBufferedReader tag

C.meta tag

D.scanner tag

42.

How are java web applications packaged?

A.jar

B.war

C.zip

D.both jar and war

43.

What does local IP address start with?

A.10.X.X.X

B.172.X.X.X

C.192.168.X.X

D.10.X.X.X, 172.X.X.X, or 192.168.X.X

44.

Which of the below can be used to debug front end of a web application?

A.Junit

B.Fitnesse

C.Firebug

D.Mockito

45.

How can we move from one desired step to another step?

A.breakpoints

B.System.out.println

C.logger.log
D.logger.error

46.

How does applet and servlet communicate?

A.HTTP

B.HTTPS

C.FTP

D.HTTP Tunneling

47.

Which component can be used for sending messages from one application to another?

A.server

B.client

C.mq

D.webapp

48.

Which method is used to get three-letter abbreviation for locale's country in servlets?

A.Request.getISO3Country()

B.Locale.getISO3Country()

C.Response.getISO3Country()

D.Local.retrieveISO3Country()

49.

What happens if ServerSocket is not able to listen on the specified port?

A.The system exits gracefully with appropriate message

B.The system will wait till port is free

C.IOException is thrown when opening the socket

D.PortOccupiedException is thrown

50.

Can servlet class declare constructor with ServletConfig object as an argument?

A.True

B.False

51.

Which of the following is true about servlets?


A.Servlets execute within the address space of web server

B.Servlets are platform-independent because they are written in java

C.Servlets can use the full functionality of the Java class libraries

D.Servlets execute within the address space of web server, platform independent and uses the
functionality of java class libraries

52.

Which view allows us to delete and deactivate breakpoints and watchpoints?

A.breakpoint view

B.variable view

C.debug view

D.logger view

53.

Which mode allows us to run program interactively while watching source code and variables
during execution?

A.safe mode

B.debug mode

C.successfully run mode

D.exception mode

54.

What is the java method for ping?

A.hostReachable()

B.ping()

C.isReachable()

D.portBusy()

55.

Which class provides system independent server side implementation?

A.Socket

B.ServerSocket

C.Server

D.ServerReader

56.

Which perspective is used to run a program in debug view?


A.java perspective

B.eclipse perspective

C.debug perspective

D.jdbc perspective

57.

How constructor can be used for a servlet?

A.Initialization

B.Constructor function

C.Initialization and Constructor function

D.Setup() method

58.

What does MIME stand for?

A.Multipurpose Internet Messaging Extension

B.Multipurpose Internet Mail Extension

C.Multipurpose Internet Media Extension

D.Multipurpose Internet Mass Extension

59.

How can we connect to database in a web application?

A.oracle sql developer

B.toad

C.JDBC template

D.mysql

60.

Servlet are used to program which component in a web application?

A.client

B.server

C.tomcat

D.applet

61.
Which of the below are common network protocols?

A.TCP

B.UDP

C.TCP and UDP

D.CNP

62.

What type of protocol is HTTP?

A.stateless

B.stateful

C.transfer protocol

D.information protocol

63.

How to deep dive into the execution of a method from a method call?

A.F3

B.F5

C.F7

D.F8

64.

Which are the session tracking techniques?


i. URL rewriting
ii. Using sessi
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

65.

What does bind() method of ServerSocket offer?

A.binds the serversocket to a specific address (IP Address and port)

B.binds the server and client browser


C.binds the server socket to the JVM

D.binds the port to the JVM

66.

How does eclipse provide the capability for debugging browser actions?

A.internal web browser

B.chrome web browser

C.firefox web browser

D.internet explorer browser

67.

In CGI, process starts with each request and will initiate OS level process.

A.True

B.False

68.

When destroy() method of a filter is called?

A.The destroy() method is called only once at the end of the life cycle of a filter

B.The destroy() method is called after the filter has executed doFilter method

C.The destroy() method is called only once at the begining of the life cycle of a filter

D.The destroyer() method is called after the filter has executed

69.

Which class represents an Internet Protocol address?

A.InetAddress

B.Address

C.IP Address

D.TCP Address

70.

What happens if IP Address of host cannot be determined?

A.The system exit with no message

B.UnknownHostException is thrown

C.IOException is thrown

D.Temporary IP Address is assigned

You might also like