CS 1021 - Introduction to Java
Fall 2009

Working at Home and Remote Access

At the University, we provide computer labs for students to work on homework, study, and conduct research.  Many students, however, find it more convenient to do this work at home, on a laptop, or someplace else.   This tutorial will provide all the information you need to know about setting up a Windows or Macintosh computer to do homework for this class.

If you have any questions about this tutorial, please email them to teach-cs1410@list.eng.utah.edu with the subject 'Tutorial question'.

Contents

  1. Installing Java
  2. Installing an IDE
  3. Web Handin
  4. PuTTY
  5. WinSCP

Installing Java

Sun (the company that created Java) has provided a set of installation instructions, available here.  The following summary will help get you started, you should also follow their instructions.

Warning: If you make a mistake during installation, it is hard to figure out where you made the mistake.  Follow the instructions carefully.

  1. Download JDK 6 Update 16 (or later) from http://java.sun.com/javase/downloads/index.jsp .

Make sure to download the JDK - do not download the JRE, it is contained within the JDK.

  1. Read and/or print the installation instructions, available here.  Most people will use the 32 bit Windows instructions.
  2. Follow the installation instructions.  Note that some steps may not apply in your case.
  3. Make sure to follow the instruction that tells you how to update your path variable.
  4. Test your installation using the instructions below.
  5. Optional: Download the Java SE 6 Documentation and unzip it into a folder.  (It is at http://java.sun.com/reference/api/ .) Then use your favorite web browser to view the documentation by opening the index.html file.

Once the installation is complete you are ready to install your favorite IDE, such as BlueJ or Eclipse.

Testing a Java installation

These instructions were tested under Windows XP. They may differ for your version of windows.

  1. Open a command prompt. This is the windows shell where you can type commands. The easiest way to open it is to select Start->run and then type cmd and press return. A command prompt will open and you will be working in some default location on your hard drive.
  2. Type notepad and press return. This launches the notepad text editor. (You may use any text editor that can save files in plain text format.)
  3. Switch directories to your My documents directory. (Use the cd and dir commands to change and view directories.)
  4. Type in the following program. Be very careful to type all the punctuation, capitalization, and symbols correctly or it won't work. (You may cut and paste from this browser window to avoid typing.)
// From here
 
import java.util.*;
 
public class Simple {
    public static void main (String[] args)
    {
     List aList = new ArrayList();
     System.out.println("Java 1.6 with generics here...");
    }
}
 
// To here
  1. Save the file as Simple.java in your My documents directory. Make sure only the first letter is capitalized. Also, you will need to change the file type when you save the file to 'All files'. (If you save it as a 'Text file', the filename will automatically be changed to Simple.java.txt which won't work.)
  2. Make sure the file is in the My documents directory. At the command prompt type dir and make sure Simple.java is there.
  3. Compile the file. Type javac Simple.java and wait for the command prompt to reappear. If you get any message, the compilation failed.
  4. Run the program. Type java Simple and see if you get the message that the program should print out. If you do, your Java installation is complete.

Installing an IDE

Now that you have installed Java on your system, you should also install an Integrated Development Environment, or IDE.  Eclipse is recommended for this class.  Another popular, but simple IDE for students is BlueJ.  Other students use NetBeans.  You do not need to have all of these IDEs installed on your home computer; however, instructions are listed for all three IDEs.

Eclipse

Another popular IDE is Eclipse.  Many other CS courses at the University of Utah use Eclipse for their coursework.  Eclipse has much more advanced features than BlueJ, but at the same time, Eclipse is a bit more difficult to learn.

Warning: If you make a mistake during installation, it is hard to figure out where you made the mistake. Follow the instructions carefully.   These instructions were tested on a Windows XP computer.

  1. Go to the Eclipse Download Page.
  2. Download the Eclipse IDE for Java Developers.  After the download is complete, open the zip file in a program such as WinZip or IZArc.
  3. Extract the ‘eclipse’ folder to the C: drive, Desktop, or any other place you like.

Testing Eclipse

After installing, you should ensure that Eclipse works.

 

1.      Run Eclipse

2.      When you first run Eclipse, you will get a dialog asking you to select a workspace.  A workspace is a location where all your projects are saved.  If this is not your first time running Eclipse, skip to step 6.

3.      The default location is usually good.  However, I would recommend setting the workspace to be in a folder called cs1410, such as C:\cs1410.

4.      If you do not want to see this dialog every time you run Eclipse, check ‘Use this as the default and do not ask again.’

5.      Click ‘OK’.

6.      After Eclipse finishes starting, click on ‘File’ and then on ‘New’ and then on ‘Project’

7.      Select ‘Java Project’ and click ‘Next’.

8.      Choose a project name.  For this example, call the project ‘Test’.  Now click on ‘Finish’

9.      Click on the icon on the far right, which, when hovered over, reads ‘Workbench’.

10.  On the left side of the screen should be the Package Explorer.  Here, you will see your ‘Test’ project.  Right click on the project and click on ‘New’ and then ‘Class’.

11.  In the box labeled ‘Name’ enter a name for the class.  For this example, call the class ‘Widget’.

12.  Also, select ‘public static void main(String[] args)’.

13.  Do not change anything else.  Click on ‘Finish’.

14.  The contents of Widget.java should now appear.  The contents of the file should look like this:

                   public class Widget {

 

               /**

                * @param args

                */

               public static void main(String[] args) {

                       // TODO Auto-generated method stub

 

               }

 

      }

15.At the top of the file, add this line: import java.util.*;

16. Look for the line that says // TODO Auto-generated method stub.  Replace it with this line: System.out.println("Hello world!");

16.  Your file should now look like this:

    import java.util.*;

 

     public class Widget {

 

          /**

            * @param args

            */

           public static void main(String[] args) {

                 System.out.println("Hello world!");

 

          }

 

        }

17.  Look for a button at the top of the window that looks like a green circle with a white triangle.  Click on that button.

18.  You will be given a dialog entitled ‘Run’.  On the left side, double click on ‘Java Application’.

  1. Now click on ‘Run’.
  2. The text “Hello world” should appear in the bottom of the screen.  To run the application again, just click on the green circle with a white triangle again.

BlueJ

BlueJ is the simplest of the IDEs - I recommend Eclipse instead.  The object workbench in BlueJ is useful, though.

Warning: If you make a mistake during installation, it is hard to figure out where you made the mistake. Follow the instructions carefully.

  1. Go to the BlueJ Download Page.
  2. Click on the installation that works for your computer.  For most people, this will be Windows.
  3. Follow the Installation Instructions on the webpage.
    1. Run the installation file
    2. Follow the onscreen directions.

Testing BlueJ

After installing, you should ensure that BlueJ works.

  1. Run BlueJ
  2. If this is the first time running BlueJ, you will get a dialog asking for your java version.  If you do not get this dialog, then go directly to step 6.  Click on ‘advanced’ and then click on ‘Browse for Java version’.
  3. Go to the directory for Java.  If you are running Windows, this should be something like C:\Program Files\Java\jdk1.6.0_04\bin\java.  Then click OK.
  4. Click on the 1.6.0_04 build on the dialog.
  5. Click ‘Launch BlueJ’
  6. Create a new Project by selecting “Project” and then “New Project”
  7. Choose a directory for all your projects.  I recommend saving your CS 1410 files in a separate directory.  For example, you could create a folder in My Documents called CS1410.  When you are in the directory you want to save your files, choose a name for your project.  For this example, call the project Test
  8. Click on ‘New Class’
  9. Choose a name for your class.  For this example, call it Widget.  Do not change anything else on this dialog.  Click ‘Ok’.
  10. Right-click on the yellow box labeled “Widget” and select “Open Editor”
  11. Clear out the contents of the file so that the file looks like this:

import java.util.*;

 

public class Widget {

 

}

  1. Insert this code between the curly braces:

public static void main(String[] args) {

           System.out.println("Hello world!");

}

  1. Click on ‘Compile’.  After the file compiles, there should be a message at the bottom saying “Class compiled – no syntax errors”.  If you get a syntax error (i.e. you get some other message), then make sure your file looks exactly like this:

import java.util.*;

 

public class Widget {

 

public static void main(String[] args) {

           System.out.println("Hello world!");

}

 

}

  1. Go back to the main window.  Right-click on the yellow box labeled ‘Widget’ and select void main(String[] args).
  2. At the next dialog, just hit ‘Ok’
  3. The program should bring up a window containing the text “Hello World!”.

NetBeans

A third IDE option is NetBeans.  NetBeans is commonly used for large projects.  NetBeans has a similar type of interface as Eclipse, but has other features in addition.

Warning: If you make a mistake during installation, it is hard to figure out where you made the mistake. Follow the instructions carefully.   These instructions were tested on a Windows XP computer.

  1. Go to the NetBeans Download Page.
  2. Choose your operating system and language.
  3. Enter your e-mail address.  Uncheck all the ‘subscribe to’ boxes if you do not want to receive mail from NetBeans.
  4. Click on ‘Next’.
  5. Next to ‘NetBeans IDE 6.5 Installer’, click on ‘Download’.
  6. Save the file someplace you can remember.  The file is about 60 MB, so it may take a long time to download.
  7. Run the install program, netbeans-5_0-windows.exe (or whatever file you downloaded)
  8. Follow the instructions in the installer
  9. At the end of the installer, pay attention to where the installer place the NetBeans program.  It should be something like C:\Program Files\netbeans-5.0\bin\netbeans.exe.  You may want to create a shortcut to this program.

Testing NetBeans

After installing, you should ensure that NetBeans works.

 

  1. Run NetBeans
  2. The program takes a while to load the first time you run it, please be patient.
  3. When the program is finished loading, click on ‘File’ and then ‘New Project’.
  4. The New Project dialog pops up.  Make sure that on the left, ‘General’ is selected, and on the right, ‘Java Application’ is selected.
  5. Click on ‘Next’.
  6. Give the project a name.  For this example, call the project ‘Test’.
  7. Specify the project location in the box labeled ‘Project Location’.  I suggest putting the project in a separate folder for this class, such as C:\cs1410
  8. In the box labeled “Create Main Class”, enter ‘Widget’.
  9. Click on ‘Finish’.
  10. The source code for Widget.java should be displayed.  Look for this block of code:

         public static void main(String[] args) {

     // TODO code application logic here

  }

  1. Replace this line of code: // TODO code application logic here with this line of code System.out.println("Hello world!");
  2. At the top of the window, look for a button that looks like a green triangle with a yellow triangle.  This is the run button.  Click on this button.
  3. At the bottom, you should see some output that looks like this:

   init:

deps-jar:

Created dir: C:\cs1410\Test\build\classes

Compiling 1 source file to C:\cs1410\Test\build\classes

compile:

run:

Hello world!

BUILD SUCCESSFUL (total time: 0 seconds)

 

Web-Handin

After completing your assignment, you must hand it in electronically in order to receive credit.  See the link on the front page of the class website for instructions.

PuTTY

PuTTY is an SSH client.  SSH means Secure Shell.  It allows you to execute commands on remote computers as if you were sitting in front of that computer.

 

  1. Download PuTTY.  Click on the first link that says ‘putty.exe’.  Save the file someplace you can remember, such as the Desktop.
  2. Run PuTTY.
  3. Look for the box labeled “Host Name (or IP address).  Type into the box best-linux.eng.utah.edu
  4. You will be prompted for your username.  Just use your CADE login name.
  5. You will then be prompted for your password.  Type in your CADE password.  Again, if you do not have your CADE password, please talk to the operators in the CADE lab.  The password will not be printed out as you type it, so don’t worry if nothing shows up while typing.
  6. You should then receive a prompt that looks like this: 101 lab4-5:~>.  Don’t panic if the numbers are not the same.
  7. You can now execute commands as if you were in the CADE lab.  Try typing in this command: java –version
  8. You should get a message describing the version of Java installed on the machine.

WinSCP

WinSCP is an SFTP client.  SFTP means Secure File Transfer Protocol.  It allows you to upload and download files to and from a remote computer.

 

  1. Download WinSCP.  Look for WinSCP 4.0.3 or later.  Click on ‘Standalone application’.  Select a mirror (doesn’t matter which one) and click on ‘Download’ next to the mirror you want to download from.  A mirror is a server which hosts a file so that people far away from the file’s source can download it in a shorter amount of time.  I selected the ‘EasyNews’ mirror, because it is the closest one to Salt Lake City.  Save the file someplace where you can remember, such as the Desktop.
  2. Run WinSCP
  3. In the box labeled ‘Host name’, type best-linux.eng.utah.edu
  4. In the box labeled ‘User name’, type your CADE login name.
  5. In the box labeled ‘Password’, type your CADE password.  Again, if you do not have your CADE password, please talk to the operators in the CADE lab.
  6. Leave everything else the same.
  7. Click ‘Login’
  8. If login proceeds, you will have a window divided in two.  The left side of the window lists the files on your computer you are using now.  The right side of the window lists the files in your CADE lab home directory.
  9. You can upload a file by navigating on the left to the folder where the file is contained and navigating on the right to the folder where you want the file uploaded to, and then dragging the file from the left side to the right side.
  10. You can download a file by navigating on the right to the folder where the file is contained and navigating on the left to the folder where you want the file downloaded to, and then dragging the file from the right side to the left side.

Conclusion

There is much more functionality to these programs than what is listed here, but that is left as an exercise for the reader.  If you have any questions regarding working at home or remotely logging into the CADE lab, please e-mail us at teach-cs1410@list.eng.utah.edu .

Page updated Monday August 24, 2009 at 18:06:05.