Main method in Java

The Main method that Java looks for when running a program. It is the entry point of any java code.

Hello.java file

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}
Hello World

Without main method

public class Hello {
    public void method() {
        System.out.println("Hello World");
    }
}
error: can't find main(String[]) method in class: Hello

Leave a Reply

Your email address will not be published.

ANOTE.DEV