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

This compiles in my environment, but nothing happens at run time.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 4
    Please show the full class, and how you're executing it. If that's all there is, I'd expect an exception due to the VM not finding a *static* `main` method to launch. – Jon Skeet Feb 26 '15 at 09:59
  • Please Look at the accepted answer of this link. http://stackoverflow.com/questions/146576/why-is-the-java-main-method-static – Vivek Mishra Feb 26 '15 at 10:02
  • 1
    Thanks all for the quick replies. This solved my problem. What a pesky little error. –  Feb 26 '15 at 10:15

4 Answers4

3

If should be a static method, otherwise it can't serve as the entry point of a Java application.

public static void main(String[] args) 
       ------
{
    System.out.println("Hello World!"); 
}
Eran
  • 387,369
  • 54
  • 702
  • 768
3

The main method should be : public static void main(String[] args)

TheLostMind
  • 35,966
  • 12
  • 68
  • 104
1
public void main(String[] args)

change this to

public static void main(String[] args)  
Pang
  • 9,564
  • 146
  • 81
  • 122
V__
  • 538
  • 10
  • 20
1

main() method syntax is,

public static void main(String[] args) 

you are missing static, so JVM not able to find your main() method i.e. entry point so there is noting happened.

Check your console It should display error message as

java.lang.NoSuchMethodError: main
Exception in thread "main" 
atish shimpi
  • 4,873
  • 2
  • 32
  • 50