This document instructs you on how to setup a Java programming
environment for your Windows XP computer and provides a step-by-step
guide for creating, compiling, and executing a Java program.
All of the software is freely available on the Web.
| Java |
You will use Sun's implementation of Java 2 Standard Edition (J2SE) 5.0. Download the Java 2 Platform Standard Edition 5.0 to the Desktop:
Once it is downloaded, install it by double clicking the file jdk-1_5_0_14-windows-i586-p.exe. We recommend all of the default options.
|
|
You will develop your Java programs in an application called DrJava. DrJava features many specialized programming tools including syntax highlighting, bracket matching, auto indenting, indent shifting, and line numbering. To install DrJava:
|
|
Now you are ready to write your first Java program.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
|
|
It is now time to convert your Java program into a form more amenable for execution on a computer. To do this, click the Compile button.
If all goes well, you should see the following message in the Compiler Output window at the bottom:
Compilation completed.
If DrJava complains in some way, you mistyped something, and you should check your program carefully. Use the error messages in the Compiler Output window to guide your search.
|
|
Now it is time to run your program. This is the fun part.
If all goes well, you should see the following message:java HelloWorld
Welcome to DrJava. Working directory is C:\introcs\hello > java HelloWorld Hello, World
| FAQ |
I have a different flavor of Windows. Will these instructions work? Yes, the instructions should work on other versions of Windows.
I receive a Windows Security Alert when I run DrJava. Should I keep blocking Java 2 Platform Standard Edition binary? No. Click the Unblock button to eliminate future warnings.
I receive a prompt for the tools.jar file. How should I proceed? The file tools.jar is part of the Java JDK 5.0 that you installed. DrJava can usually find it on its own, but if it can't, it will prompt you to enter it manually. It should be something like the following:
C:\Program Files\Java\jdk1.5.0_14\lib
How can I associate .java files with DrJava? Follow these instructions.
How do I break out of an infinite loop in DrJava? Click the Reset button in the menubar or select the menu option Tools -> Reset Interactions.
How can I convince Windows to reveal the .java or .class file extensions? Many Windows machines are configured to hide the file extensions. To override this default, open My Computer, select Tools -> Folder Options -> View, uncheck the box next to Hide file extensions for known file types, and click OK.
Why does DrJava create a file named HelloWorld.java~? By default, DrJava saves a backup file by appending a ~ to the end of the filename. You can turn off this features via Preferences -> Miscellaneous -> Keep emacs-style Backup Files.
How do I compile and execute from the MS-DOS command-line? You won't need to do this until Section 1.5, but if you want to get a head start follow these instructions for using the command-line in Windows.