Monday, May 30, 2011

How to execute the java program without main method?


public class HelloWorld
{

  static
  {

      System.out.println("Hello World!");
      System.exit(0);
  }
}

Now let us test the program without System.exit(0).
The program will terminate complaining that there is no main method. 
Exception in thread "main" java.lang.NoSuchMethodError: main