Skip To Content

Athabasca University

Getting Started with Java

  1. The first thing you will need to do, before you get started on your course, is to download your Java compiler. For most courses, you'll need the full Java Standard Edition Java Development Kit (JDK). This download also includes the JRE:
    • These instructions are now for the latest Java installation - JDK 6..
    • Java SE (Standard Edition) Downloads - Go to 'Java SE Development Kit (JDK)' box and select the 'Download' button. (This is supported for Windows 2000, XP, and Vista, as well as Linux and Solaris operating systems. For Macs, see Step 7 below.)
  2. Once you have downloaded the JDK into a folder on your harddrive, go to that folder and double click on the file named (for example) jdk-6u13-windows-i586-p.exe to install it (version number may vary). Note: This is assuming you are installing this file on a Windows machine. Double clicking on the file will start the JDK Installer, then follow the instructions the installer provides.
  3. The installer will create a new directory named (for example) C:\Program Files\Java\jdk1.6.0_13. Inside this new folder are a group of folders and files. You will need to set the path to this so that your computer can find the right programs required to compile and run your java programs. Setting Your Path for the JDK
  4. The JDK does not provide an editor or any program icons to run them with. You have several options for creating, compiling, and running your Java programs:
  5. Java Sun Tutorial for compiling first Java program in DOS
  6. Java Sun Common Java Compiler Errors and Solutions
  7. If you encounter problems downloading or installing the JDK, contact the Virtual Helpdesk.
  8. Tips for Compiling and Running Programs
  9. Java for Mac OS X
  10. Your First Cup of Java (for Windows, Linux, and Mac OS)

Java Path

Choose the operating system you use:
  1. Click Start, Control Panel, and then double click on the System icon.
  2. Click the Advanced Tab at the top of the Window, and then click Environment Variables.
  3. In the System Variables box, find the PATH statement, click once to highlight it and choose it, then click the "Edit" button.
  4. Add your SDK path to the end of the existing path statement preceded by a semi-colon as shown below: C:\Program Files\Java\jdk<version>\BIN Where <version number> is replaced by the current numerical version number.
  5. Click OK, click OK and click Ok again. Reboot your computer.

Windows 7
  1. Click "Windows Explorer" or right Click the "Start or Windows icon" and then select "Explore"
  2. Right click on the "Computer" located above the "C:"
  3. Click Change Settings, then select to Continue on the warning screen
  4. Click the Advanced Tab, then select Enviroment Variables
  5. Scoll down to the Path Variable
  6. Click Edit and modify as for Windows XP, then restart your computer.

Windows Vista
  1. Click the Windows icon for the Start Menu, then click Control Panel
  2. Click System Maintenance, then select System
  3. Click Change Settings, then select to Continue on the warning screen
  4. Click the Advanced Tab, then select Enviroment Variables
  5. Scoll down to the Path Variable
  6. Click Edit and modify as for Windows XP, then restart your computer.

Running the JDK from the Command Prompt

  1. To compile a java progam, save it in a file in your working directory. For example if the program is Program1 (with the main class within the program named Program1), save it as If using Notepad as your editor ensure that the java file you created does not have the "txt" extension added to the end of the file, otherwise, it will not compile. Then go to a DOS prompt and compile the program with
  2. To run the program, after compilation type
    java Program1
    at the DOS prompt.
  3. To run an applet, which has to be viewed using an HTML document (ie. applet.htm), type
    appletviewer applet.htm
    at the DOS prompt.
  4. To run DOS as a window Instead of as full screen, select the DOS icon (look under C:\WINDOWS\Start Menu\Programs) and click on the right mouse button. Select Properties. Select Screen. Change from Full-screen to Window.
  5. Java Sun Tutorial for compiling first Java program in DOS
  6. Java Sun Common Java Compiler Errors and Solutions

Running the JDK using the Programmer's File Editor

