Hi there. I've had quite a long discussion with a friend of mine about the correct and good use of the main method in Java. Basically we have a class like this:
public class AnImporter implements Runnable {
// some methods, attributes, etc.
}
But where to put the main method? I concider it a good practice to "keep code where it belongs", thus turning the above code into
public class AnImporter implements Runnable {
public static void main(String [] args){
// Startup code for Importer App here
}
// some methods, attributes, etc.
}
While my buddy argues that "the startup code has nothing to do with the application itself", thus it should be placed in another class, like this:
public class AnImporter implements Runnable {
// some methods, attributes, etc.
}
public class AnApplication {
// Nothing here
public static void main(String [] args){
AnImporter a = new AnImporter();
// Startup code here
}
// Nothing here
}
Despite the fact that we discussed the matter for some time we both ended up with no conclusion on which way is the better approach in Java. What's your oppinion on this topic? Where and most importantly, why, do you place your main method where you placed it?