Java: How to Get Started

In this tutorial, you will learn how to install a Java Virtual Machine (JVM) on a typical Windows based PC.

This is a summary of what will be covered:
(1) Downloading a JVM.
(2) Installing a JVM.
(3) Configuring environment variables.
(4) Verifying installation and configuration.
(5) Troubleshooting.

(1) Download:
Go to java.sun.com
Follow the Downloads link, and click the Download button for "JDK 6".
Nevermind all the other downloads- we just want "JDK 6".

Under the "Windows Platform - Java(TM) SE Development Kit 6" section, click the "Windows Offline Installation, Multi-language" link- it's about 50MB, so hopefully you have a high speed internet connection.

(2) Installation:
Run the installer and take all default options if possible.
The Java Development Kit should have been installed at:
C:\Program Files\Java\jdk1.6.0 - or in another location you specified.
Let this directory location be known as X for future reference.

(3) Configuration:
To make commandline tools visible and provide flexibility for easily switching to a different JVM in the future, we'll create an environment variable. Right click on My Computer, choose Properties, Advanced tab, Environment Variables button.

Under "System variables", not "User variables for username", create a new environment variable named JAVA_HOME with value X, where X is the installation directory of the JDK from the Installation step.

Example:

Next, we need to append %JAVA_HOME%\bin to the Path environment variable. Again, under "System variables", find Path and choose Edit. Move to the far right of the text box, add a semicolon (;) followed by %JAVA_HOME%\bin. Note: semicolons separate environment variables in Windows. Click OK to apply the settings.

Example:

(4) Verification:
Start a DOS prompt. One way to do this is: Click the Start button on the desktop, choose Run... and specify cmd, click OK.

Test 1: At the command prompt, type java -version and hit enter.
You should see something similar, if not exact, to:

If you see an older or unexpected version, then you have multiple JVMs installed. Go to the Troubleshooting section for ideas.

Test 2: At the command prompt, type javac -foo and hit enter.
You should see something similar, if not exact, to:

If you see: 'javac' is not recognized as an internal or external command, operable program or batch file, then you have made a mistake when setting up either JAVA_HOME or modifying the Path environment variables- please double check.

(5) Troubleshooting:
Seeing older or unexpected JVM version:
Simple solution is to move the JAVA_HOME\bin earlier in the list of Path environment variable values- in the extreme case, prepend it to the Path. Because some applications install JVMs, they may depend on them for proper execution, so it is not advisable to delete any other JVMs or JVM Path entries unless you are certain you understand the consequences.

Not seeing environment variable changes:
DOS command prompt shells do not pickup changes to environment variables once they've been opened. Try closing your DOS command prompt window and creating a new one.

How to see environment variable values:
In a DOS command prompt window, type echo %JAVA_HOME% and hit enter.

Example:

The same can be done with Path by typing echo %Path%
Alternatively, because Path is special, you can just type Path and hit enter.
(Not case sensitive- remember, this is Windows)

To see ALL environment variables, type set and hit enter.
Tip, do this sequence to make it easier to view environment variables:
set > env.txt
notepad env.txt

Next Steps:
Java: Hello World