CSCI 136
Fundamentals of Computer Science II
Spring 2013

Montana Tech
Computer Science & Software Engineering



RESOURCES

This page has useful resources and links related to the Java programming course:
Previous course web sites are also available:

Installing Java on your Windows computer
On Windows, before installing Eclipse you should first install the Java Development Kit (JDK). You want the Java SE Development Kit 7u6. Make sure to install the version marked JDK (Java Development Kit) and not the one marked JRE (Java Runtime Environment). The JDK includes the javac compiler which you'll need since you'll be building your own programs using Java.

Start by going to Oracle's Java download page. Accept the license terms at the top of the page. If you have a 32-bit machine, click the jdk-7u6-windows-i586.exe link. If you have a 64-bit machine, click the jdk-7u6-windows-x64.exe link. If you aren't sure what type of machine you have, you can find out by going to Start -> Control Panel -> System and Security -> System -> System Type. During installation, just accept the default options by clicking Next several times.

During installation, make note of the Java installation directory (usually something like C:\Program Files\Java\jdk1.7.0_06). We want to add the installation directory with \bin tacked on the end (so usually C:\Program Files\Java\jdk1.7.0_06\bin) to the Windows PATH variable. This makes it so the Java compiler and runtime can always be found from the command shell.
Add the Java bin directory to the front of your PATH followed by a semicolon (e.g. C:\Program Files\Java\jdk1.7.0_06\bin;). Be careful not to delete the existing information in your PATH variable! The directory name needs to be exactly correct or it won't work.

If Java is having trouble finding class files in your current directory (e.g. StdDraw or StdIn), you may have to fix your CLASSPATH. The CLASSPATH is in the same Systems variables section as the PATH. Make sure .; appears at the beginning of your CLASSPATH. This ensures Java looks in your current folder for any class files it needs to run your program.
Installing Eclipse on your Windows computer
First install the Java JDK (see above). There are a variety of different flavors of Eclipse. The current version of Eclipse is named Juno. The lab machines have the prior release Indigo. Either should work, but these instructions describe installing Indigo.

Go to Eclipse IDE for Java Developers (Indigo). On the right side of the page, click the appropriate link for Windows and your machine type (32-bit or 64-bit). To determine your machine type, go to Start -> Control Panel -> System and Security -> System -> System Type.

Eclipse comes in a zip archive and does not have the typical install wizard. Find the folder where you downloaded the Eclipse zip file (eclipse-java-indigo-win32.zip or eclipse-java-indigo-win32-x86_64.zip). Right-click on the zip file, select Extract All. For a destination folder, replacing the existing path with C:\.

(Optional but recommended) After extraction, your root folder C:\ should be displayed. Double-click on the C:\eclipse folder. Right-click on the file eclipse.exe (the one with the purple blob icon). Select Create shortcut. Drag the file eclipse.exe - Shortcut to your desktop. You can now start Eclipse by double-clicking your new desktop shortcut.

Start Eclipse using your desktop shortcut (or by navigating to the C:\eclipse and double-clicking eclipse.exe). You will be asked to select a workspace directory. This is where Eclipse stores all your programs. You can either accept the default or choose a different folder. If you always want to use the same workspace folder, check the box at the bottom.
Updating your Eclipse preferences
You will want to update your Eclipse settings to friendlier values for the course. This applies both to the lab machines and any Eclipse installation of your own. Note that settings are local to each lab machine, so Eclipse may behave slightly differently depending on the preferences.

To do this, you can import our preferences from this file: 135_prefs.epf. You import by doing the following:
Installing Eclipse on your Mac
Mac OS X comes with preinstalled Java goodness. There are a variety of different flavors of Eclipse. The current version of Eclipse is named Juno. The lab machines have the prior release Indigo. Either should work, but these instructions describe installing Indigo.

Go to Eclipse IDE for Java Developers (Indigo). On the right side of the page, click the appropriate link for Mac OS X and your machine type (32-bit or 64-bit). To determine your machine type, go to Apple menu -> About This Mac -> More Info -> Hardware -> Processor Name . Your Mac is 32-bit if you see Intel Core Solo or Intel Core Duo, otherwise it is 64-bit.

Find the folder where you downloaded the Eclipse archive (eclipse-java-indigo-macosx-cocoa.tar.gz or eclipse-java-indigo-macosx-cocoa-x86_64.tar.gz). Double-click the archive. After unarchiving you should see a folder named eclipse. Drag this folder to Applications which appears in the left-side of the finder.

(Optional but recommended) Double click the eclipse folder which is now in Applications. Find the application named Eclipse (the one with the purple blob icon). Drag this into your dock. You can now start Eclipse by clicking the icon in the dock.

