Installing and Using Java Compiler on Windows XP and Windows 7
January 23, 2013
0. Some Security Measures Before Installing Your Java Compiler
The U.S. Department of Homeland Security is urging computer users to
disable Java software on their computers. An exploit for an unpatched
vulnerability in Java is being used by cybercriminals to infect
computers with malware. I advise you to disable java applications
from running from your web browsers as follows. Running a Java
compiler offline as we will for the course is okay though.
- Go Start and Control Panel. Look for the Java icon.
(If your computer does not show the Java icon, do this:
select View by: Small Icons for Windows 7;
select “switch to classic view” for XP.)
If you still don't see Java at this point, it is likely that
Java has not been installed on your machine. Well, you will
be installing it below, so come back and do this again after
you install it.
- Click on the Java icon (it may take 5 seconds or so to
open)
- Click on the Security tab at the top.
- If you are running the latest version of Java, there will be a
check box at the top for “Enable Java Content in the
browser”. Uncheck that box.
- Then click OK and OK and you are done. Do not
bother clicking on the View button as even if the enabled button
is checked, it is disabled Java wide.
- If you are not running the latest version, there will not be a
checkbox (only a button for “certificates” which is not what we
want). So, click on the Java tab instead of the
Security tab. Click on “View”. In the box that
opens, on the far right column, uncheck the box
for “Enable” . If there are multiple lines (for both
Java 5 and 6 or 6 and 7) uncheck the box for “Enable”
on all lines. Click OK and OK to
exit.
- Important: Do this once more after you
install Java below. When you checked this the first time, Java
was probably not installed and you did not have to do anything.
Well, now you will have Java installed and will have to disable
it from your web browser.
1. Installing Java Compiler on a Windows XP Machine
If you are not familiar with some of the DOS commands, try the
DOS Lab before you try this.
Note: If you are using a Windows 7 (as opposed to
a Windows XP) machine, go to Section 2 below.
Warning: Once you make a mistake during your installation, it
is really hard to figure out where you made the mistake. So, follow
the instructions carefully.
Follow these steps:
- Go to the
Java SE Downloads page. We are installing 'Java SE
7u11'. (You may want to open another copy of this page on a
different tab if you don't want to go back and forth.)
- Click on JDK Download (not JRE Download)
for 'Java SE 7u11'.
- First, Accept License Agreement. Then, for Windows you
will see two choices: Windows x86 and Windows
x64. Download the .exe file for 'Windows x86'
or 'Windows x64' depending on whether your machine is a
32-bit machine or 64-bit machine respectively. If you don't
know whether you have a 32-bit machine or 64-bit machine, try
Start -> Control Panel -> System (note that '->' means 'followed
by') and check the System type.
- Download 'jdk-7u11-windows-i586.exe'
or 'jdk-7u11-windows-x64.exe' into a folder somewhere
on your computer. By default, it will probably download it on
to your desktop or Downloads folder. (I personally like to keep
all the downloaded stuff in one area. So, I have created a folder
named downloads in my own area on the C: drive.
So, I actually saved it in the C:\downloads folder on mine.
This way, I will have a record of all the software I have
downloaded and installed on my computer. It is my habit!
If it has already saved to the desktop or some other folder, you
can move it to one such folder using the cut and paste
operations in a Windows Explorer window. When I say Windows
Explorer, I don't mean Internet Explorer. Windows Explorer is
the tool that shows file folders and files on your file system
in a hierarchical fashion.)
At this point go back to the previous page where you clicked
on JDK Download for 'Java SE 7u11'. Click
on Installation Instructions under JDK 7 Docs. We
will develop Java programs. Click on JDK Installation
for Microsoft Windows under Microsoft Windows.
- Go to the Running the JDK Installer section. As you
follow the instructions, use this extra information that
I am adding here. (Some parts of the instructions on the SUN
website may not apply to your situation. So, what I wrote here
may be enough for you - it was enough on my Windows XP machine.)
- Check the download size (90.4 MB in my
case) (Use the "Details" option under the
"View" menu in a Windows Explorer window or check
the "properties" of the downloaded file again using
Windows Explorer.). Depending on the machine you use, it may
actually show a slightly different number, which is ok.
- Optionally uninstall Java if one has already been
installed. Even if you have not installed one yourself
personally, there may be a version of JRE (Java Runtime
Environment) installed. Uninstall it using the 'Add
or Remove Programs' by following 'Start -> My
Computer -> Control Panel'. When you install
a JDK, JRE is included in it.
- Run the JDK installer that you downloaded earlier by
clicking on it from a Windows Explorer window.
- You will be clicking on the Next button most of
the time. If you are not sure, just take the default
option that is being offered to you.
- Accept 'Development Tools' which will be your
default selection. This will include JRE as
well.
- For the destination folder ("Install to:"), just
accept the one they suggest. It will install JRE
first followed by JavaFX 2.0 SDK.
- It will ask you to register Java. Go ahead and do it
if you wish (I did).
- You have just installed a version of both JDK
and JRE now. Try Add or Remove Programs by
following Start -> My Computer -> Control
Panel again to see if 'Java 7 Update 11' is
in the list of programs installed there. Also check the
folder: 'C:\Program Files\Java' using Windows
Explorer. There you will see two subfolders
(subdirectories) named 'jdk1.7.0_11' and
'jre7'. This is where the installations
reside in your file system.
- Update the PATH variable even if it says
it is optional. This is how you do it on a Windows XP
machine:
- Follow Start -> Control Panel
-> System (double click on System).
- Select the Advanced tab.
- Select the Environment
Variables button.
- You will see two sections: 'User variables for YourName'
and 'System variables'. If you add it to the User
variables section, the PATH variable will be in effect only
when you are logged on. If you add it to the 'System
variables' section, it will be in effect as long as someone
is logged on. If you are not sharing the machine with
anyone else who writes Java programs, you may add it to
either section. (I added it to the 'User variables for alee'
section.)
Capitalization of the name does not matter. That is, PATH
is considered the same as path or Path.
If a PATH variable does not already exist (most
likely it is already there), then add a new variable
named PATH, with the
value
C:\Program Files\Java\jdk1.7.0_11\bin;.
You do it by using the New
button. OK to complete.
If PATH already exists,
select it and use the Edit
button to append the Java path value to the end of
whatever is already there. Multiple values are separated
by a semicolon (;). The
value that you want to add is most likely C:\Program Files\Java\jdk1.7.0_11\bin;
if you are installing "JDK 7 Update 2". This is the
location where the Java compiler was installed in your
file system. OK to complete.
- If you already have a DOS Command window open, close it
and open a new one to make the PATH variable
effective in that window.
- Start using the JDK. Go to section 3 now.
2. Installing Java Compiler on a Windows 7 Machine
If you are not familiar with some of the DOS commands, try the
DOS Lab before you try this.
Note: If you are using a Windows XP (as opposed to
a Windows 7) machine, go to Section 1 above.
Warning: Once you make a mistake during your installation, it
is really hard to figure out where you made the mistake. So, follow
the instructions carefully.
Follow these steps:
- Go to the
Java SE Downloads page. We are installing 'Java SE
7u11'. (You may want to open another copy of this page on a
different tab if you don't want to go back and forth.)
- Click on JDK Download (not JRE Download)
for 'Java SE 7u11'.
- First, Accept License Agreement. Then, for Windows you
will see two choices: Windows x86 and Windows
x64. Download the .exe file for 'Windows x86'
or 'Windows x64' depending on whether your machine is a
32-bit machine or 64-bit machine respectively. If you don't
know whether you have a 32-bit machine or 64-bit machine, try
Start -> Control Panel -> System and
Security -> System (note that '->' means 'followed
by') and check the System type.
- Download 'jdk-7u11-windows-i586.exe'
or 'jdk-7u11-windows-x64.exe' into a folder somewhere
on your computer. By default, it will probably download it on
to your desktop or Downloads folder. (I personally like to keep
all the downloaded stuff in one area. So, I have created a folder
named downloads in my own area on the C: drive.
So, I actually saved it in the C:\downloads folder on mine.
This way, I will have a record of all the software I have
downloaded and installed on my computer. It is my habit!
If it has already saved to the desktop or some other folder, you
can move it to one such folder using the cut and paste
operations in a Windows Explorer window. When I say Windows
Explorer, I don't mean Internet Explorer. Windows Explorer is
the tool that shows file folders and files on your file system
in a hierarchical fashion.)
At this point go back to the previous page where you clicked
on JDK Download for 'Java SE 7u11'. Click
on Installation Instructions under JDK 7 Docs. We
will develop Java programs. Click on JDK Installation
for Microsoft Windows under Microsoft Windows.
- Go to the Running the JDK Installer section. As you
follow the instructions, use this extra information that
I am adding here. (Some parts of the instructions on the SUN
website may not apply to your situation. So, what I wrote here
may be enough for you - it was enough on my Windows 7 machine.)
- Check the download size (90.4 MB in my
case) (Use a Windows Explorer window and check the
"properties" of the downloaded file.). Depending
on the machine you use, it may actually show a slightly
different number, which is ok.
- Optionally uninstall Java if one has already been
installed. Even if you have not installed one yourself
personally, there may be a version of JRE (Java Runtime
Environment) installed. Uninstall it using
the Programs and Features by following 'Start ->
Control Panel'. When you install
a JDK, JRE is included in it.
- Run the JDK installer that you downloaded earlier by
clicking on it from a Windows Explorer window.
- You will be clicking on the Next button most of
the time. If you are not sure, just take the default
option that is being offered to you.
- Accept 'Development Tools' which will be your
default selection. This will include JRE as
well.
- For the destination folder ("Install to:" or some such
thing), just accept the one they suggest.
- It will ask you to register Java. Go ahead and do it
if you wish.
- You have just installed a version of both JDK
and JRE now. Try Programs and Features
again to see if 'Java 7 Update 11' is
in the list of programs installed there. Also check the
folder: 'C:\Program Files\Java' using Windows
Explorer. There you will see two subfolders
(subdirectories) named 'jdk1.7.0_11' and
'jre7'. This is where the installations
reside in your file system.
- Update the PATH variable even if it says
it is optional. This is how you do it on a Windows 7
machine:
- Follow Start -> Control Panel
-> System and Security -> System (double
click on System).
- Click on Advanced system settings in the left pane.
- Select the Advanced tab.
- Select the Environment
Variables button.
- You will see two sections: 'User variables for YourName'
and 'System variables'. If you add it to the User
variables section, the PATH variable will be in effect only
when you are logged on. If you add it to the 'System
variables' section, it will be in effect as long as someone
is logged on. If you are not sharing the machine with
anyone else who writes Java programs, you may add it to
either section. (I added it to the 'User variables for alee'
section.)
Capitalization of the name does not matter. That is, PATH
is considered the same as path or Path.
If a PATH variable does not already exist (most
likely it is already there), then add a new variable
named PATH, with the
value
C:\Program Files\Java\jdk1.7.0_11\bin;.
You do it by using the New
button. OK to complete.
If PATH already exists,
select it and use the Edit
button to append the Java path value to the end of
whatever is already there. Multiple values are separated
by a semicolon (;). The
value that you want to add is most likely C:\Program Files\Java\jdk1.7.0_11\bin;
if you are installing "JDK 7 Update 11". This is the
location where the Java compiler was installed in your
file system. OK to complete.
- If you already have a DOS Command window open, close it
and open a new one to make the PATH variable
effective in that window.
- Start using the JDK. See the next section.
3. Verifying Your Java Installation
Compile and run a simple Java program to verify your
installation.
- To verify your Java installation, download Simple.java into a
folder (directory), any folder.
- Open a DOS Command window (enter 'cmd' into the input pane after
clicking on Start) and use the 'cd' command to go to the
directory where Simple.java is located.
- Issue the following command to the DOS prompt to compile the
source file:
"C:\Program Files\Java\jdk1.7.0_11\bin\javac" Simple.java
This will create a new file named Simple.class in the same
directory where Simple.Java is located. That is a lot of
typing if you are compiling a lot. If you set the PATH
variable correctly, you should be able to issue the following
command to achieve the same effect:
javac Simple.java
The value associated with the PATH variable tells the
operating system (the DOS operating system in our case) to look in
those places (all the folders included as the Value of the
PATH variable) for the definition of the command that you
are issuing (javac in this case).
- Issue the following command to run the program:
"C:\Program Files\Java\jdk1.7.0_02\bin\java" Simple
Or, the following if you set the PATH variable correctly:
java Simple
This will produce the output that you expected if your installation
was done correctly.
Even if the PATH variable is set correctly, there is a
slight chance that the 'java' command may not work even if
the 'javac' command worked. If that happens, it is most
likely that the CLASSPATH variable is already being used
by some other program already installed on your computer. The value
associated with the CLASSPATH variable tells the operating
system (e.g., DOS) to look in those places (all the folders
included as the Value part of the CLASSPATH
variable) for the .class file that you are trying to run
with the 'java' command. That is, PATH tells DOS
where to find the definitions of the commands ('javac' and 'java'),
whereas CLASSPATH tells DOS where to find a
.class file to run.
If your 'java' command does not work, check to see if
CLASSPATH (uppercase or lowercase letters or some mix of
uppercase and lowercase letters) is defined in the Environment
Variables section by following Start ->
Control Panel -> System -> Advanced as before. If
defined, check the value of CLASSPATH. (One student
reported to me that the value his had was C:\Program
Files\QuickTime\QTSystem\QTJava.zip.) The value
of CLASSPATH should start
with '.;' (that is a dot followed by
a semicolon without the single quotes) if it is already defined.
If '.;' is not included, add
it to the beginning of that value by using the Edit
button (We are not replacing it but adding it). OK to complete.
Close your DOS window and open a new one and try 'java Simple'
again. If this does not fix your problem, you made a mistake
somewhere else.
4. Installing Java SE 7 Documentation on your Windows machine
If you work on your computer offline a lot, you may want to have a
copy of the Java documentation installed locally on your computer. If
so, follow these instructions to install a copy.
- Go to the Java SE
Downloads page.
- Scroll down to Java SE 7 Documentation and download and
install it.
- Unzip the downloaded file into a folder. In my case, I unzipped it
under "C:\Program Files\Java\". It will create a folder
named "docs" under that directory. If you view
"C:\Program Files\Java\docs\api\index.html" by dragging it
to your web browser, you will see the home of the documentation site.
5. Some Security Measures After Installing Your Java Compiler
Now that a JRE is installed, go back to Section 0 and disable Java
for your web browser.
That's it!