2

I'm trying to run a basic "Hello World" app from the command line on windows 10 using

javac MyFirstProgram.java

but i receive

'javac' is not recognised as an internal or external command, operable program or batch

naturally, the first thing i did was google the problem and many solutions were presented, tried a few but nothing worked, has anybody else experienced this?

Treeno1
  • 139
  • 1
  • 2
  • 18
  • 1
    You need to add the location of your JDK to your PATH variable, if you wish to call javac.exe without the path. Or, you can simply call it via the full path to javac.exe from your JDK installation. – ManoDestra Jun 21 '16 at 14:28
  • Either provide the full path to javac, something like `"c:\Program Files\Java\jdk1.8.0_92\bin\javac"` or add the path to your PATH environment variable. – assylias Jun 21 '16 at 14:29
  • 1
    You need to update the PATH environment variable, as is described in the [JDK installation instructions](http://docs.oracle.com/javase/8/docs/technotes/guides/install/windows_jdk_install.html#BABGDJFH). – Jesper Jun 21 '16 at 14:29
  • I now know where the location of the jdk is, so when i open the command prompt im presented with "C:\Users\My Name>" the whole command is.... "C:\Users\My Name> C:\Program Files\Java\jdk1.8.0_91\bin\javac MyFirstProgram.java" it just returns 'C:\Program' is not recognised as an internal or external command ?!..im confused @assylias – Treeno1 Jun 21 '16 at 15:35
  • @Treeno1 because the path has spaces, you need to put the command in quotes, like I did in my comment above. – assylias Jun 21 '16 at 16:21

2 Answers2

3

Steps to fix this error in windows 10/8/7

1.Check your javac path on Windows using Windows Explorer C:\Program Files\Java\jdk1.7.0_02\bin and copy the address.

2.Go to Control Panel. Environment Variables and Insert the address at the beginning of var. Path followed by semicolon. i.e C:\Program Files\Java\jdk1.7.0_02\bin; . Do not delete the path existent, just click in and go to the left end and paste the line above. Do not try anything else, because you just need to link your code to "javac.exe" and you just need to locate it.

3.Close your command prompt and reopen it,and write the code for compile and execution. enter image description here

SaiKiran
  • 6,244
  • 11
  • 43
  • 76
2

You need to add the location of your JDK to your PATH variable, if you wish to call javac.exe without the path.

set PATH=%PATH%;C:\path\to\your\JDK\bin\dir

Then...

javac.exe MyFirstProgram.java

OR, you can simply call it via the full path to javac.exe from your JDK installation e.g.

C:\path\to\your\JDK\bin\javac.exe MyFirstProgram.java
ManoDestra
  • 6,325
  • 6
  • 26
  • 50