Is main method compulsory in Java?

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









Related Tutorials/Questions & Answers:
Is main method compulsory in Java?
difference between java5 and java6 - Java Beginners
Advertisements
main method
main method
main method
main method
Java2
main() method
Main method overloading
java sleep in main method
java sleep in main method
What is the arguement of main method?
Can a main method be overloaded?
about java1
When is java main method called?
Javap Tool application
Javah
What is the return type of the main method?
What if the main() method is declared as private?
Can a main method be declared final?
Why is the main method declared static?
About Java2
What is the first argument of the String array in main() method?
javaa swings - IDE Questions
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?
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
Artifacts of javax
Javah -  Header File Generator
JAVA what is different between static block and public static void main(String a[]) method
ModuleNotFoundError: No module named 'javax'
ModuleNotFoundError: No module named 'javax'
Javac -source KeyTest.java
java.lang.NoClassDefFoundError: javax/transaction/UserTransaction????? - Struts
javax - JSP-Servlet
ModuleNotFoundError: No module named 'javac-parser'
ModuleNotFoundError: No module named 'javac-parser'
Version of javax>javaee-api dependency
javax servlet error - JSP-Servlet
javab - Java Beginners
javas - JSP-Servlet
javac complier not found - JSP-Servlet
What is Public static void main

Ads