JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

What is the difference between Servlet and Filter?


Answer:

A filter is an object that can transform the header and content (or both) of a request or response. Filters differ from web components in that filters usually do not themselves create a response. Instead, a filter provides functionality that can be “attached” to any kind of web resource. Consequently, a filter should not have any dependencies on a web resource for which it is acting as a filter; this way it can be composed with more than one type of web resource.

The main tasks that a filter can perform are as follows:

1) Query the request and act accordingly.
2) Block the request-and-response pair from passing any further.
3) Modify the request headers and data. You do this by providing a customized version of the request.
4) Modify the response headers and data. You do this by providing a customized version of the response.
5) Interact with external resources.

Servlet is used for performing the action which needs to be taken for particular request like user login, get the response based on user role, interacts with database for getting the data, business logic execution, etc.

<< Previous Question | Next Question >>

List Of Java Interview Questions:

  1. Previous set of java interview questions
  2. What is difference between Lambda Expression and Anonymous class?
  3. What is HTTP basic authentication?
  4. What is functional interface in java?
  5. What is the difference between HTTP methods GET and POST?
  6. What is difference between CountDownLatch and CyclicBarrier in Java?
  7. Can Enum extend any class in Java?
  8. Can Enum implements any interface in Java?
  9. Can we have constructor in abstract class?
  10. What is MVC pattern?
  11. What is ActionServlet in struts?
  12. What is the difference between servlet & Filter?
  13. What is ActionMapping in struts?
  14. What is the difference between application server and web server?
  15. What is the difference between JPA and Hibernate?
  16. What is difference between the Value Object and JDO?
  17. How Struts control data flow?
  18. What is Spring?
  19. What is Dependency Injection?
  20. What are the different types of dependency injections in spring?
  21. What is BeanFactory in Spring?
  22. What is difference between BeanFactory and ApplicationContext in spring?
  23. How to make a bean as singleton in spring?
  24. What is IOC or inversion of control?
  25. What are different types of spring auto-wiring modes?
  26. What are the limitations and disadvantages of spring autowiring?
  27. Is the spring singleton bean thread safe?
  28. Why ConcurrentHashMap is faster than Hashtable in Java?
  29. What is the difference between ConcurrentHashMap and Hashtable in Java?
  30. Difference between ConcurrentHashMap and Collections.synchronizedMap(Map)?
  31. What is the difference between ORM, JPA and Hibernate?
  32. What is stream pipelining in Java 8?
  33. What is interface default method in java 8?
  34. Java-8: Interface with default methods vs Abstract class.
  35. What is @SpringBootApplication annotation in Spring boot project?
  36. What Embedded Containers Does Spring Boot Support?
  37. What are the advantages and disadvantages of Spring Boot?
  38. What is Spring Boot Actuator?
  39. What is Spring Boot Initializr?
  40. How does Maven resolve version conflicts of dependencies?
  41. How to reload Spring Boot Application without restarting server?
  42. What is the difference between Spring Boot and the Spring framework?
  43. What are the key components of Spring Boot framework?
  44. What are the different types of bean scope in Spring framework?
  45. What are the standard Spring build-in events?
  46. What is Spring IoC container?
  47. Differences between BeanFactory and the ApplicationContext in Spring framework.
  48. Difference between constructor injection and setter injection in Spring.
  49. How Java-8 Streams differ from collections
  50. What are the various ways to obtain Streams in Java-8?
  51. List Java-8 Streams intermediate operations.
  52. List Java-8 Streams terminal operations.
  53. Can we reuse Java-8 Streams?
  54. Difference between map and flatMap methods in Java 8
  55. What is the difference between Closure and Lambda in Java 8?
  56. Does Java 8 Lambda supports recursive call?
  57. Can Java 8 default methods override equals, hashCode and toString?
  58. Hibernate Eager vs Lazy Fetch Type
  59. What is POJO?
  60. What is HQL (Hibernate Query Language)?
Knowledge Centre
What is servlet context?
The servlet context is an interface which helps to communicate with other servlets. It contains information about the Web application and container. It is kind of application environment. Using the context, a servlet can obtain URL references to resources, and store attributes that other servlets in the context can use.
Famous Quotations
There is a great difference between worry and concern. A worried person sees a problem, and a concerned person solves a problem.
-- Harold Stephens

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2022 by Nataraja Gootooru. All Rights Reserved.