1.1.2 – Configuring JDK on Windows

by subbu on December 2, 2014

In the previous session we have installed JDK. Now our computer is installed with tools to debug, compile and execute java programs under the bin folder of JDK (c:\jdk1.8.0\bin)

java-tools in windows

Need of setting path to bin folder:

Now these tools are only available in the bin folder. So, we can write, compile and execute a java program only under the bin folder.
To access these tools from any where, we need to set the path to the parent folder of these tools that is “c:\jdk1.8.0\bin”. Before setting the path, let us first discourse what actually path is?

path is an announcement to the operating system saying that, if user issues a command then go, search and access related command file from so and so locations as specified in the path.

Say for example if the path is set as “c:\windows\system32;d:\codingfox;c:\jdkk1.8.0\bin;.;” then operating system look up all these locations for related command file when user issues any command. Here observe that locations are separated with semicolons and a dot (;.;) at the end means even look up in the current folder also.

One way, it promotes location transparency that is; files of these folders can be accessed from any where.

Path Vs classpath:

Many times people get confused with path and classpath. Though both are used for the same purpose, proper variable is used according to the file type. Say for example

  • Path variable is used to set path to .exe, .bat files
  • classpath variable is used to set path to .class, .jar and .zip files

As all the java development tools are exe files, we need to set the path to the parent folder of these tools that is to the “c:\jdk1.8.0\bin” folder.

Now we see how path can be set to the c:\jdk1.8.0\bin” folder

Step 1: Right click on MyComputer and select properties

Mycomputer-properties

Step 2: Select Advanced System settings in case of Windows 7/8/8.1 otherwise Properties window opens directly in case of windows XP

Select Environment variables under advanced tab

Environment-variables

Step 3: Select path environment variable under system variables and select edit

path-variable

Step 4: Add the path of java tools (c:\jdk1.8.0\bin) to the existed path value by separating with semicolon. Don’t forget to add ;.; to access the files of current folder.

path-value

Path if you install the java under c:\
xxxxxxxxxxxxxxx;c:\jdk1.8.0\bin;.;
Path if you install the java under c:\Program file\java
xxxxxxxxxxxxxxx;c:\Program Files\java\jdk1.8.0_06\bin;.;

Warning!!!
There would be a system generated path and which is selected in the path value on opening the path dialogue. Never and ever delete the existed path rather only add the new path to the existing one. Some commands and services may not work if you do so.

If you happen to accidentally delete the existed path value in hurry!! Then select cancel and then reenter into path dialogue.

Step 5: Test the configuration by typing “javac” (java compiler) and “java” (java executable) at the command prompt.

javac-cmd

java-cmd

It must show some options if the configuration is correct. There would be an error message as

'javac' is not recognized as an internal or external command,
operable program or batch file.

'java' is not recognized as an internal or external command,
operable program or batch file.

if the configuration is not correct.

In the next session we will see how we can compile and execute a simple java program on windows system.

Previous post:

Next post: