Problem in execution of JAVA programs

Status
Not open for further replies.

g_goyal2000

Youngling
I have J2SE Development Kit 5.0 as well as J2SE Runtime Environment 5.0 Update 3 installed on my machine running Windows XP SP2. I use MS-DOS for compiling & running Java programs.

I have installed J2SE Development Kit 5.0 in directory D:\jdk1.5.0
& J2SE Runtime Environment 5.0 Update 3 in default installation directory D:\Program Files\Java\jre1.5.0_03

When I compile any Java program using X:\javac <filename.java> command, the file complies properly & all the classes are formed.

But when I run the program using X:\java <classname> command, it gives me an error
"Exception in thread "main" java.lang.NoClassDefFoundError: Gaurav"

Even a simple "Hello World" program isn't running.
Here's the coding for "Hello World".

class Gaurav{
public static void main (String args[]){
System.out.println("Hello World");
}
}

I have set the paths properly.
Here is the path.

SET PATH=D:\jdk1.5.0\BIN;D:\jdk1.5.0\DEMO;D:\jdk1.5.0\INCLUDE;D:\jdk1.5.0\LIB;D:\jdk1.5.0\JRE;D:\Windows\System32\wbem\;D:\Windows\System32\;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH

My institute has JDK 1.3 installed on the machines & the all the Java programs (even Hello World) work fine. I try all the programs at home that I try (and also work fine) at my institute but none work at home PC.

What's the problem?
Kindly help.
 

desertwind

Cyborg Agent
And what does this one have to do with Open Source ? Must in QnA. Reporting.

Back to your Q. I 'm no Java expert. well, just a simple note, have you set the filename similar to the Classname ? on the above example, the filename must be Gaurav.java
 

#/bin/sh

Journeyman
public class HelloWorld {

public static void main (String[] args) {
System.out.println("Hello, world!\n");
}

}


Java of course is case-sensitive, so the class name must be exactly as declared in the class file, and the same as the file name.
 

icecoolz

Cyborg Agent
two things:

1) Make sure the filename and the class name's are identical including case's.

2) Setting the PATH alone is not enough. You will need to set the CLASSPATH as well. This can be done on the system level or on the Command prompt level. To run the current set of comiled java classes In the command window type the following:

Set CLASSPATH=%CLASSPATH%;.

This will take the existing class path and append the "." to it which is to indicate the current working directory. Now run the java program and it should work.

hope this helps.
 
Status
Not open for further replies.
Top Bottom