Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

301.

What are JDBC and its components?

Answer»

Java Database Connectivity with the ACRONYM of JDBC is known as standard Java API. It is an interface for database-independent in between a broad RANGE of databases and Java programming language. It ALLOWS the application PROGRAMS for the interaction with the database for ACCESSING the data.

Components of Java Database Connectivity are-
  • Driver
  • Connection
  • DriverManager
  • SQLException
  • Statement
  • ResultSet
302.

How to declare the Message Bundle in JSF?

Answer»

You can declare the message bundle in two ways. The first way which is the simplest way is to state the message bundle by a supply file NAME faces-config.xml in the Web INF category. Another way is to use a GLOBAL resource bundle declaration. You can ADD the F: LOAD Bundle element to each element.

303.

How to declare the message beans in the faces –config.xml file?

Answer»

The programmer should create a new XML file and PUT the managed beans detail INSIDE and declare the XML file in the javas.faces.CONFIG_FILES. This is DONE to initialize the PARAMETERS which are there inside the WEBINF/web.xml. file.

304.

What is the main tag in JSF?

Answer»
305.

Explain the differences between a Managed Bean and Backing Bean in JSF?

Answer»

The BACKING bean is similar to the Managed bean in JSF. The difference in the TWO merely pertains to the usage of the two.

S.noBacking BeanManaged Bean
1.A backing bean is referred to by its formThe managed bean is a backing bean which has been registered with the JSF. It gets AUTOMATICALLY created and OPTIMIZED by the JSF.
2.The Backing Beans should be defined in the request scope onlyThe Managed beans are created by the JSF, and it can be stored within the SESSION, request or application scope.
306.

What is h: output Text tag in JSF?

Answer»

A h: output Text Tag in JSF is used for rendering a PLAIN text. The PRESENCE of "styleClass", "STYLE", "dir" or "lang" attributes are present, then it renders a "span" element. If the "styleClass" ATTRIBUTE is present, then it renders its value as the value of the "class" attribute.

307.

Explain the different kinds of bean scopes in JSF?

Answer»

JSF is having DIFFERENT types of BEAN scopes LIKE @RequestScoped, @NoneScoped, @ViewScoped, @SessionScoped, @ApplicationScoped and @CustomScoped.

308.

Explain different types of JSF events?

Answer»

The different types of JSF events are:

  • Post Construct APPLICATION Event:- It fires when the application BEGINS. It is used for performing tasks related to initialization after an application has started.
  • Pre Destroy Application Event:- It fires when an application is about to CLOSE. It performs all kinds of clean-up tasks before the application gets closed.
  • PreRender View Event:- It fires when the JSF page is about to get displayed. It is used for user authentication. It gives restricted access to JSF view.
309.

What is the difference between JSF and JSP?

Answer»

The DIFFERENCE between JSF and JSP are:

S.noJSFJSP
1.The full form of JSF is Java Server Faces, and it is a web-based application.The full form of JSP is Java Server Pages, and it is a Java-based technology.
2.The file EXTENSION of JSF is .jsfThe file extension of JSP is .jsp
3.In JSF the tag attributes are dynamic in NATURE and are mapped automatically.Tag attributes have to be declared in the TSD file.
310.

List some of the attributes of tag in JSF?

Answer»

The attributes of tag in JSF are accepted, CLASS, enctype, id, lang, RENDERED, ONCLICK and onsubmit.

18. Which tag is used to upload a file on the website in JSF?

The tag which is used to upload a file on the website in JSF is . JSF USES HTML element of file type. This tag is used for the file to get it as INPUT.

311.

Explain @ViewScoped, @SessionScoped, @CustomScoped and @RequestScoped annotations?

Answer»

@ViewScoped: -As long as the user is interacting with a similar JSF VIEW, the beans are alive. It is usually created on an HTTP request. The BEAN gets destroyed when the user post-backs to a different view.

@SessionScoped:- Beans are there as long as HTTP session lives. This gets created with the first HTTP request. This bean is destroyed when the HTTP session is INVALIDATED.

@CustomScoped:- This bean is there when it enters in the map of custom. It is created for a particular scope live.

@RequestScoped: -Beans are there as long as the HTTP request-response lives. This usually gets created when an HTTP is requested. It gets destroyed when the HTTP request is over.

312.

What is Resource bundling in JSF?

Answer»

Resource Bundling mainly stores the UI date, label, status messages, and UI textual elements separately in the properties FILE and does not do any HARDCODING in the page. It is one of the most convenient methods. Resource bundles are stored in .inproperties file extension because they are key-value pair of strings. This maintenance KEEPS the messages in a SINGLE PLACE.

313.

What is managed bean and backing bean in JSF?

Answer»

Managed Bean: It is a basic bean java class of JSF. This java bean is being managed by the JSF framework. It consists of getter and setter methods and business logic. Managed beans generally work for UI component as a model. It can be easily accessed from the JSF PAGE. Backing Bean: It is a subpart of the managed bean. It contains all the properties of UI components in a JSF page.

This bean is USED in UI CONVERSION, component validations, and event HANDLING. Almost all the features of UI components BINDS with a backing bean in JSF page.

314.

What is the difference between struts2 and JSF?

Answer»

The difference between struts2 and JSF are:

S.noStruts2JSF
1.It is an action based FRAMEWORK.It is a COMPONENT-based framework.
2.It is accessible to TAG LIBRARIES because the component is less.It has a lot of component libraries.
3.The action framework in struts2 is thinner.The component framework in JSF is not thin.
315.

List the new features of JSF 2.0?

Answer»

The new features of JSF 2.0 are:

  • A mechanism is provided which can easily access persistent store.
  • Page loading ACTION is there in JSF 2.0.
  • Standard HTML Renderkit has strategic additions like a tree, data picker, file upload components, and tab view.
  • It GIVES ALLOWANCE for PARTIAL tree transversal.
  • Build the tree and render the tree processes are TWO different lifecycle phases.
316.

What is the use of JSF life cycle?

Answer»

The JSF life cycle begins when the client MAKES an HTTP request for a particular PAGE. It GENERALLY ends when there is a server respond with the page. This life cycle is divided into two primary phases: EXECUTE Phase and Render Phase.

317.

Why is JSF used for?

Answer»

The primary purpose of JSF is to make the construction PROCESS of the user interface simple. This UI is used for server-based applications, and the components can be reusable in a page. It CONNECTS the UI widgets with data sources. It provides the standard UI components and API (Application Programming Interface) majorly for DEVELOPING components.

318.

What is JSF? Explain

Answer»

The full form of JSF is Java Server Faces. This is a server-side COMPONENT based on the user interface framework. It is mainly used for developing web applications. It gives a programming model which is well-defined. It has RICH API and tag libraries. JSF 2 is the latest version which is using FACELETS as a default templating system.

319.

Explain value expression and method expressions in JSF?

Answer»

The Value expression usually FETCHES a value or a set of values. These expressions can be categorized into rvalue and Ivalue expressions. The Ivalue expressions can read as well as write data whereas on the other hand rvalue expression can only read the data.

The method expression allows the users to involve a public method of the bean which returns the RESULT that is IMPORTANT for validation of the data component and for HANDLING the events.

320.

Explain the difference between JSF 1.0vs.JSF 2.0?

Answer»
S.noJSF 1.0JSF 2.0
1.It is the FIRST release of the JSF specificationsIt is the second release of the JSF specifications
2.Does not SUPPORT the usage of annotationsJSF 2 SUPPORTS the ajax features
3.The API had a lot of bugsIt is TOTALLY redesigned and used as an MVC framework.
321.

What is the standard JSF tag library?

Answer»

JSF provides a standard HTML tag library. These TAGS are RENDERED into the CORRESPONDING HTML tag.

322.

Explain the different types of validations in JSF?

Answer»
323.

What is render kit in JSF?

Answer»

The Render kit refers to the collection of a renderer which renders the Java FACES. These are kits specialized for some CLIENTS to perform specific purposes. A typical Java server renders more than one renderkit instances APPLICATIONS.

4. Can we have more than one faces-config.xml FILES in JSF? Yes, there can be many faces in config.xml files in JSF.
324.

What are facelet JSF tags?

Answer»

JSF PROVIDES special tags in order to CREATE a standard layout of a web application called Facelets tags. These tags provide a flexible approach to manage common parts of the multiple pages in ONE place. You need to make use of the following namespaces in the URL HTML MODE: Xmls- “http://www.w3.org/1999/xhtml.”

325.

How can you call multiple listeners in JSF?

Answer»

When there is a need to attach MULTIPLE LISTENERS, a JSF TAG for value change listeners and the action listeners are USED to attach more than one listener to the element. When you make use of the tag syntax, you specify the class which implements the listener interface.

326.

What is event in Servlet?

Answer»

Events are scenarios of activity that take place THROUGHOUT a SOFTWARE existence cycle.
For example, if you are JOGGING a Graphical User Interface (GUI) program, click on a button can be a SCENARIO of interest.

327.

What do you mean by chaining in Servlet?

Answer»

