wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes setting up jdk Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "setting up jdk" Watch "setting up jdk" New topic
Author

setting up jdk

Jimmian Lin
Greenhorn

Joined: May 31, 2008
Posts: 16
Hi

I just started learning java from HeadFirst, and I was hoping someone could help me out with two questions.

1. How do I go about downloading the API documentation. I went onto the sun website under the API section (or so I thought) but I did not see a button that said to download it.

2. I tried setting my PATH variable under both user and system variables, to include C:\Program Files\Java\jdk1.6.0_06\bin. I thought this act was supposed to allow me to use the javac command in any directory rather than having to enter the bin directory. It doesn't seem to work for me. Did I misunderstand what changing the PATH variable was supposed to do?

Thank you.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Welcome to JavaRanch!

After updating the PATH variable, you will need to open a new Command Prompt. Depending on your operating system, you might even need to reboot.

The API documentation can be downloaded from the Java SE Downloads page. Scroll down to the "Java SE 6 Documentation" download near the bottom of the page.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Jimmian Lin
Greenhorn

Joined: May 31, 2008
Posts: 16
Thanks for the suggestion. However, I tried starting a new command prompt and also rebooting, however whenever I typed "javac HelloWorld.java" inside the directory that is not the bin directory, I would get a response like "javac is not recognized as an internal or external command"
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Hmmm... In your PATH setting, are there any spaces before or after that path? If so, you need to remove those spaces.

After that, here are a couple of things to verify:

After rebooting, does your PATH variable still include C:\Program Files\Java\jdk1.6.0_06\bin?

And is C:\Program Files\Java\jdk1.6.0_06\bin really the correct path? (Or did you install somewhere else?)
Jimmian Lin
Greenhorn

Joined: May 31, 2008
Posts: 16
Oops, it turns out I had an extra space there. Thanks, the command doesn't error now. One more thing though. Am I required to be in the bin folder where the source code is saved in order to javac something, because it would give me a "file not found" error otherwise. Doesn't that sort of defeat the purpose of setting the PATH variable since I would have to move my way towards the bin directory anyway?
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

If you have correctly set up the JDK's bin directory in the PATH, then no, you should not have to be in that bin directory for the javac or java commands to work. They should work from any where. Note, as Marc mentioned, that in windows, changes to system environment variables do not affect a currently open command window. You'll need to open a new command window in order to "see" the changes. (On older versions of Windows (pre-XP) you may need to reboot.)

In a new command window, type the command:

echo %PATH%

and make sure you are seeing the JDK's bin directory in the response that gets printed out.
[ May 31, 2008: Message edited by: Mark Vedder ]
Jimmian Lin
Greenhorn

Joined: May 31, 2008
Posts: 16
So I tried echo %PATH% and the path seems to be listed correctly. I also tried to reboot my computer (I'm using Vista) and opening a new command prompt. I attempted to type javac HelloWorld.java inside another folder other than bin (where the source code is located) but it says
"javac: file not found: HelloWorld.java Usage: javac <options> <source files>
use -help for a list of possible options".
Could the problem be that I'm using Vista and not XP?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Jimmian Lin:
... I attempted to type javac HelloWorld.java inside another folder other than bin (where the source code is located)...

Whoa... The bin directory is for Java's inner workings. You should not be adding your own files to that directory. Instead, keep things clean by creating your own directories for source and class files.

The PATH variable will allow your system to find the executable "javac," but it will not tell javac where to find source files. So when you provide javac with a file location, it must be specified relative to the current directory. Generally, it's best to change the directory in the Command Prompt to wherever your source file is located.
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Ah... ok... that is the javac program itself saying that it cannot find the file HelloWorld.java. The fact the line starts with "javac:" basically means "that it is javac outputting the following message..." and that message is "I (i.e. javac) cannot find the file HelloWorld.java. My usage is..."

When typing the command

javac HelloWorld.java

you need to be in the directory that contains that file.
[ May 31, 2008: Message edited by: Mark Vedder ]
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Oops, I didn't catch that you had placed your source code in the JDK's bin directory. I'm glad Marc caught that.
Jimmian Lin
Greenhorn

Joined: May 31, 2008
Posts: 16
Ah,okay. Thank you Marc and Mark for the clarification. Is there anyway to set a default directory that my command prompt window will "start out" in so that everytime I open the command prompt, I won't have to browse my way to the folder that contains my source files?
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Originally posted by Jimmian Lin:
Is there anyway to set a default directory that my command prompt window will "start out" in so that everytime I open the command prompt, I won't have to browse my way to the folder that contains my source files?


Yes.
  • Create a shortcut to the command window. (You can copy "cmd.exe" from "C:\Windows\System32" and "paste as shortcut" on your desktop, quick launch bar or start menu.) Alternatively, you can use the shortcut that is already present in the Start Menu's "Accessories" folder.
  • Right Click the shortcut and select "properties".
  • On the "Shortcut" tab in the properties window, edit the "Start in" text field's value to the path to your source code's directory.


  • Also note that in Vista, in Windows explorer, if you hold down the shift key when right clicking on a folder (or when pressing the "Context Menu" key if your keyboard has one), an "Open Command Window Here" option will be available. That will open a command prompt with that directory as the present working directory. Google "Vista Open Command Window Here" for a registry hack if you do not want to have to hold the shift key down when right clicking.

    For XP, there is a Powertoy that permanently puts that option in the context menu.
    [ May 31, 2008: Message edited by: Mark Vedder ]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: setting up jdk
     
    Similar Threads
    J2SE SDK
    java on command
    Error by compiling textfile Could not find the main class: HelloWorldapp. Program will exit
    bartender, I have got the same problem as Sri Addanki for the error of noClassDefFoun
    javac not recognized as an internal external command