1

Ok now it feels like I've tried everything, can someone please tell me how I can compile a Java file ? My file/code looks like this:

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

And I have saved it as HelloWorld.java and in All Files. But the problem is that everytime I try to compile the Java file it says:

'javac' is not recognized as an internal or external command, operable program or batch file.

I have downloaded JDK and JRE, set/changed the path to C:\Program Files\Java\jre1.8.0_45\bin; but when I look through the commands I can't see the javac command anywhere!

I thought for a while that I may have downloaded the wrong JDK, but when I see what's supposed to include in JDK it says that javac is supposed to be there too - but I can't find it!

Any suggestion how to fix this ?

I use Windows 8.1 (I don't know if that helps but I write it just in case). I really need some help I've been trying to fix this for about 6 months now and it's getting really annoying not know what to do.

halfer
  • 19,824
  • 17
  • 99
  • 186
Nikki
  • 301
  • 1
  • 2
  • 18
  • 1
    @GregHilston I would say it's different. Op just pointed to the wrong installation (jre not jdk) that question is more about how to set the path – d0nut Jul 20 '15 at 17:34
  • @GregHilston I've already looked at it a few times and I've tried it and it doesn't work – Nikki Jul 20 '15 at 17:37

4 Answers4

3

Having the path C:\Program Files\Java\jre1.8.0_45\bin won't help you with the Java compiler javac, which is in the Java Development Kit (JDK) rather than the Java Runtime Environment (JRE).

As a first step, make sure your path includes a bin directory from some directory with "jdk" in the name.

I see that you've downloaded jdk-8u51-windows-x64.exe, which is (what I presume to be) the JDK installer. If it is the JDK installer from a reputable source, run it and and it should produce an directory containing the JDK in a predictable place (such as adjacent to the JRE, or in the root C: directory as seanhodges helpfully commented below).

Jeff Bowman
  • 90,959
  • 16
  • 217
  • 251
  • 2
    The JDK path would have been the "Install to" path specified on this page in the installer: http://codingfox.com/wp-content/uploads/2014/12/JDK-5.png – seanhodges Jul 20 '15 at 17:41
2

You need to add your java's installation bin folder to your windows path.

Additionally, the path you set was the the JRE not the JDK. You need the JDK to compile code.

https://www.java.com/en/download/help/path.xml

d0nut
  • 2,835
  • 1
  • 18
  • 23
1

javac can be found in the JDK directory - C:\Program Files\Java\jre1.8.0_45\bin is a JRE directory. JDK directories start with jdk.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
1

Before all, make sure you understand the differences between a JRE and a JDK:

  • The JRE (Java Runtime Environment) is used to execute java programs
  • The JDK (Java Development Kit) is used to compile java source code (and embed a JRE)

If you look into the bin folder inside your JDK installation path, you may find, among other commands, javac.

So all you have to do is to configure some environment variables:

  • JAVA_HOME to your JDK installation path, most likely C:\Program Files\Java\jdk1.8.0_51.
  • PATH, you should append :$JAVA_HOME$\bin to the existing path.

Then, you may be able to execute javac HelloWorld.java in a terminal without problem, since javac is available in the %PATH%

aveuiller
  • 1,511
  • 1
  • 10
  • 25