****************** ENTERPRISE BEAN JAVA QUESTIONS ******************************

 

1. What is an enterprise bean?

 

A enterprise bean is written in Java is a server side component that encapsulates business logic of an application. For example in an inventory control system, an enterprise bean might have a method named orderProduct or checkInventory level.

 

There are 3 types of enterprise beans, namely: Session bean, Entity beans and Message driven beans.

 

2. What is Session Bean ?

 

Session bean represents a single client inside the J2EE server. To access the application deployed in the server the client invokes methods on the session bean. The session bean performs the task shielding the client from the complexity of the business logic. There

are two types of session beans, namely: Stateful and Stateless.

 

Stateful Session Bean: A state of a bean is represented by the values of its instance variables. In a stateful session bean the values of its instance variables represent the state of a client-bean session. When the client quits or leaves the bean the state is terminated.

 

Stateless Session Bean: This bean does not maintain the state of the conversation between the client and itself. When the client invokes a method on the bean the instance variables of the bean may contain a state but only for the duration of the invocation. Instance variables

are of equal value for all instances of the bean. This means the container can assign any bean to any client, making it very scalable. Typically an application requires less number of stateless beans compared to stateful beans.

 

3. How does Stateful Session bean store its state ?

 

A stateful session bean have three possible stages in its life cycle, namely: i. does not exists, ii. ready and iii. passive. The state of the bean is to stored in memory when in ready state, while stored in a secondary storage when passivated by calling ejbPassivate method on the bean. When the bean is activated again by calling ejbActivate its state is restored back.

 

4. Why does Stateless Session bean not store its state even though it has ejbActivate and ejbPassivate ?

 

There are only two stages in the life cycle of a stateless bean, namely i. does not exists and ii. ready. ejbActivate and ejbPassivate will never be called hence their state will nover be saved.

 

5. What is Entity Bean?

 

Entity bean represents a business object in a persistent storage mechanism. An entity bean typically represents a table in a relational database and each instance represents a row in the table. Entity bean differs from session bean by: persistence, shared access, relationship and primary key. There are two types of entity beans: container managed and bean managed.

 

6. When to use session, entity and message driven beans?

 

Session beans are used to represent a business procedure and no persistance

Is required. Session bean represents a client in the server. Entity beans represent a business logic compared procedure. Entity beans are typically shared between several session beans and persist beyond the scope of the application.

 

Message driven beans are new in j2ee 2.0 and are asynchronous beans typically

used to inteact with legacy batch processing systems.

 

7. Why does EJB needs two interface (Home and Remote Interface) ?

 

To handle the network tranport layer. TODO I do not have much knowledge to explain further.

 

8. What are the methods of Entity Bean?

 

setEntityState

create

ejbCreate

ejbPostCreate

ejbActivate

ejbPassivate

remove

ejbRemove

unsetEntityState

 

9. How is entity bean created using Container managed entity bean ?

 

In both container managed and bean managed when the client calls create the call is passed on to ejbCreate.

 

In a container managed bean ejbCreate method will initialize all instance variables based ont he input arguments passed in. Once ejbCreate method completesthe container will automatically persist the bean. ejbCreate would return null.This is because: it is not practially possible to generate a primary key in ejbCreate and it would be impossible to get hold of the primary key for a row in a table even before the row exists as storage happens only after

ejbCreatecall completes.

 

In a bean managed persistance the ejbCreate will perform the fallowing:

  i.   Create an entry in the database

  ii.  Initialize the instance variables

  iii. Return the primary key.

 

10. In Entity bean will the create method in EJB home and ejbCreate in

Entity bean have the same parameters ?

 

Yes, the client calls the create method passing in certain arguments and the

container inturn calls the ejbCreate with the same signature.

 

11. What is the difference between Containers managed persistent bean

and Bean managed persistent entity bean ?

 

In a bean managed persistance all loading, storing and synchonization is dealt with in the bean itself. The container will call create, ejbLoad and ejbStore methods. These methods should have implementations to do their required functionality. Bean managed persistance beans offer high degree of fluxibility, but it also increases the work needs to be done by the

developer. All persistant associations with other business objects are handled in the bean itself.

 

