Defining A Stateless EJB

  1. 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);
    								

  2. In the Package Explorer View, right click on the StatelessCalculatorBean class and select Source > Override/Implement Methods....

    Implement Methods

  3. Accept the default selection and press the OK button:

    Implement Methods - Default

  4. 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;
    }
    								

  5. 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.

Professional hosting     Belorussian informational portal         Free SCWCD 1.4 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free Mock Exam Engine