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
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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, theinit()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 nomain(), 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.