In a container managed persistance ejbLoad and ejbSave have to be implemented but would be empty. All loading, saving and reterival is handled by the containeritself. Associations with other business objects is also handled by the container. No SQL query needs to be written here, making this as very friendly to be deployed in any environment without any change to the code that require recompiling.

 

--------------------------------------------------------------------------------

Difference                     Container Managed             Bean

Managed

--------------------------------------------------------------------------------

Class definition               Abstract                      Not

abstract

Database access calls          Generated by tools            Coded by

developers

Persistent state               Represented by virtual        Coded as

public

                               persistent fields.            instance

variables

Access methods for persistent  Required                      None

and relationship field

findByPrimaryKey method        Handled by container          Coded by

developers

Customized finder methods      Handled by container,         Coded by

developers

                               but the developer must

                               define the EJB QL) queries

Select methods                 Handled by container          None

Return value of ejbCreate      Should be null                Must be

the

primary

                                                             key

 

12. When to use container managed and bean managed persistence?

 

Container managed persistance is used when the persistant datastore is a

relational database and there is one to one mapping between a data represented in a table in the relational database and the ejb object. Bean managed persistance in used when there is no one to one mapping of the table and a complex query reteriving data from several tables needs to be performed to construct an ejb object. Bean managed is also used when the

persistence datastorage is not a relational database.

 

13. How many entity beans used and how many tables can u use in EJB project ?

 

EJB architecture is scalable and could scale to any number of tables. However each entity bean represents a business object and is typically represented by a table in the persistent storage mechanism. As number of ejb's increase their complexity increases as well. This "could" cause performance issue and hence the schema of these business objects

should be rechecked.

 

14. What is scalable, portability in J2EE?

 

  i. Scalable in the sense could handle number of clients at the same time.

 

  ii. Portable - platform independent, app server independent, data store independent.

 

15. What are the services provided by the container?

 

  i. Manages execution and life cycle of EJBs.

 

  ii. May provide transaction services.

 

  iii.Shields clients from lower level network management.

 

  iv. May provide persistent storage.

 

16. Software architecture of EJB/ Explain life cycle of beans. ?

 

i. Stateful session bean

 

                        Does Not exists

                                    |  |

  create                         |  |

                                    |  |

  setSessionContext       |  |         remove

                                    |  |

  ejbCreate                    |  |         ejbRemove

                                    |  |

                                    Ready --------ejbPassivate-------------> Passive

                                                <-------ejbActivate -------------

 

ii. Stateless session bean

 

                        Does Not exists

                                    |  |

  setSessionContext       |  |         remove

                                    |  |

  ejbCreate                    |  |         ejbRemove

                                    |  |

                                    Ready

 

iii. Entity beans (Bean managed and Container managed)

 

 

                        Does Not exists

                                    |  |

  setEntityContext          |  |         unsetEntityContext

                                    |  |

                                    |  |

                                    - Pooled < -

        create -                 |  |     -

                        -  ejbAct.  |      -

  ejbCreate -                  |  |       - ejbRemove

             -                      |ejbPass. -

ejbPostCreate -              |  |   - remove

                                    ->Ready -

 

iii. Entity beans (Bean managed and Container managed)

 

 

                         Does Not exists

                                    |  |

  setEntityContext          |  |         unsetEntityContext

                                    |  |

                                    |  |

                                    - Pooled < -

        create -                 |  |     -

                        -  ejbAct.  |      -

  ejbCreate -                  |  |       - ejbRemove

                                    -      |ejbPass. -

ejbPostCreate -              |  |   - remove

                        ->Ready -

 

17. How to deploy in J2EE (i.e Jar, War file) ?

 