Accepting a REQUEST from the browser and processing it using MULTIPLE servlets in a CHAIN is called Servlet Chaining. In this process, communication occurs between chains of servlets and servlet PROGRAMS in order to process the client's request. This process may make the user requests visible to multiple servlets.

Note: This is a very important Servlet Interview QUESTIONS.

328.

Explain the difference between a Web server and a web container?

Answer»
 Web ServerWeb Container
1.Provides Request and response for HTTP .Ensures servlet objects life style is maintained.
2.Handles client request through HTTP.Uses SERVICE METHOD for some servlet objects .
3.Delivers RESOURCES and data of web pages .Responsible for running the SERVLETS .
4.Serves static content.Serves dynamic content
5.SUPERSETOnly a part of a superset
23. Explain the difference between JSP and servlet?
 ServletJSP
1.Java codeHTML-based code
2.Acts like a controller in MVC.View for showing output in MVC approach.
3.Accepts protocol requests.Accepts only HTTP requests.
4.May override service() method.Not possible to override service() method.
329.

What is Annotations in Servlet?

Answer»

Servlet 3.0 has introduced javax.servlet.ANNOTATION that provides annotation TYPES, which can annotate servlet CLASSES. Annotation also represents metadata. So, if you are using annotation, you may not require deployment descriptor.

Note: This is very essential java servlet interview questions which is ASKED in every interviews.

330.

How to call a jsp from the servlet?

Answer»

You can invoke a JSP web page from a servlet via the functionality of the popular javax.servlet.REQUESTDISPATCHER interface. Complete the following steps in your code to use this mechanism:

  • Get a servlet context instance from the servlet instance:
    SERVLETCONTEXT sc = this.getServletContext();
  • Get a request dispatcher from the servlet context instance, specifying the page-relative or application-relative course of the goal JSP page as ENTER to the getRequestDispatcher() method:
    RequestDispatcher rd = sc.getRequestDispatcher("/jsp/mypage.jsp");
    Prior to or in the course of this step, you can optionally make FACTS on hand to the JSP page thru attributes of the HTTP request object. See the next section, "Passing Data Between a JSP Page and a Servlet", for information.
  • Invoke the include() or FORWARD() approach of the request dispatcher, specifying the HTTP request and response objects as arguments. The performance of these techniques is similar to that of jsp:include and jsp:forward actions. The include() approach solely briefly transfers control; execution returns to the invoking servlet afterward.
331.

Explain the different ways for servlet authentication?

Answer»

There are WAYS of SERVLET AUTHENTICATION:

  • HTTP basic authentication.
  • HTTP digest authentication.
  • HTTPS CLIENT authentication.
  • Form-based authentication.
332.

Explain the features are in Servlet 3?

Answer»

Servlet 3.0 is an update of Servlet 2.5. Servlet 3.0 FOCUSES on extensibility and pluggability. Key features in Servlet 3.0 can be CATEGORIZED into the FOLLOWING areas:

  • Easier development with annotations.
  • Web application modularity.
  • Asynchronous Servlet.
  • Programmatic instantiation of Servlets/Filters.
  • Security ENHANCEMENTS.
333.

How we can get IP address of client in servlet?

Answer»

Here are 2 methods for getting client’s IP address in SERVLET:

HttpServletRequest.getRemoteAddr method returns IP of the client that SENDS request.

HttpServletRequestgetRemoteHost method returns the hostname of the client that is sending the request. However, it may RETURN an empty STRING if hostname is UNKNOWN.

334.

What is URL Encoding in Servlet?

Answer»

URL ENCODING process TRANSFORMS user INPUT to a Common Gateway Interface (CGI) form. It is fit to TRAVEL across the network through STRIPPING spaces, punctuation and replacement with escape characters.

335.

What do you mean by SingleThreadModel interface?

Answer»

The SingleThreadModel interface ENSURES that only one thread is EXECUTED at a given point of time in a given SERVLET service method. This is a marker interface and contains no METHODS. This interface ALSO ensures thread-safe servlets.

336.

How we can create war file in servlet?

Answer»

In order to create a WAR file, use JDK's JAR tool. Use -c switch of jar for CREATING the war file. Enter the PROJECT directory of your project and write this command: jar -cvf projectname.war * Here, -c is for creating file, -v for generating verbose output and -f for specifying name of the ARCHIVE file.

337.

What are the types of an HTTP request?

Answer»

HTTP outlines a SET of request methods that indicate the action to be PERFORMED for a resource. Each request method implements a different semantic, but they also share some common features. Here are the 7 HTTP request methods EVERY web developer preparing for Servlet interview QUESTIONS and answers should know:

  • GET
  • HEAD
  • POST
  • PUT
  • DELETE
  • OPTIONS
  • PATCH
