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

CSCI 135
Fundamentals of Computer Science I
Fall 2018



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 10. 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. (Please note that these instructions were current as of 8/16/18. Java is updated periodically, so the version numbers may be slightly different when you install it.)

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 10.0.2. If you have a machine running Windows, click the jdk-10.0.2_windows-x64_bin.exe link. Choose the Save File button. Then go to your downlads and click that file to run it. 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-10.0.2). We want to add the installation directory with \bin tacked on the end (so usually C:\Program Files\Java\jdk-10.0.2\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\jdk-10.0.2\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), 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 Photon, but the exact Eclipse version you use isn't so important.

Go to the Eclipse download page. In the section "Get Eclipse Photon", click the Download 64 bit button. Choose Save File. Go to your downloads and click the dowlnoaded file to start installation. When the installation starts you will be asked which IDE you want. Choose Eclipse IDE for Java Developers, then choose Install (and accept the license agreement).

You can launch Eclipse from installation. If you do so, the first thing it will ask will be which directory you want to use as a workspace. This is the directory where all of your projects will be saved. You can accept the default, or, if you wish to save everything on a USB drive, you can change it here. (This is handy if you are bringing your projects back and forth to class with you.)


Installing Eclipse on your Mac
Mac OS X comes with preinstalled Java. There are a variety of different flavors of Eclipse. The current version of Eclipse is named Photon, but the exact Eclipse version you use isn't so important.

Go to the Eclipse download page. In the section "Get Eclipse Photon", click the Download 64 bit button. Choose Save File. Go to your downloads and click the dowlnoaded file to open the archive and then click on Eclipse Installer to start installation. When the installation starts you will be asked which IDE you want. Choose Eclipse IDE for Java Developers, then choose Install (and accept the license agreement).

You can launch Eclipse from installation. If you do so, the first thing it will ask will be which directory you want to use as a workspace. This is the directory where all of your projects will be saved. You can accept the default, or, if you wish to save everything on a USB drive, you can change it here. (This is handy if you are bringing your projects back and forth to class with you.)


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 "10.0.2" 2018-07-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, 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, click on the Terminal icon at the bottom of the screen. You should see something like:
Last login: Thu Aug 16 10:07:59 on console
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 "10.0.2" 2018-07-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)
 
Second, lets make sure the Java compiler can be found by entering javac -version :
micheles-iMac:~ Michele$ javac -version
javac 10.0.2
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: August 15, 2019