I am going through the Java EE 6 tutorial and I am trying to understand the difference between stateless and stateful session beans. If stateless session beans do not retain
Stateless and stateful in this context don't mean quite what you might expect.
Statefulness with EJBs refers to what I call conversational state. The classic example is a flight booking. If it consists of three steps:
Imagine each of those is a method call to a session bean. A stateful session bean can maintain this kind of conversation so it remembers what happens between calls.
Stateless session beans don't have such capacity for conversational state.
Global variables inside a session bean (stateless or stateful) are something else entirely. Stateful session beans will have a pool of beans created (since a bean can only be used in one conversation at a time) whereas stateless sesion beans will often only have one instance, which will make the global variable works, but I don't think this is necessarily guaranteed.