Is main method compulsory in Java?

Ads
 

Is main method compulsory in Java?

Hi,

Can we have a executable class in Java without a main method? I am going to write simple Java program and there is main method.

Is main method compulsory in Java?

Thanks

View Answers

May 19, 2017 at 1:52 PM

Hi,

Main method is import in Java program. This is the point from where JVM star running the program. So, it you want your class to be run by JVM then you should have a main method.

JVM looks for the main method in the compiled code and then starts the execution of the program.

This applicable for all the program that you directly executes using JVM. But in case of server application its not required, because JVM first runs the Server program and in turn server program runs your class files.

You can follow following examples:

In all the above examples you will find the use of main methods.

Thanks

Ads









Related Tutorials/Questions & Answers:
Is main method compulsory in Java?
main method
Advertisements
main method
Java2
main() method
java sleep in main method
java sleep in main method
What is the arguement of main method?
Can a main method be overloaded?
When is java main method called?
What is the return type of the main method?
Javah
What if the main() method is declared as private?
Can a main method be declared final?
Why is the main method declared static?
Javap Tool application
What is the first argument of the String array in main() method?
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method
Should a main method be compulsorily declared in all java classes?
Artifacts of javax
Accessing non-static members through the main method in Java.
Why we should use string args[] in main method in java?
how to open one Jframe from main method call
ModuleNotFoundError: No module named 'javax'
ModuleNotFoundError: No module named 'javax'
Javah -  Header File Generator

Ads