Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

[Java] How come I can't compile this?

  1. Dec 23, 2014 #1
    I wrote a very simple Java application in Notepad++ and saved it in the Documents inside of File Explorer. Then I opened the command prompt and typed javac GetStarted.java but it says 'javac' is not recognized as... So how do I compile this?
     
  2. jcsd
  3. Dec 23, 2014 #2

    ShayanJ

    User Avatar
    Gold Member

    Seems to me that you didn't add the javac path to the PATH environmental variable!
     
  4. Dec 23, 2014 #3

    Borg

    User Avatar
    Gold Member

    Note also that javac is not part of the Java Runtime Environment (JRE) that is installed on most computers. You have to have the Java Development Kit (JDK) installed and have your path pointed at it's bin directory where javac is installed as Shyan stated above.
     
  5. Dec 24, 2014 #4
    Then how to add the javac path to the PATH environmental variable?
     
  6. Dec 24, 2014 #5

    Borg

    User Avatar
    Gold Member

    Assuming that you have Windows. Go to Control Panel. Select System and then Advanced System Settings. From there you will get a dialog with 5 tabs. Select the Advanced tab and Environment Variables button on the bottom. That will bring up a dialog with two sections. The bottom section has administrative values that apply to every user. If you don't have admin rights, you can enter the path info on the top section but you still need to know what you're doing.
     
  7. Dec 24, 2014 #6

    ShayanJ

    User Avatar
    Gold Member

  8. Dec 24, 2014 #7
    But what's the PATH info that I need to enter to the top section?
     
  9. Dec 24, 2014 #8

    phinds

    User Avatar
    Gold Member
    2016 Award

    You have to figure out where the executable you want the execute IS and add a path to that folder.
     
  10. Dec 24, 2014 #9

    Borg

    User Avatar
    Gold Member

    If you don't have admin access, you can update your path by creating a new Path variable in the top section and setting the value to the directory where your javac program is located. My javac.exe is located in C:\Java\jdk1.7.0\bin so it would look like this:

    Path.png

    Enter the path for your javac and it should work. This will append your user Path to the Path that all users get in the lower section. Once you have added the javac path, you can confirm that it has been set by opening a command prompt and typing the word 'set'. This will show you all of the variables that have been set for your system. You should see a PATH variable with a good number of directory paths separated by semicolons. Your new javac path should be at the end. You should also be able to type javac at this point and it will display the program's run options.
     
  11. Dec 25, 2014 #10
    After I typed 'set', I did see lots of things. But when I typed javac GetStarted.java, it still says 'javac' is not recognized as...
     
  12. Dec 25, 2014 #11

    Borg

    User Avatar
    Gold Member

    Was the directory where your javac is located part of the Path?
     
  13. Dec 25, 2014 #12
    I guess so.
     
  14. Dec 25, 2014 #13

    Borg

    User Avatar
    Gold Member

    I guess so? Really? I can't help if you can't even verify that.
     
  15. Dec 25, 2014 #14
    But you know what? This is too complicated. I think I should get a Java-specific IDE rather than doing it with Notepad++. Because Notepad++ is just a text editor, I have to do this path thing every time I need to compile something. So What Java-specific IDE would you guys recommend?
     
  16. Dec 25, 2014 #15

    Borg

    User Avatar
    Gold Member

    You will have to have your path configured with an IDE also. Once it is set, you won't have to set it again.
     
  17. Dec 25, 2014 #16
    So with a text editor like Notepad++, you would have to configure the path every time?
     
  18. Dec 25, 2014 #17

    Borg

    User Avatar
    Gold Member

    No. just once.
     
  19. Dec 25, 2014 #18

    Borg

    User Avatar
    Gold Member

    Think about this. How does an Operating System (OS) like Windows know where a program is located when you want to run it? There are three ways - you can find the program yourself and run it from that location, you can run the program from another location by entering the path (or relative path) to the program or, as we've been trying to show you, the OS can find it for you if the program is in one of the directories specified in the Path.

    The Path variable tells the OS where to look for programs that it can run without having to specify where those programs are located. In the first two cases, you have to specify where a program is located each time. But, with the Path variable, the OS will find it for you. This is why we've been trying to help you to set up the location of javac in your path. This is an important thing that you're going to have to know and understand if you're going to learn programming.
     
  20. Dec 25, 2014 #19
    So what's the problem? I wrote my Java application and saved in the Documents inside File Explorer, I'm using Windows 8. Then I go to the Computer, Properties, System, Advanced System Settings, Environment Variables, in the top section, I typed Path, with C:\Program Files\Java\jdk1.8.0_40\bin and I opened the command prompt and typed javac GetStarted.java but it says 'javac' is not recognized as...
     
  21. Dec 25, 2014 #20

    Borg

    User Avatar
    Gold Member

    Is javac.exe located in your C:\Program Files\Java\jdk1.8.0_40\bin directory?

    P.S. I've got to leave for an hour.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: [Java] How come I can't compile this?
  1. Java compile problems (Replies: 2)

  2. Java Compilation (Replies: 4)

Loading...