[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

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?
0
Ronayne
Asked:
Ronayne
  • 3
  • 3
1 Solution
 
CEHJCommented:
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;
}
0
 
RonayneAuthor Commented:

So a bean can have a main method?
0
 
RonayneAuthor Commented:
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?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
CEHJCommented:
>>So a bean can have a main method?

Yes. It probably just would not be called
0
 
RonayneAuthor Commented:

ok, ill try that, thx
0
 
CEHJCommented:
8-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now