Forums Register Login

Running compiled code

+Pie Number of slices to send: Send
I was just testing the installation of java on my machine. I wrote the following program and saved it as Hello.java. Then I compiled it using javac Hello.java. It compiles fine. But when I try to run it using java Hello I got the following error messageException in thread "main" java.lang.NoClassDefFoundError: Hello
My code sample for Hello
-------------------------
public class Hello {
public static void main (String[] args){
System.out.println("Hello World!");
}
}
What is wrong. Thanks for help.
+Pie Number of slices to send: Send
Amar, you need to set your classpath so that it points to the directroy of your Hello.class file.
you can do this easily from the DOS
let us assume that your Hello.class file is in the following directory
C:\Amar\classes\Hello.class
then you set the path in the dos like this way
C:\>set classpath=%classpath%;c:\Amar\classes
and then you can run the class using <java Hello>
if your class is inside a package, you follow the same step
and point to the directory of your package.
Hope this can help
+Pie Number of slices to send: Send
 

Originally posted by Amar Das:
I was just testing the installation of java on my machine. I wrote the following program and saved it as Hello.java. Then I compiled it using javac Hello.java. It compiles fine. But when I try to run it using java Hello I got the following error messageException in thread "main" java.lang.NoClassDefFoundError: Hello
My code sample for Hello


after compilling see the directory listing of your current directory in which your class hello existing.
read the name of that class carefully with propercase (upper/lower) and then execute command
java "your class name wihout extension"
every thing will be fine.
this is the mistake due to uppercase lowercase mistake & nothing else.
check name of the .class file created after compillation and then execute above command
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1003 times.
Similar Threads
trouble with my first assignment - Head First Java
Problem with Hello World
Exception in thread "main"
trouble with my first assignment - Head First Java
Java beginning
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 02:28:44.