Celeb Glow
general | March 14, 2026

Error: Could not find or load main class(Java)

I am using java in ubuntu machine. I can run java program from my eclipse. But I have some work that that I have to perform from command prompt. I could compile java program using javac HelloWorld.java command and its create the HelloWorld.class in same directory. But when I run java HelloWorld command its gives me following error.

Error: Could not find or load main class

I dont know why???

can anyone tell me what's the problem?

3 Answers

Check you CLASSPATH. It should contain current directory (aka ".").

2

Did you correctly create a main method in your java file, did you name the java file exactly like the class?

$ cat HelloWorld.java
public class HelloWorld { public static void main(String[] args) { System.out.println("Bonjour le monde !"); }
}
$ javac HelloWorld.java
$ java HelloWorld
Bonjour le monde !

I was executing

java HelloWorld.class

instead of

java HelloWorld

Problem Solved!

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy