Hello, World in Java 1.6 on Windows


This document instructs you on how to setup a Java programming environment for your Windows 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. These instructions are specialized to Windows 7, but are similar for Windows XP and Windows Vista.

Java

You will use Sun's implementation of the Java Platform, Standard Edition Development Kit (JDK 6). Download the JDK 6 Update 16 to the Desktop:

Once it is downloaded, install it by double clicking the file jdk-6u16-windows-i586.exe. We recommend all of the default options.

DrJava

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:

Launch DrJava and make the following customizations.

Create the program

Now you are ready to write your first Java program.

Compile the program

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.

Execute the program

Now it is time to run your program. This is the fun part.

Congratulations, you are now a Java programmer!

FAQ

Can I use Java 1.5 instead of 1.6? Yes. Here's a link to download JDK 5, Update 20.

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 have a 2008 Princeton SCI Windows laptop and DrJava complains that it can't save or retrieve my settings. What's wrong? OIT misconfigured the Java user home directory - it is C:\Users\User instead of C:\Users\[username]. As a quick and dirty workaround, update the permissions for C:\Users\User:

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, select Start -> My Computer -> 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 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.