Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the Main method must needed in a Java program?

Tags:

java

Is the main method needed to write a java program?

This is my code:

package example;

public class HelloWorld {

    public HelloWorld() {

    }

    public String getHelloWorld() {

        return "Hello From Java!";
    }
}

It shows an error at compilation:

java.lang.NoSuchMethodError: main
Exception in thread "main"
like image 222
Praveen Avatar asked May 24 '10 10:05

Praveen


1 Answers

Without a main method you application will have no entry point. Yes, it is required for any executable program.

like image 132
Andrew Hare Avatar answered Oct 18 '22 17:10

Andrew Hare