This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am unable to execute any application’s main() method) from an applet or servlet, even though I can execute a public method from the same application. Anybody would help, I would really appreciate. Does it suppose to execute the main method if I instantiate it? (For me it does not exeute it.)
Alex, If I understand your question correctly, you are indicating you have an applet (say MyApplet) and you are trying to execute the main() method of a class (say MyClass) but are failing; but you can have MyApplet execute a public method in MyCalss. That is exactly what should happen. The purpose of a main method is to start an application. Applications with 1 class or 10,000 classes both only have one main method. In the case of an applet, when the applet is loaded, the browser or applet viewer calls the applet�s init() method. You can think of an applet�s init() method as basically being the applet�s main. At this point your �application� is running (although be it as an applet) and it does not make any sense to call a main method within the same application. The same holds true for Servlets. It all starts with the init method. I hope that answers your question. If not, please clarify so I or someone else can help you out. Regards, Mark
Welcome to JavaRanch, Alex! I am unable to execute any application�s main() method) from an applet or servlet, even though I can execute a public method from the same application. Why do you want to do such a thing? Could you post some example code of what you're trying to do? Does it suppose to execute the main method if I instantiate it? No. The main method is either invoked by the JRE when the program is started with a call to java or javaw, or when another program explicitly invokes the main method.