So far I've been using public void run() {}
methods to execute my code in Java. When/why might one want to use main()
or init()
instead of run()
?
So far I've been using public void run() {}
methods to execute my code in Java. When/why might one want to use main()
or init()
instead of run()
?
This is a peculiar question because it's not supposed to be a matter of choice.
When you launch the JVM, you specify a class to run, and it is the main()
of this class where your program starts.
By init()
, I assume you mean the JApplet method. When an applet is launched in the browser, the init()
method of the specified applet is executed as the first order of business.
By run()
, I assume you mean the method of Runnable. This is the method invoked when a new thread is started.
If Eclipse is running your run()
method even though you have no main()
, then it is doing something peculiar and non-standard, but not infeasible. Perhaps you should post a sample class that you've been running this way.