Reputation: 1163
I was running a Java class that extends Applet implements Runnable
and apparently the program can run, but there is no main
method. I thought Java applications needs the main
method as its entry point?
Upvotes: 6
Views: 15748
Reputation: 137787
Yes, but applets aren't applications. There is a main method in the applet runner (assuming it's implemented in Java; it need not be) but the applet doesn't work that way; it gets loaded/instantiated from a file and then it proceeds along its lifecycle through initialization, starting, operating, stopping, and finally being destroyed. The code that sends it through these states is hidden from the applet's view; it just knows its in an environment that can run applets.
Upvotes: 5
Reputation: 3456
Applets differ from stand-alone Java applications in that they do not need to implement a main method.
Upvotes: 2
Reputation: 186
Java Applets have an init method instead of main. It's:
public void init() {... }
Upvotes: 8
Reputation: 3931
Copied from google results:
Applets are standalone programs which require a third party tool for its execution that is either it is java enabled web browser or applet runner. So it doesn't have main(). It is possible to run a program without main.
Possible duplicate of:
Why do applets not need a main()?
Upvotes: 0