Installing JDK and DrJava

From CompSciWiki
Revision as of 19:37, 14 November 2009 by Tandres (Talk | contribs)

Jump to: navigation, search

COMP 1010 Home > Getting Started


Introduction

To start programming in Java, you will need to install the Java Development Kit (JDK) first.You will also need to install a development environment where you can write and run your Java programs. The development environment you need to install depends on the operating system your computer runs on. This section is subdivided to guide you through installing the right software for your computer.

   

{{{Body}}}

Installing your software

Installing JDK

The JDK is a free piece of software that contains a minimal set of tools that you need to develop Java programs.

If you are a Mac user, you do not need to download the JDK. Mac OS X comes with a fully configured and ready-to-use Java runtime and development environment. Mac OS X includes a full version of J2SE 1.5, pre-installed with the Java Development Kit (JDK) so you don't have to download, install, or configure anything.

If you are still using the older version of Mac OS X 10.4 (Tiger) you may want to manually update the older JDK version to the newest release by downloading Java for Mac OS X 10.4.

For Windows users, the JDK is the first thing you need to install before creating and running Java programs on your home computer. The JDK allows your computer to create and run Java programs.

Below is the link to download JDK and installation instructions. There are several downloads available at this link. You need the Java SE Development Kit. You do not need any of the bundles.

Installing a development environment

After installing JDK you are now ready to install a development environment. A development environment is where you do the actual writing and running of your programs.

For Mac users

The development environment you need to install is DrJava development environment.

Below is the link to download JDK and installation instructions.

For a guide on using DrJava, simply click on the "Documentation" or "QuickStart Guide" link on the lefthand side pane on http://drjava.org/

For Windows users

Most students install the textpad development environment, as that is the environment used in class by most instructors. Note that Textpad is shareware, and you are expected to purchase a copy if you intend to keep on using it. You may instead download the Windows version of the free DrJava package as described above for Mac users.

IMPORTANT: Install the JDK first! If you install it after you have already installed Textpad, you will need to manually set up Textpad to compile and run Java programs.

Below are the links to download textpad and installation instructions.

Helpful Textpad Options

Introduction

Textpad is a very basic text editor for Windows. It is much like Notepad but with a few more bells and whistles.

Main Environment

Menu Bar

The menu bar is located at the top of the window. It contains the following menu items: File, Edit, Search, View, Tools, Macros, Configure, Window and Help. To see a description of each menu item, move your mouse over the item name and look at the bottom-left of the Textpad window for a description. Try fiddling around with them and get a good understanding of what they all do.

Toolbar

The toolbar is located directly under the menu bar and contains buttons for commonly used tools. To customize which buttons appear:

  1. Right click on the tool bar
  2. Select Customize
  3. Click on the "Commands" tab
  4. Select the category desired
  5. Click and drag the icon to the desired location on the toolbar

Document Chooser

The document chooser displays all of the files that are currently open. To change which file you are looking at in the editing area simply click on the file's name. To close a file, right click on the file name and select "Close document(s)".

Clip Library

The clip library (located under the document chooser) is used as an easy way to insert strings of text into the document. Simply double click on the string of text desired and it will be inserted wherever the text cursor is located. To change the current clip library that is being displayed, pick the one you want from the dropdown menu which is located at the top of the clip library window. You can download and add more clip library at: http://www.textpad.com/add-ons/cliplibs.html

Editing Area

The editing area is where all the text is entered. To view line numbers, click on the "View" menu item and select "Line numbers".

Additional Helpful tips

Changing the Font for Java Documents

  1. Select the menu-item "Configure, and then select "Preferences".
  2. Click on the plus sign (+) beside "Document Classes".
  3. Click on the plus sign (+) beside "Java".

Now you can change how Textpad displays files that end with .java

Handy Keyboard Shortcuts

Textpad has many helpful keyboard shortcuts. Here is a brief list of the most helpful commands:

Ctrl+M
Find the matching {} or ().
F5
Search
Ctrl+F2
Set/delete a bookmark on the current line (makes it easier to find later).
F2
Go to next bookmark.
Ctrl+1
Compile Java program.
Ctrl+2
Run Java Program (You must compile before running).

Where to Find More Keyboard Shortcuts

  1. Select Help Topics from the Help menu.
  2. Click on the plus sign (+) that appears beside Referencing Information
  3. Select "The Keyboard"

This will list all of the keyboard shortcuts.

Common Problems

TextPad Does Not Have the Options to Compile and Run, or These Options are Present But do Not Work

First, make sure that you have installed the JDK. If it is not installed when you install TextPad, TextPad will not be able to set up the compile and run commands. Then you have two options: 1) Re-install TextPad or 2) Add JDK commands using the menu. There is also a third option involving changes to Windows configuration that you may find on the internet, but this option varies somewhat depending on your version of Windows, so we will address only these two choices here.

OPTION 1: Reinstall TextPad

