It is mostly said that running a program is not possible without the main() method. In most colleges and institutes and organizations, teachers and interviewers asked if it is possible to execute a Java program without the main(). The answer should be Yes. You might have noticed that Java applets do not have main() but run on browsers.

A Java program can run without the main method. You need a static block for that, and You need to put your executable code in that static block and execute it. The sequence goes something like this:

  • The Java Virtual Machine first loads your class
  • Then it arranges and runs all static blocks
  • Then finally stare across your code for main() and uses it

However, if you are planning to run your program directly from the command-line without using static block, and with the use of JVM, then your program must be required to have the main() method. This is because the Java Virtual Machine keeps looking for the main().

Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram