aspose file tools*
The moose likes Beginning Java and the fly likes Why this snippet does not run? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why this snippet does not run?" Watch "Why this snippet does not run?" New topic
Author

Why this snippet does not run?

Aditya Sirohi
Ranch Hand

Joined: Jan 05, 2010
Posts: 93


What prevents this from running? I think the main method should be "static"? Can any one tell me more?

public class Hello {

public void main(String args[])

{

System.out.println("Hello World!");

}

}
MrKamal Joshi
Greenhorn

Joined: Jul 31, 2011
Posts: 24

You have to declare main as static.main is the entry point of a class. In java everything thing is written in a class.Now when you run java filename on command prompt, loader will load the class and jvm will search the main method to enter into the class. so making the main() as static, will make jvm access it directly through classname.main()
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
You have to find the main method before an instance can be created. A static method can be found as soon as the class has been loaded. So the JVM is looking for a method with the heading public static void main(String[] ???).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why this snippet does not run?