This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Running compiled code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Running compiled code" Watch "Running compiled code" New topic
Author

Running compiled code

Amar Das
Greenhorn

Joined: Dec 18, 2000
Posts: 1
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.
Axl Rose
Greenhorn

Joined: Dec 18, 2000
Posts: 16
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
naveen sahu
Ranch Hand

Joined: Nov 15, 2000
Posts: 48
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Running compiled code
 
Similar Threads
trouble with my first assignment - Head First Java
Exception in thread "main"
Java beginning
Problem with Hello World
trouble with my first assignment - Head First Java