I have set two environment variables for JAVA JDK.

1. PATH=C:\Program Files\Java\jdk1.6.0_26\bin;%PATH%

2. CLASSPATH=C:\Program Files\Java\jdk1.6.0_26\lib\tools.jar

When I compiled the file using javac it was done successfully but when I ran the file using java command I got the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld

You don't have to set the classpath to the JDK folders. The java command knows where they are.
Are you setting the variables in a batch file or in the whole system?
Open a commmand prompt and enter:
SET
Copy and paste the full contents here so we can see what you have set.
Here is my settings:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

D:\Norms\Norms Tools>set
ALLUSERSPROFILE=C:\Documents and Settings\All Users
ANT_HOME=C:\Program Files\apache-ant-1.6.5
APPDATA=C:\Documents and Settings\Owner\Application Data
CATALINA_HOME=D:\Program Files\Apache Software Foundation\Tomcat 5.5
CLASSPATH=D:\JavaDevelopment;.
CLIENTNAME=Console
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=TIGERDIRECT
ComSpec=C:\WINDOWS\system32\cmd.exe
DEV_DRIVE=D:
DEV_HOME=D:
DOCS_HOME=C:
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\Owner
JAVA_HOME=C:\Program Files\Java\jdk1.5.0_04
JAVA_RUN=D:\JavaDevelopment\runtime
JDK_HOME=D:\Java\jdk1.6.0_02
JMFHOME=E:\Java\JMF2.1.1e
LOGONSERVER=\\TIGERDIRECT
NUMBER_OF_PROCESSORS=1
OS=Windows_NT
Path=C:\Program Files\PHP\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wb
em;C:\Program Files\Java\jdk1.5.0_04\bin;C:\BatchFiles;C:\Program Files\Support
Tools\;C:\WINDOWS\system32\WindowsPowerShell\v1.0;C:\Program Files\QuickTime\QTS
ystem\
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PSC1
PHPRC=C:\Program Files\PHP\
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 31 Stepping 0, AuthenticAMD
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=1f00
ProgramFiles=C:\Program Files
PROMPT=$P$G
QTJAVA=D:\Java\jre6_20\lib\ext\QTJava.zip
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\DOCUME~1\Owner\LOCALS~1\Temp
TMP=C:\DOCUME~1\Owner\LOCALS~1\Temp
TOMCAT_HOME=C:\Java\jakarta-tomcat-3.2.4
USERDOMAIN=TIGERDIRECT
USERNAME=Owner
USERPROFILE=C:\Documents and Settings\Owner
windir=C:\WINDOWS
WORK_DIR=D:\JavaClass

D:\Norms\Norms Tools>

To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.

commented: Time to patch jave 1.6_02 is few months old ;) +16

Here's my Settings:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\p4>SET
ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\p4\Application Data
CLASSPATH=C:\Program Files\Java\jdk1.6.0_26\lib\tools.jar
CLIENTNAME=Console
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=HIMANSHU
ComSpec=C:\WINDOWS\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\p4
LOGONSERVER=\\HIMANSHU
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
PATH=C:\Program Files\Java\jdk1.6.0_12\bin;%PATH%;C:\Program Files\Java\jdk1.6.0
_12\bin;C:\Program Files\Java\jdk1.6.0_12\bin;%PATH%
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PSC1
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 4 Stepping 1, GenuineIntel
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=0401
ProgramFiles=C:\Program Files
PROMPT=$P$G
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\DOCUME~1\p4\LOCALS~1\Temp
TMP=C:\DOCUME~1\p4\LOCALS~1\Temp
USERDOMAIN=HIMANSHU
USERNAME=p4
USERPROFILE=C:\Documents and Settings\p4
windir=C:\WINDOWS

C:\Documents and Settings\p4>

Edit

PATH=C:\Program Files\Java\jdk1.6.0_12\bin;%PATH%;C:\Program Files\Java\jdk1.6.0
_12\bin;C:\Program Files\Java\jdk1.6.0_12\bin;%PATH%

to

PATH=C:\Program Files\Java\jdk1.6.0_12\bin;

Any good reason you want to create CLASSPATH?

I changed the PATH in Environmental Variables as suggested by peter and removed the CLASSPATH but now it is saying "javac is not recognized as an internal or external command, operable program or batch file."

How did you change PATH? Did you you adjust also Java version number to reflect your installation (1.6.0_versionNum)? What operating system you have and what Java installation you used (32bit/64bit)?

Sorry Very very sorry! my mistake to include wrong version number.

And Thanks a lot after all ran my program.

Thanks to Daniweb Quick help.

there is an another solution
just set the classpath to the location of your program
the error will be removed

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.