I’m a beginner in Java and I created this class:
class test
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
as test.java, and when I compiled it with this cmd:
javac C:\Users\Aimad\Desktop\test.java
and then:
java C:\Users\Aimad\Desktop\test.class
I received this error :
Could not find or load main class C:\Users\Aimad\Desktop\test.class
The problem with what you have written is that you have added “.class”. By writing this you have instructed Java.exe to look for a class file called “class” in a directory called “test” underneath the one you are currently in. To make you code work remove the “.class” extension and you need to navigate to the file in the command line first. Additionally, the class that holds your main method must be declared as “public”.
Code
Command Line