Lab Assignment 0

CSC 132

August 24, 2000

Due at the end of today's lab period

"A sip of Java"

 

This is a simple application to get you started or refreshed on the production of Java programs. If you complete the assignment very quickly, please stay around to assist those who are not as familiar with the facilities.

1. If your network account has not been created, proceed now to Cheek 150 downstairs with your ZIP card to do this. You'll need this account to access the PCs in labs across campus.

2. There are a number of products to support the development of Java programs. PCs in the CSC labs (Cheek 209, 210, and 213) have three installed.

(a) Microsoft Visual J++, which I do not recommend.

(b) combination of a text editor and the JDK command-line compiler and runtime environment.

(c) Sun's Forte IDE, freely downloadable, which also utilizes JDK.

3. Those of you who learned Java in CSC 131 most likely used method (b). If so, I expect you to use Forte for this assignment (we will use it later in the semester for developing GUI applications anyway). Although designed to facilitate development of GUI applications, it can be used for console (DOS) applications as well. You'll find Forte on the Program menu of the lab PCs.

4. If you have little or no experience with Java, I recommend you start by using method (b). Here is a brief explanation of this method.

- Store your Java course code in files having the ".java" extension. The source file should contain the code for one Java class, and the name of the class needs to be the same as the name of the file. For example, the definition for class Try will be stored in file Try.java.

- You need a working directory to contain your files. You are provided disk space on the NT server called white. It has a folder user, which has folders for each letter of the alphabet. Select the one that matches your first initial. Your individual folder will be in there. If you need help finding it, let me know (follow the path: network neighborhood, entire network, copper). An alternative is to use a Zip disk or a diskette. You can save files to the PC hard drive but you will need to copy them to other storage before logging off, because others may gain access to your files if you forget to delete them plus they are subject to removal at any time by the system administrator.

- Source code can be written using any text-capable editor (e.g. Notepad or Wordpad) but we recommend using PFE (the Programmer's File Editor). A Win32 version is installed in directory C:\jdk1.3 on the lab PCs. On the CSC 132 home page (www.cs.smsu.edu/~pete/csc132/) you'll find a link called "Configuring PFE" that explains how to configure this versatile editor for use with Java.

- Once the source file is edited, you will compile it into "bytecode" using the javac compiler. Fire up a DOS window (C:\winnt\system32\cmd.exe) and make your working directory the current one. The command is "javac filename.java" If the compile is successful, the bytecode file classname.class is created.

- Once the bytecode file is created, you will run it using the java runtime program. The command is "java classname". Note that the file extension is not given.

 

5. Begin by editing and running a "Hello world" application. Use your last name as the class and file name. May as well give you the code at this point. Use:

public class yourLastName
{
	public static void main(String[ ] args)
	{
		System.out.println("Hello world");
	}
}

 

6. Once you've got that working, modify this program so it will prompt the user to enter a character string, accept character string input from the keyboard, then echo that string. Keyboard input is a touchy subject for Java. Like many textbook authors, Dr. Main has provided a class to make this easier. His class is called EasyReader. See Appendix B of your textbook. The source code for EasyReader can be downloaded from the textbook web site (there is a link from my CSC 132 home page, and the EasyReader.java URL is given on page 714, the first page of Appendix B). Store it in the same directory as your other Java code, and comment out the "package edu.colorado.io;" line. You'll also need to add the statement "import EasyReader;" at the top of your source code. See Appendix B for instructions on how to use this class.

 

7. Once you've successfully completed this task, submit your Java source file by copying it to the server directory for this class. On the NT server called eccentric, this is folder upload\csc132\001. Soon that folder will have individual subfolders for each of you but they have not been created yet. Since all of you have different names, you can copy your source file into this folder without fear of file loss. Let me know if you have trouble finding this (it is in copper along with white).

 


[ Assignments | CSC 132 | Peter Sanderson | Computer Science | SMSU ]


Last reviewed: 24 August 2000

Peter Sanderson ( PeteSanderson@smsu.edu )