338.

Explain the jar and war files in servlet?

Answer»

Both WAR and JAR have the same file STRUCTURE of a single file that is compressed and contains multiple files INSIDE it. WAR files COMBINE servlets, JSPs, Java and XML files, JAR libraries, JAVASCRIPT libraries, static web pages, and other resources that are needed to run the applications.

339.

What is the difference between forward () and sendRedirect () functions in Servlet? Explain

Answer»
 FORWARD()sendRedirect()
1.SERVER-side redirect.Client-side redirect.
2.Redirect is at the server end, not visible to the client.Redirection is at the client end and visible to the client.
3.Original URL remains intact.Original URL changes.
340.

What do you mean by Request Dispatcher in Servlet? Also explain its methods.

Answer»

RequestDispatcher INTERFACE defines an OBJECT that can DISPATCH the request to resources like HTML, JSP, and Servlet, on the server. This interface provides TWO methods

forward (ServletRequest request, ServletResponse response) will forward a request from Servlet to another resource such as a Servlet, JSP, or HTML, on the server.

Include (ServletRequest request, ServletResponse response) will include the content of a resource such as Servlet, JSP, or HTML, in the response.

341.

What do you mean by filter in servlet?

Answer»

A filter is an object that FILTERS tasks that are EITHER request to a resource, or RESPONSE from a resource, or both. Filtering is PERFORMED in doFilter method. Filters get configured in deployment descriptor of your application.

342.

What are the difference between session and cookies in Servlet? Explain

Answer»
 SessionsCookies
1.Server-side files.Client-side files.
2.Stores UNLIMITED CONTENT in user's browser.Stores LIMITED content of limited users.
3.Data is not EASY to MODIFY.Data is easy to modify.
343.

What do you mean by Session Tracking and also explain its techniques?

Answer»

Session TRACKING is a technique that servlets USE to maintain a record of a series of requests originating from the same USER or the same BROWSER across a period of time. These sessions are shared between the servlets that are accessed by a client.

There are 4 TECHNIQUES to track sessions:

  • Cookies
  • Hidden Fields.
  • URL Rewriting.
  • Session Tracking API.
344.

Explain the difference between ServletConfig and ServletContext in Servlet?

Answer»
 ServletConfigServletContext
1.Parameters specified for a specific servlet.Parameters specified for the entire application.
2.The object created during the INITIALIZATION process.The object created during WEB application deployment.
3.Available as long as the servlet is EXECUTING.Available as long as the application is executing.
345.

Explain the difference between GET and POST method in Servlet?

Answer»
 GET methodPOST method
1.A LIMITED AMOUNT of data can be SENT as data is sent in the headerLot of data can be sent as data is sent in the body
2.Not secured because data is exposedSecured because data is not exposed
3.Can be BOOKMARKEDCannot be bookmarked
346.

Explain the difference between generic Servlet and HTTP Servlet?

Answer»
 GENERIC ServletHTTP Servlet
1.Subclass of javax.servlet.GenericServletSubclass of javax.servlet.HttpServlet
2.Protocol independentProtocol dependent
3.Belongs to javax.servlet PACKAGEBelongs to javax.servlet.http package
347.

What is Servlet and list its types?

Answer»

The Servlet is a CLASS used in JAVA applications for enhancing the CAPABILITIES of the server. Servlets respond to a request from the browser and return response content and also run on web application server container and are used to generate HTML content that shows on the web browser.

There are two types of servlets - GENERIC and HTTP

348.

Explain the lifecycle of a Servlet?

Answer»

Servlert’s life cycle is the entire process from its CREATION until its destruction. A Servlet follows this path:

  • Initialized by CALLING init( ) METHOD
  • Calls service( ) method to process request
  • Terminated by destroy( ) method

Finally, the servlet is NOTHING but the garbage that gets collected by JVM's garbage collector.

349.

What are the difference between Servlet and CGI?

Answer»
 ServletCGI
1.PortableNot portable
2.Requests HANDLED by lightweight Java ThreadRequests handled by heavyweight OS process
3.Data sharing possibleData sharing not available
4.LINK directly to the Web serverCannot link directly to the Web server
350.

Explain the difference between plain-validator and field-validator in Struts?

Answer»

Field validators

  • Act on SINGLE fields that are accessible through action
  • More generic
  • Offer validations in full content

Non-field validators

  • Only add action level messages
  • Mostly domain specific
  • Offer CUSTOM implementations
  • Allows to declare both TYPES of validators