Java programs are compiled and run from an operating system prompt, unless you have installed an IDE that will do this for you directly. If you create an applet, this would run inside a web page in a browser.
After you have installed the JDK, you will need to set at least one environment variable in order to be able to compile and run Java programs.
For more complex projects that pull together elements from different sources, you must set an additional environment variable or two. Note that:
PATHenvironment variable enables the operating system to find the JDK executables when your working directory is not the JDK's binary directory.
CLASSPATHis Java's analog to
PATH, the compiler and JVM use it to locate Java classes.
PATHis then set from
The procedure to permanently set the environment variables varies slightly from one version of Windows to another; the following will work in many, including Windows XP. The process for Vista is similar, but slightly different:
JAVA_HOMEexists, check to see that it matches your most recent JDK (or the one you wish to use).
C:\Progra~1\Java\jdk1.5.0_14(you can check if this works in your system by typing it into the address bar of a My Computer window).
PATH, again select either Add or Edit.
PATH, it will work as a User variable.
JAVA_HOME, then we are already set correctly .
PATH, it will be found first, and therefore supercede any other directory - if you append to path, your directory won't be found if an earlier entry JDK entry exists (the following image shows a prepend).
If you set the variables from a command prompt, they will only hold for that session, but you could create a batch file that you could run each time you open a command prompt window.
To set the
PATH from a command prompt or batch file:
If you need to set the
CLASSPATH; this is no longer necessary .
%CLASSPATH%, and that the path element separator is a colon instead of a semicolon.