Uninstall Textpad, and install it again. To uninstall Textpad:

  1. Click on the Start button at the bottom left corner of the screen.
  2. Click Control Panel
  3. Double click on Add or Remove Programs (the name is slightly different in some versions of Windows)
  4. Scroll down the list until you find Textpad
  5. Click on the Change/Remove button
  6. Follow the prompts to uninstall Textpad

OPTION 2: Add JDK commands using the TextPad menu

In TextPad, follow these steps if the compile and run options do not appear (see below if they appear but do not work):

  1. Click on Configure, then choose Preferences
  2. Select Tools (from Preferences dialog box)
  3. Click Add
  4. If "JDK Commands" appears on the drop down menu, select it and click Apply or OK. (See picture below.)

Javacommands.jpg

If "JDK Commands" did not appear on the drop down menu, or you already have command and run options, but they do not work, then you can install working compile and run commands from scratch:

  1. Click on Configure, then choose Preferences
  2. Select Tools (from Preferences dialog box)
  3. Click Add
  4. Choose Program... and then use the file selection window that opens up to find the javac command. It will be in C:\Program Files\Java\jdk...\bin (where the ... means some version number). Click on javac and then click on Open. A new tool called Javac should appear in the list of tools. Click on Apply to make it permanent. Javac is your new compiler tool.
  5. Create a run tool in the same way, but this time select the file java instead of javac. The new run tool will be called Java. Make sure you click on Apply.
  6. Then click on the + beside Tools in the Preferences dialog box to show Javac and Java below it. Select each one in turn and make sure the rest of the settings are correct.
  7. Javac: Parameters should be $File and Initial Folder should be $FileDir. You may want to click on "Capture Output" and/or "Sound alert when completed" as well.
  8. Java: Parameters should be $BaseName and Initial Folder should be $FileDir. You may want to click on "Capture Output" and/or "Sound alert when completed" as well. It should look something like the following:

JavaTool.png

I Get A Popup When I Try To Save

If you get a popup that asks if you would like to register or continue evaluation, simply click on "Continue Evaluation". The trial period of Textpad will never run out.

Sample Code Does Not Compile

If your instructor has given you a code example which does not compile on your machine, you may have a different version of the JDK than they do. Please contact your instructor for instructions on getting the code to compile.

My java program compiles fine, but I get a "NoClassDefFound" error when I try to run it

Windows machines have what is called a "classpath" environment variable. When you try to run a Java program from your development environment (like TextPad), the classpath variable tells your system what directories / folders to look in for files (or classes) to run.

Usually, the classpath environment variable is set so that one of the places that will be searched is your "working folder / directory". Your working folder / directory is where you are saving all your files containing Java code.

Some software (Adobe products like Photoshop often seem to be the culprit) modify this environment variable so the working directory / folder is never actually checked for the classes you are trying to run. The end result is that when you try to run your program, you get a "NoClassDefFound" error.

This is an annoying problem. Fortunately, it is usually easy to fix.

The solution? Add a ";." (that's a semi-colon followed by a period) to the end of your classpath environment variable. The ";" separates the "." from the other directories / folders, and the "." specifies to look in the working directory.)

If you have the NoClassDefFoundError, take a look at your classpath environment variable (if you don't have one, then you likely don't have the problem described here) and see if that period is there. If not, follow the steps for the appropriate version of Windows.

Note: Be careful; making a mistake with your system variables can disable your entire machine.

Changing your classpath in Windows Vista:

  1. Click on START (lower left)
  2. Click on "Control Panel".
  3. Select "Classic View".
  4. Double-click on the "System" icon.
  5. Click on the "Advanced system settings" link.
  6. User Account Control may ask you for permission to continue. Select "Continue".
  7. Click on the "Environment Variables" button (near bottom).
  8. Highlight CLASSPATH and click the "edit" button.
  9. Add a semi-colon and a period (";.") to the END of the existing CLASSPATH. Alternatively, you can add a ".;" to the BEGINNING of the existing CLASSPATH.
  10. Exit the control panel. If the class problem persists, restart your computer.


Changing your classpath in Windows NT, 2000 and XP

  1. Click on START (lower left).
  2. Click on "Control Panel" (You may find the Control Panel directly off the start menu, or you might have to click on "Settings")
  3. Double-click on the "System" icon.
  4. Click on the "Advanced" tab.
  5. Click on the "Environment Variables" button (near bottom).
  6. Highlight "CLASSPATH and click the "edit" button.
  7. Add a semi-colon and a period (";.") to the END of the existing CLASSPATH. Alternatively, you can add a ".;" to the BEGINNING of the existing CLASSPATH.
  8. Exit the control panel. If the class problem persists, restart your computer.


Windows 98

  1. Click on START.
  2. Select RUN.
  3. Type in sysedit, then click OK.
  4. The system editor starts up with several windows showing. Go to the window that is displaying AUTOEXEC.BAT.
  5. Look for the CLASSPATH
  6. Edit the CLASSPATH statement by Adding a semi-colon and a period (;.) to the END of the existing CLASSPATH
  7. Close the AUTOEXEC.BAT window. If the class problem persists, restart your computer.