Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Command Prompt cannot find programname.java when using javac

    Please help me out with this. I have Vista and the easier way to compile java programs using Textpad is just not working. I have a deadline soon so I'm using command prompt.

    I have ensured that javac is now recognized in command prompt, and even "programname.java" is recognized in the command prompt, but for some reason, when I type javac programname.java it tells me:


    C:\Users\name>javac programname.java
    javac: file not found: programname.java
    Usage: javac <options> <source files>
    use -help for a list of possible options

    Thank you so much for your help!

    Additional information:

    I added javac to the "Path" system variable, following instructions I found elsewhere on this thread. When I type java -version it all looks good.

    I decided when it initially failed to find programname.java to add the location of the .java to the "Path" as well. I can now open the program using command prompt, but when I try javac it can't find it. I am perplexed.

    The file is called MakeChange.java, if that helps you in explaining what to do at all. It is located in "C:\Users\Dbo\Documents\Computer Science"

  2. #2
    Regular Coder cs_student's Avatar
    Join Date
    Oct 2009
    Location
    ~/
    Posts
    195
    Thanks
    2
    Thanked 22 Times in 22 Posts
    Try
    Code:
    >> cd "C:\Users\Dbo\Documents\Computer Science\" 
    >> javac MakeChange.java
    >> java MakeChange
    If that doesn't work make sure that MakeChange.java is spelled right and is in the correct directory.

  3. #3
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    660
    Thanks
    31
    Thanked 100 Times in 94 Posts
    Greedy algorithms ftw! To state the obvious it would make your life so much better if you used an IDE such as Eclipse or NetBeans.

    To run a java program using command line:
    Start->Control Panel->System->Advanced Settings->Environment Variables

    Then, choose to edit the "Path" variable. Add the path of the bin directory of your JDK installation to your path environment variable (ie: put a semicolon and paste it on to the end). A sample JDK bin directory would be C:\Program Files\Java\jdk1.6.0_16\bin, though it may be different based on where you installed.

    Then open up your command prompt and run "cd" to go to where you are creating your source files, like cs_student mentioned.
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com

  4. #4
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. I had some recollection of a command to change the directory but I had forgotten what it was. Fantastic. It's working now. Btw, just out of curiosity, how can I make it so the command prompt always opens in that directory?

    P.S. I missed semicolons in my program...

  5. #5
    Regular Coder cs_student's Avatar
    Join Date
    Oct 2009
    Location
    ~/
    Posts
    195
    Thanks
    2
    Thanked 22 Times in 22 Posts
    In windows you can create a shortcut on your desktop, press ctrl+r then type in the drive and directory you want to go to, or create a batch script which can change your directory accordingly (if you want to choose from multiple directories).

    Best of luck,


    cs_student


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •