A Java Bean is defined as an instance of a class that contains private attributes (data), and getter & setter methods.
If you have:
private String myString;
in your class, you should have the methods
public String getMyString (); and public void setMyString (String settingString); defined in your code. Although, I have found that it is not absolutely necessary to have everything defined, just don't be surprised if something breaks!
An EJB (Enterprise Java Bean) is much more complex They only reside in application servers that handle EJBs (Tomcat doesn't hold EJBs). There are 3 types of EJBs:
- Session: Usually contain some business logic.
- Entity: Usually interface with a data store (such as a database).
- Message-Driven: Receives messages from JMS.