4

I have set Path and ClassPath environment variables. But still I am unable to compile my HelloWorld.java program from command prompt. Please help me compile and run java program from command prompt

CLASSPATH C:\Program Files\Java\jre6\lib

Path C:\Program Files\Java\jre6\bin\

2
  • 2
    Can we get your error message? Commented Jun 13, 2011 at 15:44
  • Can we see some code where it fails? Commented Jun 13, 2011 at 15:45

5 Answers 5

3

You need to add JDK's directory to your path variable (not your JRE's path as you are actually doing it). JDK is usually in:

C:\Program Files\Java\jdk1.6.0_xx\bin\

Where xx stands for update number you have installed. Then just compile HelloWorld by using:

C:\Your\dir\where\HelloWorld\Is\>javac HelloWorld.java

In case you don't have JDK installed and you have only JRE installed, you won't be able to compile anything. You will need to download and install JDK properly to do Java Development in general (including compiling stuff).

Sign up to request clarification or add additional context in comments.

1 Comment

From where should I install jdk?
1

You need a JDK to compile classes rather than a JRE. The JRE is used for running Java applications (the JDK can also do this, but you cannot distribute the JDK).

When you have installed a JDK, ensure that the JDKs bin directory is on your path. You can then compile your Java classes using the javac.exe command.

Comments

0

PATH must be like

C:\Program Files\Java\jdk1.6.0\bin (This is on my system)

That is must point to JDK's bin not the jre's bin.Hope this helps.

Comments

0

You should also have your current directory in the CLASSPATH.

set CLASSPATH=.;C:\Program Files\Java\jre6\lib;

Comments

0

You could try writing cd C:\examples\ch01\ATM then press enter and that will change your directory. This allows you to write for example java ATMCaseStudy, then press enter. This should work if you placed your directory in C with your JDK in the same place.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.