title: Difference between @Stateless and @Singleton
body: <p>I'm following <a href="http://netbeans.org/kb/docs/javaee/cdi-intro.html">this tutorial</a> which also uses an EJB:</p>
  
  <pre class="lang-java prettyprint-override"><code>package exercise1;
  
  import java.util.Random;
  import javax.ejb.Stateless;
  import javax.inject.Named;
  
  @Stateless
  public class MessageServerBean {
      private int counter = 0;
  
      public String getMessage(){
          Random random = new Random();
          random.nextInt(9999999);
          int myRandomNumber = random.nextInt();
          return "" + myRandomNumber;
      }
  
      public int getCounter(){
          return counter++;
      }    
  }
  </code></pre>
  
  <p>Here is an output example:  </p>
  
  <hr>
  
  <p>Hello from Facelets<br>
  Message is: 84804258<br>
  Counter is: 26<br>
  Message Server Bean is: exercise1.MessageServerBean@757b6193</p>
  
  <hr>
  
  <p>Here's my observation:</p>
  
  <ul>
  <li>When I set the bean as <code>@Stateless</code> I always get the same object ID and counter always increments. </li>
  <li>When I set the bean as <code>@Stateful</code> I get a new instance every time I refresh the page.</li>
  <li>When I set it to <code>@Singleton</code> I get the same results as when I set it to <code>@Stateless</code>: same object ID, counter incrementing.  </li>
  </ul>
  
  <p>So, what I actually would like to understand is: what's the difference between <code>@Stateless</code> and <code>@Singleton</code> EJBs in this very case?</p>