Start Eclipse using your dock (or by navigating to Applications -> Eclipse and double-clicking the Eclipse application). You will be asked to select a workspace directory. This is where Eclipse stores all your programs. You can either accept the default or choose a different folder. If you always want to use the same workspace folder, check the box at the bottom.
Using the Windows command prompt
It is possible to compile and run your Java programs directly on the command line. This allows you to do things not possible in the Eclipse IDE such as reading from standard input or piping information between programs.

To start the Windows command prompt, launch All Programs -> Accessories -> Command Prompt. You should see something like:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\keith>
First lets test and be sure the Java Virtual Machine (JVM) can be found by entering java -version:
C:\Users\keith>java -version
java version "1.7.0_06"
Java(TM) SE Runtime Environment (build 1.7.0_06-b24)
Java HotSpot(TM) 64-Bit Server VM (build 23.2-b09, mixed mode)
Second, lets make sure the Java compiler can be found by entering javac -version :
C:\Users\keith>javac -version
javac 1.7.0._06
If either java or javac is not found, you probably have a problem with your system PATH variable (see the instructions in Installing Java on Windows). You can move around your folders using the cd (change directory) command. So for example, if we have an Eclipse project called HelloWorld in the standard location, we can move to the folder containing the source files as follows:
c:\Users\keith>cd workspace

c:\Users\keith\workspace>cd HelloWorld

c:\Users\keith\workspace\HelloWorld>cd src

c:\Users\keith\workspace\HelloWorld\src>dir
 Volume in drive C has no label.
 Volume Serial Number is 9251-5CF1

 Directory of c:\Users\keith\workspace\HelloWorld\src

07/28/2011  06:55 PM    <DIR>          .
07/28/2011  06:55 PM    <DIR>          ..
07/28/2011  06:21 PM               294 HelloWorld.java
               1 File(s)            294 bytes
               2 Dir(s)  14,858,080,256 bytes free
As shown, the dir (directory) command displays a list of all files in the current directory. By default, Eclipse stores the compiled bytecode (*.class) in a separate directory from the source code (*.java). We can move into this directory using .. which is a handle for the directory back one level:
c:\Users\keith\workspace\HelloWorld\src>cd ..\bin

c:\Users\keith\workspace\HelloWorld\bin>dir
 Volume in drive C has no label.
 Volume Serial Number is 9251-5CF1

 Directory of c:\Users\keith\workspace\HelloWorld\bin

07/28/2011  06:51 PM    <DIR>          .
07/28/2011  06:51 PM    <DIR>          ..
07/28/2011  06:21 PM               769 HelloWorld.class
               1 File(s)            769 bytes
               2 Dir(s)  14,858,125,312 bytes free               
From the current directory, here is how we recompile the HelloWorld.java file and create a new HelloWorld.class file. We will then run the program:
c:\Users\keith\workspace\HelloWorld\bin>javac ..\src\HelloWorld.java

c:\Users\keith\workspace\HelloWorld\bin>java HelloWorld
Hello world!

Using the Mac OS X terminal
It is possible to compile and run your Java programs directly on the command line. This allows you to do things not possible in the Eclipse IDE such as reading from standard input or piping information between programs.

To start the Mac OS X terminal, launch Go -> Applications -> Utilities -> Terminal. You should see something like:
Last login: Thu Jul 28 21:25:25 on ttys000
keiths-iMac:~ keith$ 
First lets test and be sure the Java Virtual Machine (JVM) can be found by entering java -version:
keiths-iMac:~ keith$ java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-10M3425)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-384, mixed mode)
Second, lets make sure the Java compiler can be found by entering javac -version :
keiths-iMac:~ keith$ javac -version
javac 1.6.0_26
If either java or javac is not found or is an earlier version, run Software Update and then verify Applications -> Utilities -> Java -> Java Preferences is set to Java SE 6.

You can move around your folders using the cd (change directory) command. So for example, if we have an Eclipse project called HelloWorld in the standard location, we can move to the folder containing the source files as follows:
keiths-iMac:~ keith$ cd Documents
keiths-iMac:Documents keith$ cd workspace
keiths-iMac:workspace keith$ cd HelloWorld
keiths-iMac:HelloWorld keith$ cd src
keiths-iMac:src keith$ ls
HelloWorld.java
As shown, the ls command displays a list of all files in the current folder. By default, Eclipse stores the compiled bytecode (*.class) in a separate folder from the source code (*.java). We can move into this directory using .. which is a handle for the folder back one level:
keiths-iMac:src keith$ cd ../bin
keiths-iMac:bin keith$ ls
HelloWorld.class             
From the current directory, here is how we recompile the HelloWorld.java file and create a new HelloWorld.class file. We will then run the program:
keiths-iMac:bin keith$ javac ../src/HelloWorld.java 
keiths-iMac:bin keith$ java HelloWorld
Hello world!


Page last updated: May 15, 2013