J2EE Interview Questions with Answer:
One can see these questions and answer from interviewee or 
interviewer perspective.
=> These questions and respective answers are my own
understanding of the Subject, and I am not a Subject Matter
Expert in this, so if you have any queries, suggestions,
comments, differece of opinion, please take some time off
your busy schedule to correct me if I am wrong.
your respective comments will be added to the appropriate
place in this page.







In any interview, be it Java,
J2EE, JMS, JDBC, JSP, Servlet
Technologies, it is paid to be
prepared with basic questions
and with common sense in place.
As an interviewer I have observed
many times, potential candidates
tend to forget some basic concepts
and try to give some complicated
answers including some of the
tools or Technologies those they
have heard but never worked on,
and thus giving interviewer a
chance to explore on those
Technologies and making it
difficult for the candidate to be
in self confidence. Once this
happens, it might comes out to
be very difficult for the candidate
to be in control of what he is
talking and trying to answer to
the questions from interviewer.
 
J2EE Interview question 1: What is the lifecycle of an J2EE component in an application? J2EE Interview answer 1: Lifecycle of J2EE Component deals with component creation, component assembly and application deployment. Component creation is like writing application classes like Servlet, EJB, Connections and deployment descriptors etc. Component assembly is to assemble or create Jar and War file and bundling all these components created in component creation cycle. Application deployment is to deploy or make the assembled file available in J2EE container, for these J2EE components to get active. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com J2EE Interview question 2: Is it advisable to have a class file present in a single Jar and or war file for once in a single EAR file? J2EE Interview answer 2: Yes, as J2EE application server may have two or more classloaders present like WAR class loader, EJB Jar classloader. Then if same class file is placed in war as well as Jar file separately, these two classloader will load two versions of same class file in two classloaders. And this could be potential classcast problem. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com J2EE Interview Question 3: Suppose there is a requirement to use scheduler thread from the Servlet, and within JTA transaction transaction, will these scheduler threads run within scope of JTA transaction or not? J2EE Interview Answer 3: No, as per J2EE specification, if web component creates a thread, J2EE platform must ensure that the newly created thread is not associated/executed within this JTA transaction. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com J2EE Interview question 4: Suppose two EJB components running in two different J2EE container instances, will the transaction initiated by one EJB component, be propagated to another EJB component running in another J2EE container instance? J2EE Interview answer 4: No, one EJB component running in a J2EE Container instance cann't be able to propage transaction to another EJB component in another J2EE Container instance. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com J2EE Interview Question 5: Can Servlet filters and web application event listeners, start UserTransaction and use transaction outside doFilter method? J2EE Interview answer 5: No, Servlet filter and web application event listeners, should use transaction within doFilter method only (if anyone wants to use it). => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com J2EE Interview Question 6: What is a major change in EJB3.0 over EJB2.0, that makes testing EJB components really easier? J2EE Interview Answer 6: With anotations EJB3.0 session and entity beans are POJO (Plain Old Java Objects) and due to this it is ease to test POJO, as we can write JUnit testcases for session and entity beans and can run these testcases out of container environment. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com J2EE Interview Question 7: What are EJB anotations and how can we use those? J2EE Interview Answer 7: EJB anotations are many, some of the anotations I can think of are @Stateless, @Stateful, @Remote, @Local, @EJB etc. If any anotation is used in Session bean or Entity bean, it has to be in import section of the class file as well. If interested in using @Stateless in SessionBean, then this session bean has to import javax.ejb.Stateless class as well. And these bean can only be deployed onto EJB3.0 or JEE 5 compatible container/application server only. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com Servlet Question 8: Can a Java Thread be started from Servlet class, and what will be the implications? Servlet Answer 8: Yes, it is possible to write a Thread or start a Thread from Servlet. In fact a Servlet can be started on load of the web application by defining "load-on-startup" tag value as "1" in the "web.xml" file. One should not start/create a thread from a Servlet that is to be invoked by browser or Java client application. Reason is that web container has Threads running to delegate every client request to appropriate Servlet instance. If servlet instance starts a thread from every request, then it is like each thread spanning multiple threads. As HTTP is stateless protocol, and after response is sent back to client, job of servlet is over, and web container manages the lifecycle of the servlets, but not responsible for the lifecycle or management of the Threads those Servlets have created. If need is to to some kind of scheduling operation, then it is allows advisable to try for some good Scheduler frameworks available. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com Servlet interview Question 9: What is HTTP Session tracking and why is it important? Servlet interview Answer 9: HTTP Session tracking is the way Web server knows that the request is not a fresh or new request, and has a session already created in the web context. So when a request reaches web server, it looks for a variable called jsessionid, that should be associated with the request either in form of cookies, or URL rewriting. If your site visitor has blocked all cookies then redirect to another JSP or Servlet, will not be able to carry the same session, and all the data/object reference stored in HttpSession is/are lost. But is this redirect is done by using encodeURL method of HttpServletResponse object, then session id is attached as a part of URL and webserver attaches already created session to the new request. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com Servlet Question 10: What is session management, and how is it different from session tracking? Servlet Answer 10: HTTP session management is related to the mechanism, by which application data or client state can be passed from one request to another request (As HTTP is stateless). Session Management is obviously comes after session tracking, as without session tracking, client request cannot be hooked onto one and only one session. But if requirement is to just pass reasonably small data/variables, from one request to another, then it can be done, by Hidden form field, and can be transported from browser to server, either by POST or GET as method in HTML FORM tag. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com Servlet Question 11: Can I use Hidden form field to track session? Servlet Answer 11: No, as Hidden form field sends its value as a request parameter, which is not same as URL rewriting (passing jsessionid as part of URL). => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com Servlet Question 12: How can I pass method as request parameter to be called, instead of default doGet or doPost method of HttpServlet object, on submit of an URL? Servlet Answer 12: By overriding service method of HttpServlet object, and using reflection to invoke the desired method of the servlet that is passed as a request parameter. It is similar to the dispatcher mechanism implemented in Struts framework for dynamic dispatching of action. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com Servlet Question 13: In a architecture pattern like MVC, if it is mandatory that Servlet should be the controller, why not JSP? Servlet Answer 13: As JSP cannot be configured as a default mapping to be called based on a URL pattern in web.xml file. In that case, not all request goes through a JSP controller, and the very purpose of controller is not achieved. As Servlet can be mapped to a particular URL in web.xml like, for example: <servlet-mapping> <servlet-name>SampleController</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com Servlet Question 14: Why JSP is used as View part of MVC ? Servlet Answer 14: As JSP is easily configurable at runtime and by using Tag library, XSL, and many more scripting language, productivity increases by using JSP instead of Servlet. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com Servlet Question 15: Can a database connection pool be instantiated in init method of servlet instead of server connection pool? What will be the problem? Servlet Answer 15: It is true that connection pool can be instantiated in init method of Servlet and is available for the web application to use, but generally there can be many web application required to use database connection pool, and multiple web applications do not have access beyond ServletContext. So it is desirable to have external resources defined at server level, not at an application level. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com Servlet Question 16: How to implement Servlet singlethread model, by not using singlethreadmodel? => Requesting for user input as answer for this question => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com Evaluating JPA Java Persistence API in EJB 3.0 API JPA interview question 17: In Java Persistence API, as per Enterprise JavaBeans Specification version 3.0, What is an Entity class? JPA interview answer 17: In java Persistence API, Entity class is the Persistable class that can be mapped to a database table with a primary key defined in table column. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com JPA Java Persistence API Interview Question 18: Can Entity class in JPA Java Persistence API, be an interface or can an interface be acted like an Entity? JPA Java Persistence API Interview Answer 18: No, Entity class must be class only, not an interface, Entity class must not be declared final, and Entity class must be the top level class in an class hierarchy. Entity class must have a no-argument public or protected constructor. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com JPA Java Persistence API interview question 19: Do Entity class supports inheritence? JPA Java Persistence API interview answer 19: Yes, Entity class supports inheritence and inheritence could have Entity class extending non entity class or non-Entity class can extend Entity class. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com JPA Java Persistence API interview question 20: Can an abstract class be acted like an Entity class? JPA Java Persistence API interview answer 20: Yes, abstract class can be an Entity class as well. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com JPA Java Persistence API interview question 21: How to define an abstract class or concrete class as JPA Entity class? JPA Java Persistence API interview answer 21: By placing annotations @Entity in the class level for the Entity class or by defining the Entity class in deployment descriptor. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com JMS Interview Question 22. What are the Open Source JMS Implementation and its basic features? JMS Interview Answer 22: OpenJMS, and it has Topic and Publish mode of sending and receiving Messages. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com JMS Interview Question 23. Can JMS be able to use Transaction? JMS Interview Answer 23: One way of handling JMS within transaction is by using Message Driven Bean within EJB Container. => If you want to comment/add/differ with any of the question and/or answer, please contact Author at usingframeworks@gmail.com
Copyright © 2009-2010, Interview-Questions-Tips-Forum, All Rights Reserved.

These Pages are NOT affiliated in any form with Weebly.com