Servlets Flashcards

1
Q

What is a servlet?

A
- A servlet is a Java programming language class that is used to extend the capabilities of
servers that host applications accessed by means of a request-response
programming model.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is J2EE?

A
  • J2EE stands for Java Platform Enterprise Edition. It is a collection of Java APIs used to write server-side applications.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the Lifecycle of a Servlet?

A

1) Servlet class is loaded
2) Servlet instance is created
3) Init method is invoked
4) Service method is invoked
5) Destroy method is invoked

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

App Server vs Web Server

A
  • A Web server exclusively handles HTTP requests, whereas an application server serves business logic to application programs through any number of protocols.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is XML?

A
  • Stands for Extensible Markup Language

- It defines set of rules for encoding documents in a format that is both human-readable and machine readable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is JAXB?

A
  • Stands for Java Architecture for XML Binding

- It is used to convert Java Object to XML and XML to Java Objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Marshalling?

A
  • The process of transforming the memory representation of an object to a data format suitable for storage or transmission.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Unmarshalling?

A
  • The process of transforming a representation of an object that was used for
    storage or transmission to a representation of the object that is executable.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is MVC?

A
  • Represents Model, View, Controller.

MVC is an architectural pattern that separates an application into three main
components:

  • Model - all data related logic.
  • View - all UI related logic.
  • Controller - handles all business logic and incoming requests.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the deployment descriptor?

A
  • In J2EE, a deployment descriptor describes how a component should be deployed.
  • An example of a “deployment descriptor” is the web.xml.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the important tags you need to include in the web.xml?

A
  • web-app
  • servlet, servlet-name, servlet-class
  • servlet-mapping, servlet-name, url-pattern
  • init-param, param-name, param-value
  • context-param, param-name, param-value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Eager Loading vs Lazy Loading

A
  • Lazy loading - a servlet is not loaded when server is starting and loaded only when the servlet receives a request.
  • Eager Loading - servlet loads while server is starting.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

URL vs URI vs URN

A
  • URL (Uniform Resource Locator) - identifies the location of the resource and how to access it.
  • URI (Uniform Resource Identifier) - identifies a resource by name, location, or both.
  • URN (Uniform Resource Name) - identifies a resource by name in a given
    namespace but does not specify how to obtain it.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the method signatures of doGet() and doPost()?

A
  • Protected void doGet(HttpServletRequest req, HttpServletResponse res) extends
    IOException, ServletException.
  • Protected void doPost(HttpServletRequest req, HttpServletResponse res) extends
    IOException, ServletException.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Init, Service and Destroy, how many times do they execute?

A
  • The init and destroy method is called once.

- The service method is called for every request the servlet receives.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

doGet vs doPost vs GET vs POST

A
  • doGet handles all GET requests while doPost handles all POST requests
  • GET HTTP requests supplies all required data in the URL while POST HTTP requests
    supplies all required data in the request/message body
17
Q

Another name for web.xml?

A
  • Web application deployment descriptor
18
Q

How do I declare a Servlet?

A

servlet tag
servlet-name servlet1 /servlet-name
servlet-class com.xx.servClass /servlet-class
/servlet

19
Q

How does Error Handling work on JEE?

A
  • Handle the error on the server side with try-catch or throws.
  • Return status codes to the front-end depending on errors or lack thereof
20
Q

How to maintain user state?

A
  • Cookies initialized when the user logs in.
  • Send the session id from the cookie in HTTP requests.
  • Access the HttpSession object from the request object using the getSession()
    method.
21
Q

What are filters?

A
  • A filter in the context of java servlets is an object that performs filtering tasks on either the request to a resource or on the response from a resource
22
Q

What is a thread pool?

A
  • Object pools are used in java for storage of objects that we want to use
    dynamically.