Avatar ·

Error "Could not find or load main class" in Java: causes and solution

Hi everyone! I just started learning Java and already ran into a problem that completely stumped me. I wrote a simple "Hello, World!" program in a file `HelloWorld.java`: ```java public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } } ``` I compiled it with the command `javac HelloWorld.java` — it went successfully, and a `HelloWorld.class` file appeared. But when I try to run the program with the command `java HelloWorld`, the command line gives an error: ``` Error: Could not find or load main class HelloWorld ``` I checked: the `HelloWorld.class` file is definitely in the same folder where I am in the terminal. I tried different options — wrote `java HelloWorld.class`, `java -cp . HelloWorld` — nothing helped.