Friday 28 September 2007

These Environment Variables

One of the first problems I had with Java was adding the /bin of the Java SDK to my path variable. My problem with that was that all the books I read just stated it that way without explaining how. Now, I know I look back and laugh but some newbies out there aren’t laughing so this entry will be about doing just that and a little.

When you call commands like javac, and java from command prompt, it checks a certain environment variable for the path to the actual executables you are trying to call. This variable is called the “path” and can be accessed by right-clicking on the “My Computer” from the start menu of windows machines, selecting “properties” from the context menu, selecting the “Advanced” tab from the window that pops up and clicking on the “Environment Variables” button around the bottom of that tab in Windows XP. In Vista, its slightly different; when you right click “My Computer” and select properties, a window pops up. To the right of that window, click on “Advanced System Settings” and another window pops up from which you can select the “Advanced” tab. From then on, both operating systems are similar.

On the last pop up window (after clicking on the “Environment Variables” button), there are two list boxes. Scroll through the one below and select the “Path” entry. Click on “Edit” just below that list box and two text boxes will appear. Click within the one marked “Variable value” to deselect the line (It appears selected by default) so that you can append to rather than erase the variable. Get to the end of the line, add a semi-colon and type the location of the bin folder where the Java SDK was installed. Better still, navigate to the location in your windows explorer and copy and paste the location from your address bar. On my computer, its something like “C:\Program Files\Java\jdk1.6.0_01\bin” cos I’m using the 1.6 version of the SDK. For versions 1.4 and below, it may be something like “C:\ jdk***\bin”. Click “OK”s till all windows disappear.

Setting Classpath is similar. The only difference is that there’s usually no variable called classpath (except if you or a program has added one before). The first thing to do is to check for one in the same place you checked for “Path”. If you find one, add the new classpath (a.k.a location of a class referenced in your program) the same way you added a new entry to the path variable. If there is no classpath variable yet, instead of clicking “Edit”, click on “New”. The same set of boxes will pop up and this time they will be empty. In the box marked “Variable name” type CLASSPATH and in the one marked “Variable value”, type the classpath location(s) each separated by a semi-colon.

There’s a way to set classpath at runtime as arguments passed to the Java interpreter in the Java command but I don’t know it yet.

When building certain programs, you might have to set a JAVA_HOME variable as well. Same procedure as classpath. And the location of this should be the installation folder of the SDK (not the bin, but one level above it), in my case, “C:\Program Files\Java\jdk1.6.0_01”.

When using an IDE like Netbeans (and you’ll eventually have to use one), you won’t need all this.

C’est finite, all ye budding Java developers. I started down this road myself some 12…months ago and can’t believe how far I’ve travelled. You can do it too. Don’t give up. I’m open and willing to answer all questions about anything that starts with J.

4 comments:

Lapa said...

TOP PORTUGUESE UNIVERSAL WRITER: CRISTOVAO DE AGUIAR.

He has, also, translated into Portuguese the Wealth of Nations by Adam Smith.

He has been awarded several prizes.

Don't forget the name of this great author, you'll be hearing of him soon.

Thank you for spending time in Universal Culture.

Thanks for visiting.

Anonymous said...

How proficient are you with java?

My lil sis needs some coaching if u dont mind

Can u send me ur email add?

bighead said...

I'm proficient enough...when girls are involved, I can be as proficient as needed. Jokes apart tho' I'm a Sun Certified Java Programmer moreover I work with it everyday so I guess I could give your sister tips. My email addy is available on my profile: thisbighead@gmail.com

Anonymous said...

I remember configuring my first java environment, wow... its been long a road from there