I'm a newbe, and i don't know where must i use a JavaBean. I know that is very usual to make a javaBean with functions to "help" a JSP and this make more easy to understand the jsp for nonprogramers person.
But the really dude that i have is where to use insede an Aplication server.
What are the differents betewn a stateless EJB adn a JavaBean?
What code must i put in one or in the other?
What is the principal use of a JavaBean inside an Aplication server?
a java bean is a general java class with three additional rules:
a) a constructor is a must,(that doesn't take parameters.
b) have getter methods.
c) have setter methods.
and ejb is a special java class in the sense it carries a lot of overhead with it and is mostly used for distributed architecture construction.
so if you have some real business problem that requires lot of transaction processing, well you have got a case for an ejb.
if you want to write general data place holders, java beans are the bet.
for example, is usual to put jdbc code in a javaBean?
If you are calling to a JavaBean from a EJB Session for example, to get some data:
- The server have to do a new of this java bean.(mwmory allocation)
- when you have data in yor EJB, the JVM garbage collector can destroy the java BEAN.
What is better, do this kind of thinks with a javabean, or do with a EJB session that is inside an application server that have a pool of EJB instances.
Thank you, i hope anybody could clarify me.
okay it's something like this.
It is not very usual to put JDBC code in normal JavaBeans.
But it is not that rare too. Only one has to remember that when one is retrieving data from some store into a normal JavaBean then one is not going for extensive transaction processing or things such as that. there is no built in facility to achieve such things with a java bean. further there is no inbuilt facility to distribute them in a distributed environment. you will have to write your own code for that and EJB has been developed to precisely save you that trouble.
When you are using EJBs you solely concentrate on the business logic that should go into your problem. You hardly write any networking code or RMI code, because the application server handles all that overhead for you.
thanks, you clarify me a lot.