Difference between revisions of "Setting up your own computer"

From CompSciWiki
Jump to: navigation, search
(Cleaned up the Mac and Windows part of installing the JDK)
(Added a conclusion)
Line 6: Line 6:
  
 
==Introduction==
 
==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.  
 
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.  
  
Line 172: Line 173:
 
<LI>Close the AUTOEXEC.BAT window. If the class problem persists, restart your computer.</LI>
 
<LI>Close the AUTOEXEC.BAT window. If the class problem persists, restart your computer.</LI>
 
</OL>
 
</OL>
 +
 +
==Summary==
 +
 +
In conclusion, make sure you have the Java SDK installed on your computer before choosing DrJava or TextPad. This is key to making your life easy in terms of setting up your programming environment. After that, follow the steps above to install your choice of program. If you have any problems, contact your professor.
 
}}
 
}}

Revision as of 14:21, 6 December 2011

COMP 1010 Home > What is Programming?


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.

Installing Java SDK

Below are the instructions for setting up the Java SDK for various operating systems you may be using. Consult your professor if you cannot get the SDK working.

Windows

NEW!***When the Java website asks you for your operating system, choose 'Windows'. Do NOT choose 'Windows 64-bit'. Install the Java Developer's Kit (JDK). The JDK allows your computer to create and run Java programs. There is a problem with the Windows 64-bit version of JDK, QuickTime, and TextPad. The easiest solution is to just go back to the 32-bit version of JDK.

Mac

Java should already be installed on your machine unless you are running Mac OS X (Lion) as it does not include Java. You can download it here: http://support.apple.com/kb/DL1421. Once the SDK has been installed. Go ahead and install DrJava or it's alternative, TextPad.

Second Step: Install Dr Java

We'll be using DrJava as the development environment for this course.

Below is the link to download JDK and installation instructions.

Frequently Asked Questions on DrJava:

  • I can't find DrJava after downloading it? Did you use Chrome? Chrome installs DrJava in the non-standard directory C:\Users\username\Documents\Downloads.
  • Can I detach the tabbed panes (for Interactions, Console, and Compiler Output)? Yes. Click Edit, then Tabbed Panes, then check "Detach Tabbed Panes".
  • What can I do if DrJava is not listed with my other programs? DrJava may not automatically install itself in your program directory. So, to easily find the program, add it to your start menu, or create a shortcut on your desktop.
  • Why does DrJava always require me to choose "Run" when I open the program? Just remove the check mark from "Check each time that you want to run this program".
  • How do I set up my computer so I can click on a java file and it will automatically open in DrJava? Click on a java file with your right mouse button. Choose "Open With" and choose DrJava as the default program. You can also set default files in your web browser.



Some guides to using DrJava:


Alternate Development Environment: TextPad

Some students may wish to program using TextPad (instead of Dr. Java). The following instructions are for students using TextPad with the JDK.

Installing TextPad

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.

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.

Here's a short Guide to TextPad.

Common Problems with JDK and TextPad

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

NEW!*** When you were installing JDK did you chose 'Windows' or 'Windows 64-bit'? If you chose Windows 64-bit, uninstall JDK, then reinstall it, choosing just 'Windows'. There is a problem with the Windows 64-bit version of JDK, QuickTime, and TextPad. The easiest solution is to just go back to the 32-bit version of JDK.

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.

STEP 1: 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

STEP 2: 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

STEP 3: If you're still reading, it probably means you've reinstalled TextPad, then tried to add the "JDK Commands" and they still do not appear. Next? 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


Textpad doesn't use colour for key words

First, make sure you have the JDK commands under the tool menue (see above help item). Next, turn on the Java syntax highlighting:

  1. Click on Configure, then Preferences.
  2. Click on the + beside Java.
  3. Select syntax
  4. Check the box 'Enable Syntax Highlighting' and choose java.syn as the Sytnax Definition File

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.

Summary

In conclusion, make sure you have the Java SDK installed on your computer before choosing DrJava or TextPad. This is key to making your life easy in terms of setting up your programming environment. After that, follow the steps above to install your choice of program. If you have any problems, contact your professor.

Previous Page: What is Programming? Next Page: Anatomy of a Program