Computer OS: Windows 7 Language: Java
After long time back I am using java, I am getting problem while running the hello world program:
public class Hello
{
public static void main (String args[])
{
System.out.println ("Hello World!");
}
}
I saved this code in Hello.java File, and then compiled using cmd:
C:\Users\XYZ\Desktop>javac -version
javac 1.6.0
C:\Users\XYZ\Desktop>javac Hello.java
C:\Users\XYZ\Desktop>java Hello
Error: Could not find or load main class Hello
C:\Users\XYZ\Desktop>
Can you explain why the error message above was thrown?
The main() method must be called from a static method only inside the same class.
You are missing one "}" at the end of the program
public class Hello
{
public static void main (String args[])
{
System.out.println ("Hello World!");
}
}
and then try
java -cp . Hello
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With