CSCI 136
Fundamentals of Computer Science II
Spring 2019

Montana Tech of The University of Montana
Computer Science & Software Engineering



RESOURCES

This page has useful resources and links related to the Java programming course:

Lab Tutor Hours (Museum Lab): oftware Installation:
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 9.0.1. 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. In the center panel on the right, there are download buttons for the JDK, Server JRE and JRE. Select the download button under the JDK. Accept the license terms at the top of the download list for Java SE Development Kit. If you have a 64-bit machine, click the jdk-9.0.1_windows-x64_bin.exe link.

During installation, make note of the Java installation directory (usually something like C:\Program Files\Java\jdk1.9.0_1). We want to add the installation directory with \bin tacked on the end (so usually C:\Program Files\Java\jdk1.9.0_1\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.9.0_1\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. If you don't have a CLASSPATH variable, you can create one here.
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 Oxygen, but the exact Eclipse version you use isn't so important.

Go to the Eclipse download page. In the section "Eclipse IDE for Java Developers", click the Download Packages link (below the orange Download 64 Bit button) then next to the Eclipse IDE for Java Developers (second on the list) click the appropriate link for your machine type (32-bit or 64-bit). To determine your machine type, go to Start -> Control Panel -> System and Security -> System -> System Type. Click on the big orange Download button to download the file.

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-luna-R-win32.zip or eclipse-java-luna-R-win32-x86_64.zip), usually your Downloads folder. 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 may 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 Oxygen, but the exact Eclipse version you use isn't so important.

Go to the Eclipse download page. In the section "Eclipse IDE for Java Developers", click the Download Packages link (below the orange Download 64 Bit button). At the top of the orange and blue box is a drop down menu with Windows selected. Click on the arrow and select Mac OS X (Cocoa). On the right side of the page, click the 64 bit link for Mac OS X by the Eclipse IDE for Java Developers.

Find the folder where you downloaded the Eclipse archive. 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, that is, not using Eclipse at all. 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\Michele>
First let's test and be sure the Java Virtual Machine (JVM) can be found by entering java -version (the exact version displayed will vary depending on what you installed):
C:\Users\Michele>java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b17)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
Second, lets make sure the Java compiler can be found by entering javac -version :
C:\Users\Michele>javac -version
javac 1.8.0_60
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\Michele>cd workspace

c:\Users\Michele\workspace>cd HelloWorld

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

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

 Directory of c:\Users\Michele\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\Michele\workspace\HelloWorld\src>cd ..\bin

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

 Directory of c:\Users\Michele\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\Michele\workspace\HelloWorld\bin>javac ..\src\HelloWorld.java

c:\Users\Michele\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
micheles-iMac:~ Michele$ 
First lets test and be sure the Java Virtual Machine (JVM) can be found by entering java -version (the exact version displayed will vary depending on what you installed):
micheles-iMac:~ Michele$ java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-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 :
micheles-iMac:~ Michele$ javac -version
javac 1.8.0_60
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 8.

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:
micheles-iMac:~ Michele$ cd Documents
micheles-iMac:Documents Michele$ cd workspace
micheles-iMac:workspace Michele$ cd HelloWorld
micheles-iMac:HelloWorld Michele$ cd src
micheles-iMac:src Michele$ 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:
micheles-iMac:src Michele$ cd ../bin
micheles-iMac:bin Michele$ 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:
micheles-iMac:bin Michele$ javac ../src/HelloWorld.java 
micheles-iMac:bin Michele$ java HelloWorld
Hello world!


Page last updated: December 20, 2019