I want to know the difference between init and main method of java
-
6They have different names. – skaffman Dec 14 '10 at 11:20
-
1What class is your init() method from? Please clarify your question. Are you referring to the public static void main(String[] args) method? – Koekiebox Dec 14 '10 at 11:23
-
i think he means the servlet init(). Main methods you have in applications. – Costis Aivalis Dec 14 '10 at 11:24
-
4Here is the answer: http://stackoverflow.com/questions/261428/entry-point-for-java-applications-main-init-or-run – Bruno Berisso Dec 14 '10 at 11:25
3 Answers
The main method is used as an entry point for applications, the init method is used as an entry point for applets and servlets.

- 154
- 6
static void
main
is usually the declaration for a method which allows an entry point for launching the Java file/application. however, main
can also be used to name any random method.
while init
is one of the many random names which can be selected for naming a method [satisfying the basic rules for naming methods]. typically, programmers, in Java or any other programming language, like to name a method init
if there's some initialisation routine to be run.

- 4,797
- 4
- 32
- 42
init method is used when servlets or applets is initialize while main method is used for entry point of program....
If there is first time request for servlet then first of all servlet's init method is called and also some properties may be initialize at that time While when you start your application main is entry point for that .......means main is first process for your application

- 34,448
- 50
- 182
- 322

- 1,392
- 5
- 24
- 46