
Use this procedure to create a session enterprise bean that calculates the result from two float numbers. The enterprise bean has four business methods for adding, subtracting, dividing, and multiplying the numbers.
Specifying the general properties of the Session Bean
| Property | Value |
|---|---|
| EJB Name | Calculator |
| EJB Project | CalculatorEjb |
| Bean Type | Stateless Session Bean |
| Default Package | com.sap.examples.calculator |
| Generate default interfaces | unchecked |
The New EJB wizard appears and displays the screen containing names of the remote and the local interfaces.
In the screen that appears, you can add the required business methods.
Creating business methods
In the Calculator bean, you need to add and implement the four business methods: add , subtract , multiply , and divide . For all of these methods, you will specify float as the return value and two parameters f1 and f2 , each of them also of type float.
In the J2EE Explorer, a new substructure named CalculatorBean is inserted automatically under the project node .
Implementing the business methods
The Java Editor opens and displays the source code of the generated bean class.
/**
* Business Method.
*/
public float add(float f1, float f2) {
return f1 + f2;
}
/**
* Business Method.
*/
public float subtract(float f1, float f2) {
return f1 - f2;
}
/**
* Business Method.
*/
public float multiply(float f1, float f2) {
return f1 * f2;
}
/**
* Business Method.
*/
public float divide(float f1, float f2) {
return f1 / f2;
}The Developer Studio updates and compiles the project sources.
The Calculator bean has been created in com.sap.examples.calculator package. The package now contains the bean's class and the bean's home and remote interfaces. You have also completely implemented the business methods of the Session Bean.
Next step:
You continue with creating a Enterprise Bean archive.