Search code examples
javacmdwindows-8.1javac

Compile a java file using javac


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.


Solution

  • 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).