You need to set environment variables. Run sysdm.cpl from the startup dialog box to open advanced system properties.

In the environment variables, add a new one, as in this dialog box.

Name : JAVA_HOME VALUE: C:\Program Files\Java\jdk1.7.0_21\
Now edit the value of the PATH variable and add ;%JAVA_HOME%\bin\; at the end of this value.

Now reboot your system and you can run Java related commands from the command line.
source share