Difference between revisions of "Setting up your own computer"

From CompSciWiki
Jump to: navigation, search
(Updated chapter_TOC to Gatting Strated instead of What is programing)
(Changed Text Pad Problemd to TextPad FAQ)
Line 72: Line 72:
 
Here's a short [[Guide to TextPad]].
 
Here's a short [[Guide to TextPad]].
  
===Common Problems with JDK and TextPad===
+
===TextPad FAQs===
  
====TextPad Does Not Have the Options to Compile and Run, or These Options are Present But do Not Work====
+
'''Q:'''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.'''
+
* ''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.
 
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.

Revision as of 00:44, 8 December 2011

COMP 1010 Home > Getting Started


Introduction

To start programming in Java, you will first need to set-up your computer. You will need to install the Java Development Kit (JDK) first and then install a development environment. It is important that these two things are installed in this order. The development environment will be where you will write, debug, and run your Java code.

Installing Java JDK

In order to begin developing Java applications and applets, you must have the Java Development Kit (JDK) installed on your computer.

Windows

To get the JDK, visit http://www.oracle.com/technetwork/java/javase/downloads/index.html and download the latest version.

  • Note: Ensure that you download and install the correct version of the JDK for your computer, according to operating system.
  • Tip: When in doubt, get the 32-bit version (x86). Also, if you cannot get it working, consult your professor.

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.

Installing and Using DrJava

DrJava is available for a Windows PC as well as for Mac.

In COMP 1010: Introduction to Computer Science, the main development environment we will be using is DrJava. DrJava is a fully-features Java editor that is simple and very easy to use.

  • For more information on DrJava, as well as download links, tutorials, and technical support, visit their website at http://www.drjava.org.

DrJava FAQs

DrJava on Mac OSX Lion

Q: I just downloaded DrJava, where did it go? I can't find it.

  • Depending on which operating system you computer is running, the file you have to download differs. There are three different files that are available: .exe, .tar.gz, and .jar for Windows, Mac, and Linux respectively. Once downloaded, the file will be located where ever you specified you browser to download files.

Q: Does DrJava work on my operating system?

  • One of the main reasons that we use DrJava for this course, rather than Textpad, is its compatibility with a variety of operating systems. DrJava is compatible most of the popular mainstream operating systems. This includes Windows, Mac OS, as well as Linux systems.

Q: Can DrJava compile and run my programs?

  • Yes, as long as you have installed the Java JDK (as above) DrJava can compile and run your programs, so you do not need to use command line. To compile and run your programs, you can use the buttons on the right-hand side of the top toolbar.

Q: What is the file extension for my java programs?

  • Your Java programs are saved into Class_Name.java files. In addition, when compiling and running java programs there will be other file extensions generated. Those extension are created to as by product fo running you code. When submitting your files submit only .java files.

Some guides to using DrJava:


Alternate Development Environment: TextPad

Textpad is only available for Windows based PCs.

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.

TextPad FAQs

Q: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: Claiming IDs Next Page: Getting Started