This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Now when I try to compile my java class at command prompt as "javac SomeClass.java" , I get an error message "'javac' is not recognized as an internal or external command,
operable program or batch file."
Does it mean that path I have set is for compiled program ? i e if I want to run java SomeClass, then this will work ? So which path do I need to set to compile the program ?
The problem is that command "javac" is not indentified. Do a search for the file "javac.exe" and discover the directory (folder) where that file is placed. And then, you have to set the path to that directory.
You have two options:
1) In the command prompt write set path=C:\Program Files\Java\jre1.5.0_06\bin and then you can compile the program by simply typing javac anyProgram.java
2)Write click my computer, go to environment variable and add the the path C:\Program Files\Java\jre1.5.0_06\bin to the Path variable
If you chose the 2nd option, you will need not to set the path every time you open the command prompt.
Joined: Apr 16, 2009
I did following.
I kept my source code directly under C:\
At the cmd prompt, I executed following exe file "C:\Program Files\Java\jdk1.6.0_11\bin>javac c:\AnyClass.java" So the source code did compile and class file is created under c directory.
Now when I do "C:\Program Files\Java\jdk1.6.0_11\bin>java c:\AnyClass"., I get following error
C:\Program Files\Java\jdk1.6.0_11\bin>java c:\AnyClass
Exception in thread "main" java.lang.NoClassDefFoundError: c:\AnyClass
Caused by: java.lang.ClassNotFoundException: c:\AnyClass
at java.security.AccessController.doPrivileged(Native Method)
Could not find the main class: c:\AnyClass. Program will exit.
I tried to keep classfile in different folder and try to execute from there, but same error.
It is actually set path=C:\Program Files\Java\jre1.5.0_06\bin;%PATH% or something like that. Otherwise other programs in the PATH will vanish. And if you set up the PATH like that, you will only have that PATH for the lifetime of that command prompt window. Fuller instructions can be found by looking up your problem in this "common problems" page.
This is all getting confusing....
First things first,
1. You need to have jdk installed to compile java files . Default Install directory is : "C:\Program Files\Java\jdkXXXXXX" where XXXXXX is the installed jdk version.
2. Set value of the PATH variable as follows:
To set the PATH permanently, add the full path of the jdk1.6.0_<version>\bin directory to the PATH variable. Typically this full path looks something like C:\Program Files\Java\jdk1.6.0_<version>\bin. Set the PATH as follows on Microsoft Windows:
Click Start > Control Panel > System on Windows
Click Advanced > Environment Variables.
Add the location of bin folder of JDK installation for PATH in User Variables and System Variables. A typical value for PATH is:
PATH environment variable is a series of directories separated by semi-colons (;) and is not case sensitive. Microsoft Windows looks for programs in the PATH directories in order, from left to right.
You should only have one bin directory for a JDK in the path at a time. Those following the first instance are ignored. If one is already present, update it to jdk1.6.0_<version>\bin.
If you are not sure where to add the path, add it to the right end of the PATH in the User Variables.
The new path takes effect in each new command window you open after setting the PATH variable.
3. To compile any java file, cd to the directory where it is located and type the command:
4. To execute a class file, cd to the containing directory and type:
Hope this helps.....
Joined: Oct 13, 2005
That should help. I would add:
It is a good idea to create a "java" folder to keep all your .java and .class files.
You must download java jdk1.6.0 or something like that. Set environment variable modify path to add jdk1.6.0 bin path.
in command prompt type this : path c:\program files\java\jdk1.6.0\bin or you can create batch file also.
The problem is that he has his path set to a JRE bin folder, not a JDK. JRE install does not include javac utitily, only java and some others. You need JDK to get the javac utility.
Simple fix: download the JDK, NOT the JRE. Then go find the bin folder for that as you did with the JRE, append it to the PATH variable, then you'll be fine. Delete yor JRE reference as well from the path variable. Nothing will happen if you don't. Windows will simply look in that path first for javac/java commands but won't find the javac command and thenw ill go to the next entry in the PATH variable (the right one with the JDK path).
You can simply type javac at the ommand prompt to test it. Remember, if you leave a command prompt/shell open and do these changes, they won't take affect until you cloe and open a new shell.
Windows OS Shipped with default JRE not JDK
If your system does not have JRE, Any site which has applet can prompt you to download JRE automatically to your system. And you might have JRE in that scenario.
JRE: Runtime environment.
JDK: Development kit
So you can not develop java application without a JDK, what it names speaks a lot.
So in JRE you will not find java compiler which is javac.
Do not confuse yourself. Java is an open standard as per the rule every OS must have JRE.