Link to home
Start Free TrialLog in
Avatar of Ronayne
Ronayne

asked on

change java file to bean

Hi Experts, if I have a java file that has a main method and executes on its own, what changes are needed to change it to a bean?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

A java class cannot 'execute on its own' - if it's an application, it has to have its main method called. Turning it into a bean would really entail ensuring that it has an empty constructor and making sure it has private member variables with public accessor/mutator methods.

private int someVal;

public void setSomeVal(int someVal) {
      this.someVal = someVal;
}

public int getSomeVal() {
      return someVal;
}
Avatar of Ronayne
Ronayne

ASKER


So a bean can have a main method?
Avatar of Ronayne

ASKER

So if I have a java file declared like so:

import statements

public class sample {
  public static void main (String args[]) throws Exception {
 
  }
}

Do I need to make the changes you suggested?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ronayne

ASKER


ok, ill try that, thx
8-)