Question 2: How can we create deadlock condition on our servlet?
Ans: one simple way to call doPost() method inside doGet() and doGet()method inside doPost() it will create deadlock situation for a servlet. This is rather simple servlet interview questions but yet tricky if you don’t think of it J
Question 3: For initializing a servlet can we use constructor in place of init ().
Ans: No, we can not use constructor for initializing a servlet because for initialization we need an object of servletConfig using this object we get all the parameter which are defined in deployment descriptor for initializing a servlet and in servlet class we have only default constructor according to older version of java so if we want to pass a
Config object we don’t have parametrized constructor and apart from this servlet is loaded and initialized by container so ots a job of container to call the method according to servlet specification they have lifecycle method so init() method is called firstly.
More important Java doesn't allow interfaces to declare constructors. These kinds of servlet interview questions are quite popular on service based companies who just want to dig one level more.
Question 4: Why super.init (config) wiil be the first statement inside init(config) method.
Ans: This will be the first statement if we are overriding the init(config ) method by this way we will store the config object for future reference and we can use by getServletConfig () to get information about config object if will not do this config object will be lost and we have only one way to get config object because servlet pass config object only in init method . Without doing this if we call the servletConfig method will get NullPointerException.
Question5: Can we call destroy() method inside the init() method is yes what will happen?
Ans:Yes we can call like this but if we have not override this method container will call the default method and nothing will happen.after calling this if any we have override the method then the code written inside is executed.
Question 6: How can we refresh servlet on client and server side automatically?
Ans: On client side we can use Meta http refresh and server side we can use server push.
Question 7: How can you get the information about one servlet context in another servlet?
Ans: In context object we can set the attribute which we want on another servlet and we can get that attribute using their name on another servlet.
Context.setAttribute (“name”,” value”)
Context.getAttribute (“name”)
Question 8: Why we need to implement Single Thread model in case of Servlet.
Ans: In J2EE we can implement our servlet on two different ways either by using:
1. Single Thread Model
2. Multithread Model
Depending upon our scenario, if we have implemented single thread means only one instance is going handle one request at a time no two thread will concurrently execute service method of servlet.
Example in banking account where sensitive data is handle mostly this scenario was used this interface is deprecated in Servlet API version 2.4.
As the name signifies multi thread means a servlet is capable to handle multiple requests at same time. This servlet interview question was quite popular few years back on entry level but now its loosing its shine.
Question 9: what is servlet collaboration?
Ans communication between two servlet is called servlet collaboration which is achieved by 3 ways.
1. RequestDispatchers include () and forward() method .
3. Using servlet Context methods
Question 10: What is the difference between ServletConfig and ServletContext?
Ans: ServletConfig as the name implies provide the information about configuration of a servlet which is defined inside the web.xml file or we can say deployment descriptor.its a specific object for each servlet.
ServletContext is application specific object which is shared by all the servlet belongs to one application in one JVM .this is single object which represent our application and all the servlet access application specific data using this object.servlet also use their method to communicate with container.
These Servlet interview questions are good for quick recap of important concept before appearing on any J2EE interview. Please share if you have come across any other interesting interview question on Servlets.
Read more:
http://javarevisited.blogspot.com/2011/09/servlet-interview-questions-answers.html#ixzz1sqEpQmmH
相关推荐
从国外网站上下载的Java面试题。可以看看国外公司的Java面试常用题,以及如何用英文回答。
### IT面试问题与答案解析 #### 1. 如何描述自己? **优秀示例回答:** 我的背景至今一直围绕着成为一名最优秀的财务顾问而努力。让我具体介绍一下我是如何准备自己的。我是一名在______大学主修金融和会计的本科...
因此,公司在两年内实现了10%的收入增长。此外,我对企业如何利用网络工具进行自我营销非常感兴趣,我致力于拓展和完善你们现有的平台。” **分析与建议:** - **聚焦优势**:强调自己的强项以及与应聘职位相关的...
Top 200 Data Engineer Interview Questions & Answers.epub
Haldane's Best Answers to Tough Interview Questions 面试常见问题应对
i < 10; i++) { cout ; } ``` ### 4. 面向对象编程 #### 4.1 什么是类和对象? - **类**:是一种用户自定义的数据类型,它可以包含数据成员和成员函数。 - **对象**:是类的一个实例,可以通过对象来访问类的...
**10. 序列号(Serial Numbers)** **问题:** 在SAP SD中如何管理序列号? **答案:** 序列号管理是SAP SD中的一个重要功能,用于追踪产品的生命周期。它可以通过设置序列号管理配置来实现。 **11. 变体定价(Variant ...
CISA Interview Questions and Answers学习文档手册.pdf
一本介绍面试C程序员时的问题及解答的书籍。
### SQL面试题与解答知识点详解 #### 一、关系型数据库管理系统(RDBMS) **定义:** 关系型数据库管理系统(Relational Database Management System,简称RDBMS)是一种用于存储和管理数据的软件系统,它将数据...
devops interview questions by tech interviews get it for devops interview
SAP ABAP Certification Review SAP ABAP Interview Questions, Answers, And Explanations.pdf
本书《Java Coding Interview》旨在帮助读者在面试过程中取得优异的成绩,传授给求职者必要的面试准备知识。作者有着指导和面试过数百名软件工程师的经验,本书的面试题目是真实的,不仅来自于真实公司的面试问题,...
SAP Basis Interview Questions 在进行 SAP Basis 的面试准备时,面试官通常会关注应聘者对 SAP Basis 的基础知识和实践经验的理解。例如: - **问题示例**:“请简要介绍 SAP Basis 并解释它的主要功能。” - **...
### Android面试问题与解答:面向对象编程概念详解 在Android开发乃至整个软件工程领域中,面向对象编程(Object-Oriented Programming, OOP)是一种核心的设计思想和技术手段。本文将详细解析面向对象编程中的四大...
This book covers useful Interview Questions and Answers on ASP.NET MVC. This book is appropriate for novice as well as for senior level professionals who wants to strengthen their skills before ...
101 great answers to the toughest interview questions 美国经典面试参考书
The Ultimate Reference & Learning Guide for SAP MM/PP Consultants SAP PP Interview Questions, Answers, and Explanations! It's clear that Production Planning is a key specialization for SAP MM ...
C++ interview questions