I looking at one EJB sample from the Java EE 6 tutorial. In This example, I want to know if I could just use @Singleton instead of @Stateless ?
package converter.ejb;
import java.math.BigDecimal;
import javax.ejb.*;
@Stateless
public class ConverterBean {
private BigDecimal yenRate = new BigDecimal("83.0602");
private BigDecimal euroRate = new BigDecimal("0.0093016");
public BigDecimal dollarToYen(BigDecimal dollars) {
BigDecimal result = dollars.multiply(yenRate);
return result.setScale(2, BigDecimal.ROUND_UP);
}
public BigDecimal yenToEuro(BigDecimal yen) {
BigDecimal result = yen.multiply(euroRate);
return result.setScale(2, BigDecimal.ROUND_UP);
}
}
Looks to me like a Util methods.
I could have use a static methods on this ConverterBean, if I wasn't using EJB.
And another question. I know that is a simple sample, but if I use this code from a servlet like in the sample, why using EJB only for this ?