Each web application should be contained in a war (web archive) file. War files are nothing but a jar file containing atleast one descriptor called web.xml. The file structure of war file is:

 

  /--

    |

    | WEB-INF

    |   |

    |   |-- WEB.XML (Deployment descriptor)

    |   |-- classes (Folder containing servlets and JSPs

    |

    | META-INF

    |   |

    |   |-- MANIFEST.MF

    |

    | all utility files and resources like error pages etc.

 

Each enterprise bean is stored in a jar file. The jar file contains all standard files like manifest and atleast one additional file called ejb-jar.xml. The structure of a jar file is:

 

  /--

    |

    | META-INF

    |   |

    |   |-- MANIFEST.MF

    |   |-- ejb-jar.xml

    |

    | all classes as in a normal jar file.

 

Both jar and war files are placed inside a ear (enterprise archive) file. The structure of an ear file is

 

  /--

    |

    | META-INF

    |   |

    |   |-- MANIFEST.MF

    |   |-- application.xml

    |

    | jar and war files.

 

TODO may be we should add the structure of all the deployment descriptors here as well.

 

18. Types of transaction ?

 

19. What is bean managed transaction ?

 

20. What are transaction attributes ?

 

21. What is JTS ?

 

22. What are the Isolation level in JDBC transaction ?

 

23. What is Connection pooling? Is it advantageous?

 

24. Method and class used for Connection pooling ?

 

************************* SERVLET QUESTIONS ************************************

 

25. What methods do u use in Servlet - Applet communication ?

 

TODO don't know

 

26. What are the types of Servlet ?

 

Two types of servlets GenericServlet and HttpServlet.

 

GenericServlet is envisioned to be general and super class of all types of servlets. It is  protocol independent, allowing for specific types like Http or FtpServlets. It has one abstract method that all sub classes should implement service method.

 

HttpServlet is a sub-class of generic servlet and provides some http specific functionality like doGet and doPost methods.

 

27. Difference between HttpServlet and Generic Servlets ?

 

GenericServlet is an abstract class that provides protocol independent framework for writing servlets. While http provides for http specific layer.

 

28. Difference between doGet and doPost ?

 

doGet and doPost handles POST and GET of Http respectively.

 

29. What are the methods in HttpServlet?

 

i.   doGet

ii.  doPost

iii. doPut

iv.  doOption

v.   doDelete

 

30. What is the capacity the doGet can send to the server ?

 

31. What are the types of SessionTracking ?

 

Http protocol is a stateless protocol and does not know if the same client returned back asking for further information. Servlets provide machanism for tracking information as about a client.

 

32. Why do u use Session Tracking in HttpServlet ?

 

33. What is Cookie ? Why is Cookie used ?

 

34. If my browser does not support Cookie,and my server sends a cookie instance What will happen ?

 

35. Can u use javaScript in Servlets ?

 

Typically no, however in theory there are implementations of javascript available like: rhino that could be used.

 

36. What are the type of protocols used in HttpServlet ?

 

Http and Https

 

37. Suppose If we have variable ' I ' in run method, If I can create one or more thread each thread will occupy a separate copy or same variable will be shared?

 

38. In servlets, we are having a web page that is invoking servlets username and password? which is cheks in the database ? Suppose the second page also If wewant to verify the same information whethe it will connect to the database or itwill be used previous information?

 

****************************** RMI QUESTIONS ***********************************

 

39. Why do you use UniCastRemoteObject in RMI?

 

40. How many interfaces are used in RMI?

 

Two, skeletons and stubs. Skeletons are typically used on the server side and stubs by the client side.

 

41. Can RMI registry be written in the code, without having to write it in the command prompt and if yes where?

 

Yes, TODO don't know where in a practical sense.

 

42. What is the functionality of the stub?

 

43. How to generate skeleton & Stub classes

 

44. What is the functionality stubs and skeletons?

 

 

****************************** JDBC QUESTIONS **********************************

 

45. What are the types of JDBC drivers?

 

46. Explain the third driver (Native protocol driver)?

 

47. Which among the four drivers is pure Java driver?

 

48. How do you connect with the database?

 

49. How do you connect without the Class.forName (" ")?

 

50. What does Class.forName return?

 

A class as loaded by the classloader.

 

51. What are the types of statement?

 

52. Why is preparedStatement,CallableStatement used for?

 

53. In real time project which driver did u use?

 

54. What is the main functionality of the Prepared Statement?

 

55. What is meant by static query and dynamic query?

 

56. What are the Normalization Rules? Define the Normalization?

 

Author: Senthil e-mail: v_senthil@hotmail.com