Servlets Flashcards

1
Q

What is TCP/IP?

A
  • Stands for Transmission Control Protocol/Internet Protocol.
  • It is a communication protocol used to interconnect network devices on the internet.
  • It is a suite that encompasses a number of different protocols for different purpose and needs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the different content types?

A
  • Content types is also known MIME (Multipurpose Internet Mail Extension) Type
  • Commonly used content types:
    • text/html
    • text/plain
    • application/jar
    • application/pdf
    • images/jpeg
    • images/png
    • images/gif
    • audio/mp3
    • video/mp4
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a servlet?

A

Servlet is a technology used to create web applications; it is used to respond to incoming requests.

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

What is the Lifecycle of a Servlet?

A
  • Servlet class is loaded
    • Loaded when the first request for the servlet is
      received by the web container
    • Load on startup
  • Servlet instance is created
    • Created after the servlet class is loaded.
    • Created only once in the servlet life cycle.
  • Init method is invoked
    • Web container calls the init method once after
      creating the servlet instance.
    • Used to initialize the servlet.
  • Service method is invoked
    • Called every time a request is received for the
      servlet
  • Destroy method is invoked
    • Called before removing the servlet instance from
      the service.
    • Used to clean up any resources
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
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.
  • Web server is responsible for serving static content over HTTP while Application server is responsible for serving dynamic content, managing EJB, lookup over JNDI, and application security.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
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
7
Q

What is Well-Formed XML?

A
- Refers to an XML document that satisfies certain rules 
  specified by the W3C 
    - documents with correct syntax
- A Well-Formed XML requires that:
    - Content be defined
    - Content be delimited with beginning and end tag
    - Content be properly nested
    - There can be only one root tag
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Element vs Attribute

A

Elements can be viewed as containers that stores text, elements, etc…
Attributes defines the property of an element

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

What is DTD?

A
  • DTD stands for Document Type Definition.
  • This defines the elements that may be included in the document, what attributes the elements have, and the ordering and nesting of the elements.
  • Documents validated against DTD is considered to be “Well-Formed” and “Valid”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is an XML Schema?

A
  • Describe the structure of an XML document

- Provides a more powerful alternative to DTD

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

What is XSL?

A
  • Stands for Extensible Stylesheet Language
  • Describes how XML elements should be displayed
  • Consist of three parts:
    • XSLT - language for transforming XML documents
    • XPath - language for navigating in XML documents
    • XSL-FO - Used for formatting XML documents
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is XSLT?

A
  • Stands for Extensible Stylesheet Language Transformations
  • Used for transforming XML documents into other XML documents
    • Ex: HTML to XHTML
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is XPath?

A
  • Stands for XML Path Language
  • Used to navigate through elements and attributes in an
    XML document
  • Core component of XSLT
  • Defines part of the XML document
  • Provides powerful “path expressions”
  • Used to select node or list of nodes from an XML
    document
  • Provides library of standard functions for manipulating
    string, numbers, etc.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
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
15
Q

What are the different types of XML parsing?

A
  • DOM parser
  • SAX parser
  • JDOM parser
  • StAX parser
  • XPath parser
  • DOM4J parser
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
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
17
Q

What is a Front Controller?

A

A design pattern that represents a single controller that handles all incoming requests.

18
Q

What is a Dispatcher?

A
  • Dispatcher is part of the Front Controller Design
    Pattern
  • It is responsible for view management and navigation
19
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.
20
Q

What is the deployment descriptor?

A

A deployment descriptor describes how a component should be deployed.

21
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
22
Q

What is the HttpServlet class? What methods does it provide?

A
- It is a class that extends from the GenericServlet class 
  and provides Http specific methods
- Provided methods:
    - doGet
    - doPost
    - doPut
    - doDelete
    - service
23
Q

What is the flow of client-to-server using a servlet?

A

The client sends requests through HTTP over TCP/IP to the HTTP server. The servlet will receive the HTTP requests and return a response back to the client.

24
Q

What is a RequestDispatcher?

A
  • Is an interface that facilitates dispatching a requests to another resource.
  • The RequestDispatcher provides two methods:
    • Forward and Include
25
Q

Forward() vs Include()

A
  • Forward() - forwards a request from a servlet to another resource
  • Include() - includes the contents of a resource into the response
26
Q

Forward() vs SendRedirect()

A
  • Forward sends requests to other resources in the same server while SendRedirect sends requests to other resources in different servers
  • Forward is declared in the the RequestsDispatcher interface while SendRedirect is declared in HttpServletResponse
27
Q

Context-Param vs Init-Param

A

Init-param is only accessible to the servlet that it is declared in while context-param is accessible to all servlets

28
Q

Eager Loading vs Lazy Loading

A
  • Lazy loading - a servlet is not loaded when server is starting and load only when the servlet receives a request
  • Eager Loading - servlet loads while server is starting
    • A servlet can be set to load eagerly when you
      declare
29
Q

Servlet Context vs Servlet Config

A
  • Servlet Config - are specified only for a particular servlet and is used for initialization purpose
  • Servlet Context - are specified for the entire application and is accessible by all servlets within that application
30
Q

getParameter() vs getAttribute()

A

getParameter - returns the HTTP requests parameters passed from client to server
getAttribute - mostly for server-side usage only; filling a request with attributes that can be used within the same requests.

31
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
32
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 requests the servlet receives

33
Q

How do I declare a Servlet?

A

extending HttpServlet

34
Q

How does the Servlet Container track sessions?

A

An HttpSession object can be created by invoking the requests getSession() method.
Sessions in servlets manage user sessions; used with JSPs and JSFs because they have views, meaning they serve as both the client and server; not with RESTful servlets

35
Q

What is the service method signature on GenericServlet?

A

Public abstract void service(ServletRequest req, ServletResponse res) throws ServletException, java.io.IOException.

36
Q

Service method in HttpServlet.

A

Protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException.

37
Q

How many versions of init does HttpServlet have?

A
  • 2 inits that are inherited from GenericServlet.
  • init()
  • init(ServletConfig config)
38
Q

Method signature doGet.

A

Protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException.

39
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.
40
Q

Front Controller

A
  • A design pattern for full-stack applications.
  • Front-end sends a request to the back-end.
  • Back-end has a single servlet that is the request dispatcher it receives all requests.
  • When the dispatcher gets a request it consults the handler mapper which tells it by the request type url and other aspects what controller to send the request to.
  • The dispatcher sends it to the appropriate controller who uses a service to call a DAO.
  • The DAO sends a query to the database and receives the databases response which it sends back through the service.
  • The service returns it to the controller who passes it to the dispatcher.
  • If the request was for a page then the servlet would communicate with the view resolver to produce the correct view on the front-end.
  • The dispatcher writes a response with the data in it to the response stream to the front-end producing the view or passing the data for manipulation or display.
41
Q

What is a thread pool?

A
  • Object pools are used in java for storage of objects that we want to use dynamically.
  • The thread pool is one of these object pools
  • Object pools controls the lifecycle of its resources.
  • Many of the java.util.concurrent libraries use thread pools implementing thread pools of worker threads
  • Worker threads are separate objects from Runnable and Callable tasks and are usually used for multiple tasks.
42
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. It’s used to limit input and output from a resource to only requests and responses fitting a set of rules defined by the filter.