Add business method signatures to the StatelessCalculator interface:
public double add(double a, double b); public double subtract(double a, double b); public double multiply(double a, double b); public double divide(double a, double b);
In the Package Explorer View, right click on the StatelessCalculatorBean class and select Source > Override/Implement Methods....
Accept the default selection and press the OK button:
Open the StatelessCalculatorBean.java file (if not already open) and modify the newly created methods as shown below:
public double add(double a, double b) { return a + b; } public double subtract(double a, double b) { return a - b; } public double multiply(double a, double b) { return a * b; } public double divide(double a, double b) { if (b == 0.0) { throw new javax.ejb.EJBException("Divide by zero error !"); } return a / b; }
The stateless EJB is complete. WIth EJB 3, there is no need to code deployment descriptors or the home interface. The next step is to package the EJB in the EJB JAR file.
![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |