Take this code for instance
public class Hello
{
static void main(String[] args)
{
System.out.println("Hello World");
}
}
Here, I didn't write public for the main method and compiled the class. When I run the program why does the error read as "Could not find or load main class Hello.java".
My question is, if main(String[] args) is a 'method' then why say 'main class'?The point is not that public is there or not. The point is that I changed access modifier which caused main(string[] args) to be invisible to JVM. So why does JVM say main class and not main() method?
P.S. If this a stupid question then I really regret asking it.
Edit:- Here is the error message
Error: Could not find or load main class Hello.java
There are two problems here.
main()
must be declared as public static void
.However the real problem was your command line. Clearly it was
java Hello.java
It should have been
java Hello
There is no such class here as Hello.java
. The name of the class is Hello
.