Now that we have set up our projects, it's time to create our first session bean. We
can do so by right-clicking on the EJB module, navigating to New | Other , and then
selecting the Enterprise JavaBeans category and the Session Bean file type from the
New File wizard.
We now need to specify a number of things:
• It is a good idea to override the default name given to our session bean.
• We need to specify the package for our session bean.
• We need to specify the session bean type: stateless, stateful, or singleton.
° Stateful session beans maintain conversational state with the client
(which simply means that the values of any of their member variables
are in a consistent state between method calls).
° Stateless session beans don't maintain conversational state; therefore,
they perform better than stateful session beans.
° Singleton session beans were introduced in Java EE 6. A single
instance of each singleton session bean is created when our
application is deployed. Singleton session beans are useful
to cache frequently read database data.
• We need to specify whether our session bean will have a remote interface,
which is used for clients executing in a different JVM than our bean; a local
interface, which is meant for clients running in the same JVM as our bean;
or both a remote and a local interface.