6

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?

Nicholas Kong
  • 1,083
  • 4
  • 14
  • 14
  • possible duplicate of [Why do applets not need a main()?](http://stackoverflow.com/questions/932052/why-do-applets-not-need-a-main) – Jacob Dec 23 '11 at 00:23

4 Answers4

8

Java Applets have an init method instead of main. It's:

public void init() {... }
Fritz
  • 186
  • 2
5

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.

heenenee
  • 19,914
  • 1
  • 60
  • 86
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
2

Applets differ from stand-alone Java applications in that they do not need to implement a main method.

Life Cycle of an Applet

Beau Grantham
  • 3,435
  • 5
  • 33
  • 43
0

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()?

Community
  • 1
  • 1
Smamatti
  • 3,901
  • 3
  • 32
  • 43