• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need guidance on how to get Javac compile to execute

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

What is the exact error message that you get?

Did you follow the installation instructions? Especially take note of step 4, setting the PATH environment variable.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe Raszewski wrote:Does the jre6 need to be in the same folder as the remainder of the jdk1.6.0 files?


No! If you change the default to the folder where you just installed a JDK you'll lose the JDK, including javac.exe.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Joe Raszewski
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As stated earlier, make sure you add the 'bin' folder (the folder where javac is) to your path. It should look something like this --> C:\Java\jdk1.6.0_30\bin\

Here, is a tutorial on doing so
 
Joe Raszewski
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Vince.

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.


User Variable

%JAVA_HOME% is set to: C:\Program Files\Java\jdk1.7.0_03\bin


System Variable

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
 
Vince Stout
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Joe Raszewski
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?





C:\Tracey's Files> javac MyFirstJavaApp.java
MyFirstJavaApp.java:7: error: missing return statement
}
^
1 error

C:\Tracey's Files>
 
Joe Raszewski
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S. the indentations are missing after the copy but they line up and are in line as per the program in the book...
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe Raszewski wrote:I have copied it right from the book


No you haven't. Java is case sensitive. Look carefully at the declaration of the main method.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe Raszewski wrote:P.S. the indentations are missing after the copy but they line up and are in line as per the program in the book...


UseCodeTags
 
Vince Stout
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let the compiler help you. It says your problem is on line 7. That is where you start looking. What looks different between line 7 in the book and yours?

To use code tags put code=java between sqauare brackets above your first line of code, and /code between brackets after your last line of code
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can add code tags for you.
 
Joe Raszewski
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joanne. Thank You. When I am working in Notepad it is very hard to distinguish Caps from small case. Until I copied that code into the forum, i could not see that the 'V' was capitalized. It now runs.

Thank you. I am on my way.
 
You get good luck from rubbing the belly of a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic