EXECUTION PROBLEM

I've problem regarding executing a java program.

The following is the java program:

class Sample

{

public static void main(String args[])

{

System.out.println("Hello World!!");

}

}

The above program is saved as Sample.java and then compiled thru the command:javac Sample.java

Compilation successful;a .class file generates: Sample.class

But when I execute it by the command: java Sample

the following error message appears:

Exception in thread 'main' java.lang.NoClassDef Found. Error:Sample

I know that it is a runtime environment variable problem or something like that.But I don't know how to fix it. I've installed and then uninstalled and and again reinstalled to get rid of it.But all in vain.

PLEASE SUGGEST A SOLUTION HOW TO SOLVE THIS PROBLEM.

THANKS

[868 byte] By [Cyrus_71a] at [2007-10-3 3:11:10]
# 1

You probably have a classpath set (environment variable CLASSPATH).

Either unset it ("unset CLASSPATH" or "set CLASSPATH=", depending on your environment) or always provide the classpath when compiling and executing. In your simple case you probably need only "." as the classpath:

javac -cp . Sample.java

java -cp . Sample

good luck

JoachimSauera at 2007-7-14 21:02:01 > top of Java-index,Java Essentials,New To Java...
# 2
PLEASE DON'T ABUSE THE SHIFT KEY. IT TURNS PEOPLE OFF ANSWERING QUESTIONS.tryjava -cp . Simple
mlka at 2007-7-14 21:02:01 > top of Java-index,Java Essentials,New To Java...
# 3

dear,

prob is that compiler not found classfile path.

so first u set ur classpath .

if u install java in c driive then first go in c.

now see where ur classfile save.suppose it save in c:\A then

type

c:\>set classpath=c:\A

now it run ur classpath.

then use java command

u get ur results

Alpa

Alpaa at 2007-7-14 21:02:01 > top of Java-index,Java Essentials,New To Java...