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 3


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

  • when I echo $CLASSPATH it shows the following path /opt/lucene-3.5.0/lucene-core-3.5.0.jar:/opt/lucene-3.5.0/contrib/demo/lucene-demo-3.5.0.jar:/opt/semanticvectors/semanticvectors-3.2.jar and when i echo $JAVA_HOME it shows /usr/lib/jvm/java-7-oracle
    – tetrapack
    Jan 15, 2014 at 10:27
  • Then add '.' to your $CLASSPATH with CLASSPATH=.:$CLASSPATH or as a paramater with java -classpath .:$CLASSPATH HelloWorld
    – ragol
    Jan 17, 2014 at 10:36

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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .