This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
i am beginning a java programming class and have downloaded jdk1.6.0_30 and it recognizes the java command and confirms the version of java, but will not run the javac command and will not return a version for javac. I have spent hours retrying the download and can't get javac to work. one theory is that I originally doenloaded the JRE for 1.6.0_31 only to start and it created a separate folder in the Java folder for the jre6 vs. the jdk and the reinstall put the JRE in the 2nd file folder jre6 again. Does the jre6 need to be in the same folder as the remainder of the jdk1.6.0 files? that's just a guesss. I simply can't get javac to work and am going in cirlces. any helpm would be really welcome. Thank you.
Do you see javac in your jdk1.6.0_30/bin ? How are you trying to compile? Command Line?
Please post more details on your execution environment and any error messages.
Joined: Apr 14, 2012
hi Rajeev. Thanks for your reply. i see javac in my bin folder, but not javac.exe. I am trying to complie from the command line. A good example of the error is that when I try Javac Filename.java, it returns 'javac not recognized as an internal or external command...'. i tried uninstalling jdk today and reinstalling the latest 1.7 version. everything completed, but i still get same message whan attempting to compile and still do not see javac.exe in the 1.7 bin folder (I do see a file javac, but it has no extension).... This has to be something simple i am either missing in the download or install process. Everything else completes normally. I re-register with Oracle and i can see the java -version return the java 1.7, etc... I am still stumped. Any help would be really appreciated. Thanks
Always consult the oracle before asking a question.
Joined: Apr 14, 2012
ok. i now know the software is operational because i was able to navigate to the bin folder and compile & run the HelloWorld program while in that directory. Therefore, i must not have my variables set properly. I also can't copy my java files into the bin for compile so i have to rely on PATH and CLASSPATH and must not have them set properly. Here's what i have set up.
%JAVA_HOME% is set to: C:\Program Files\Java\jdk1.7.0_03\bin
CLASSPATH is set to: .;C:\Program Files\Java\jdk1.7.0_03\bin
PATH is set to: %JAVA_HOME%\bin;C:\Windows\etc..other stuff....
This must be wrong. Got the ideas from other posts on setup. I presume that if they were set properly that i could run javac and java commands from any command prompt, correct? i think i made some progress today, but still not where i need to be.
Any guidance would be helpful. Thanks
Joined: Apr 13, 2012
You said path is set to '%JAVA_HOME%\bin' if that's correct, you need to remove the '\bin' because its already defined in %JAVA_HOME%. And you should also add that to the end of your PATH variable, not the beginning.
You can also remove CLASSPATH, that's more for if you want the compiler (javac) to find your own 3rd party libraries and such without using the -cp switch.
Joe Raszewski wrote:. . . i was able to navigate to the bin folder and compile & run the HelloWorld program while in that directory. . . . I also can't copy my java files into the bin for compile so i have to rely on PATH and CLASSPATH and must not have them set properly. . . .
It is a serious mistake trying to work inside the bin folder. Progam Files is not for you to put your own work in. It is also a mistake to set your own classpath, even though some books tell you to. You can delete that classpath entirely and suffer no problems. Your %JAVA_HOME% variable should not end in bin. You can either set a JAVA_HOME which ends in jdk1.7.0_03 or similar, or put the whole path in the path variable entry. If you have bin in both, the computer will try to find a bin/bin folder which you haven’t got.
You know what error message you get if you supply a path to a non-existent folder? None at all! You might find our FAQ helpful.
Joe Raszewski wrote:%JAVA_HOME% is set to: C:\Program Files\Java\jdk1.7.0_03\bin
That should have been C:\Program Files\Java\jdk1.7.0_03 without the bin.
Note: For Java itself, the JAVA_HOME environment variable doesn't matter. Java doesn't use it. Some other programs do, but just for compiling Java source code with the JDK you don't need to set JAVA_HOME at all.
Joe Raszewski wrote:CLASSPATH is set to: .;C:\Program Files\Java\jdk1.7.0_03\bin
That is wrong. CLASSPATH is used by Java to find compiled *.class files. The bin directory of your JDK does not contain class files. It does not belong in the CLASSPATH.
It is best to not set CLASSPATH at all. If you leave it unset, Java will by default use the current directory "." as the classpath.
Joe Raszewski wrote:PATH is set to: %JAVA_HOME%\bin;C:\Windows\etc..other stuff....
That is correct. If you use JAVA_HOME in the PATH like this, then ofcourse JAVA_HOME has to be set too, but without the bin in it as I wrote above.
Joined: Apr 14, 2012
Thanks for everyone's help.
I finally got the PATH set and got my test program to compile and run. I am running a 2nd test with a program copied verbatim from my text. It's the I Rule The World progam and while I have copied it right from the book, i keep getting the missing return statement error. I cannot figure out the solution. I've tried placing the closing bracket in al positions, butt . Heres the program and the corresponding message. What am i doing wrong?