This program provides a few basic options to help you develop your java programs using the JDK. (You must first have Java SDK). One of its biggest advantages is that it is completely free.

  1. If you haven't already done so, download the Programmer's File Editor. Unzip it to the folder of your choice.
  2. Click on the Pfe32 icon in that folder, to open up the program. It would be a good idea to create a shortcut to that file.
  3. This program runs much like any other windows editor. Go to "file", then "new" or "open" to open a file. You have editing options available similar to notepad or wordpad. All files are saved in text format. You have to choose the file extension name you wish to save it as (ie - .java or .htm).
  4. To compile or run your program, go to "Execute", select the "Dos Prompt", and proceed in the same way you would with Running the Java SDK using MS-Dos. Program and error output appear in the MS-Dos window.

Running the JDK using JCreator

This program provides many options to help you develop your java programs using the JDK. (You must first have Java SDK installed). JCreator is freeware.

  1. If you haven't already done so, go to The JCreator Home Page and download the latest version of JCreator. Click on this file to extract and install it. This will create an icon in your start-up menu and on your desktop.
  2. When you first open the program, you will be prompted to enter in path to your JDK directory and the JDK documentation directory. You can browse for these directories. You will need to install the JDK Documentation files separately (from the JDK site), if you wish to have the help files in place.
  3. JCreator opens up in 3 sections and includes a FileView, Class View and an Output View. The main section is the edit window. Open your program files in the same way as in any windows editor - "File" then "New" or "Open". The edit window color codes the source code - green for comments, blue for reserved words, etc..
  4. The Class browser windows enables you to navigate through the Java classes of your application. It displays the project items of the project workspace and its classes as an expandable file tree.
  5. The Output View displays the output messages of the tools and the search engine.
  6. To compile a file, from the Menu at the top, click on Build, Compile File. This will start the java compiler and will compile the active file. If you want to Execute the file, from the menu at the top, click on Build, Execute File. This will execute the active file.
  7. At the bottom of the screen, you have an Build/Output windows. Within the windows there are some tabs. A Build tab and an Output tab. When you compile a file, messages will appear here in the Build tab. When you run the file, clicking on the Output tab will display the program's output.
  8. JCreator has a comprehensive help system included within the program, which you can access by clicking Help from the bar at the top.


This is a system variable that defines the root for the source of classes. It operates like a path variable. For example, when you set: CLASSPATH=.;E:\JDK-version\BIN\..\CLASSES; You are telling the compiler where to find the root directory of built-in class libraries. The starting '.' is necessary to instruct the machine to use the current directory as a CLASSPATH, as well. Normally the CLASSPATH does not need to be set, unless another program has set one and then you need to be sure that it has included the current path as above. Note that setting the CLASSPATH is different from setting the PATH, (for example PATH=E:\JDK1.2.2\BIN\) which is the path to the binaries java and javac.


A package is a library of classes all in the same subdirectory. You can also put source files and anything else in that subdirectory and compact the whole thing into a .zip or .jar file. When you, as a programmer, want to build a library you include a package statement in the program before the first source line e.g. package comp308.program1 if the root of your classpath goes to ..myprograms\ then the compiler will put the class files in myprograms\comp308\program1. You will need to do this for all the source files that make up the package. When you compile your program with javac the compiler will expect to find all the source files and will put all the class files in myprograms\comp308\program1. When you run your program with java you must indicate the package as well as the class. The interpreter will look for the class files by following the classpath to its root and then adding the package pathing. For example, in the situation above, if your main() is in Class1, to run Class1.class type: java comp308.program1.Class1

Computer Programming in Java

  1. Make sure that you edit the Java source code of every class you design in a SEPARATE FILE, and that the name of that file has the ".java" extension.
  2. Make sure that name of every Java source code file (not counting the ".java" extension) MATCHES EXACTLY the name of the class defined in that file.
    • for example if the class name of the first Java source code that you need to compile is called Program1. You will need to save this file as Ensure that you preserve the capital letter, as the Java compiler is case-sensitive.

Updated October 15 2015 by FST Technical Staff

AU, CANADA'S OPEN UNIVERSITY, is an internationally recognized leader in online and distance learning.