public class SampleService implements Serializable{ //default counter is 100 protected int counter = 100; //add the counter for the inc number public String addCounter(String inc){ if (inc != null) { counter = counter + Integer.parseInt(inc); } else { counter++; } return String.valueOf(counter); } //set default value public void initialize(String dseInit){ counter = Integer.parseInt(dseInit); } //substract counter by dec number public String subtractCounter(String dec){ if (dec != null){ counter = counter - Integer.parseInt(dec); } else{ counter--; } return String.valueOf(counter); } }
This is a JavaBean or a POJO, which provides two functions as addCouneter() and substractCounter().
Create Stateful and Stateless using the class as superclass and create AccessBean at same time: