Helpful Hints (CSCI 14)

Home Up Syllabus Schedule Resources Helpful Hints Labs Program Samples

 

Topics on this page: 

Getting to your command prompt on a Windows Machine (95, 98, 2000, XP)

To connect to your Unix account at school from home

         The old-fashioned way.

        An Easier Way

Developing Java at Home

        Downloading and Installing the SDK

        Setting your "Path"

        Setting the "Class Path" Variable

        Creating Programs on Your Home Machine (Not Connected to School)

Transferring Files to and From your Account at School Using FTP

        The "Old-Fashioned" Way to use FTP

        An Easier Way to use FTP

 

Getting to your command prompt on a Windows machine (95, 98, 2000, XP):

There are several ways to access the command prompt while working on a Windows machine.  On my machine (Windows 2000) the command prompt is accessible through the Start | Programs | Accessories | Command Prompt menu selection.  You can also go to the Start | Run dialog box, and type command into the text input box (then click on "okay").  

Perhaps the easiest way (in the long run) to access the command line is to make a shortcut and put it on your desktop.  There are several ways to do this -- I was able to make a shortcut directly from the | Programs | Accessories | Command Prompt menu selection.  I highlighted that menu selection, right clicked the mouse, and chose "create shortcut" from the resulting right-click menu.  This created a shortcut in the menu itself, but I was able to "drag" the shortcut from the menu to the desktop.

The actual command program is found in c:\winnt\system32 (NT and 2000) and c:\windows\system32 (Windows 95 and 98).  You can find the actual program, make a shortcut to it, and put the shortcut on your desktop.  The nice things about these shortcuts is that you can edit their properties (right-click on the icon and choose "properties" from the right-click menu).  You can then do things like set your background color, your text color, size and font, etc.

 

To connect to your Unix account at school from home:

1.  The old-fashioned way.

A.  Connect to your internet service provider (e.g., AOL, Compuserve, Sunset net, etc.)  This will serve as a "socket"  to get you to the school's Unix computer.  If you have DSL, or are working on a PC at school, you are already connected.

B.  Open up a command window, as described above (get to the command prompt). 

C.  At the prompt, type telnet ect-unix.ecst.csuchico.edu

D.  You should then get connected to the school's computer, which will ask you for your log-in and password.

E.  Enter your log-in and password, and you should then end up with a little window running your Unix account on your home computer.  You will be placed in your "home" directory at school.  As this is a Unix environment, you will have to use Unix commands at the command prompt.

F.  Note that when first entering the Unix environment, hitting the backspace key to try to erase input will actually put ^H on the screen, and wont backspace at all.  This can be fixed by typing stty erase <backspace> on the command line, (where <backspace> is actually pressing the the backspace key),  then pressing enter.  From that point on, pressing the backspace key should result in the cursor actually backspacing and erasing input it backspaces over.

 

2.  An Easier Way

A. Download and install PuTTY -- the same program used at school.  It can be downloaded from
                          

B.  Connect to your internet service provider (e.g., AOL, Compuserve, Sunset net, etc.)  This will serve as a "socket"  to get you to the school's Unix computer.  If you have DSL, or are working on a PC at school, you are already connected.

C.  In the "Host Name" field, type ect-unix.ecst.csuchico.edu

D.  Click on "Open" and you should be connected to the school's computer (Tiglon) and asked for your user name and password.  

E.  PuTTY will place you in a window allowing you to run on the school's Unix system from home. 

 

Developing Java at Home

Downloading and Installing the SDK

If you prefer to work at home on your own platform (not connected to your Unix account at school), you need to download and install the Java software development kit (SDK) 1.4.   This program can be downloaded from http://java.sun.com/j2se/1.4/ .   

Setting your "Path"

If after installing the SDK you cannot get the java compiler or interpreter to run at all, you need to modify your "path" system variable. In Windows 95 or 98, you need to edit the "autoexec.bat" file and add the directory to the path that contains the Java executable programs themselves (e.g., java and javac). These programs are usually stored in the directory c:\jdk\bin, although you might have put them somewhere else when installing the SDK. Whatever the directory is, you need to add this directory to the PATH variable in the autoexec.bat file.

The autoexec.bat file is found in the root directory of your boot drive on your local machine (almost always the C drive -- i.e., c:\autoexec.bat ).  You can edit it using notepad, WordPad, TextPad, or any other ASCII editor. You should find a line in the autoexec.bat file that says something like SET PATH=C:\stuff;C\otherStuff\etc; (just an example) This line has several sections after the equals sign separated by semicolons. Each of these sections specifies a place for the operating system to look for executable programs. You need to add the path to your SDK executables to this path variable. E.g.,

SET PATH=C:\stuff;C:\otherStuff\etc;C:\jdk\bin; (added to the end)

You can accomplish the same effect by adding the following line to the bottom of the autoexec.bat file

Set Path=C:\jdk\bin;%PATH%

The above line appends the path c:\jdk\bin to the previously existing set of paths in the path system variable. Once you've made these changes save and exit the autoexec.bat file.

In Windows NT or 2000, the procedure is slightly different. You need to open the control panel, and choose the "System" icon. Under the system dialog box, choose the advanced tab, then choose "environment variables". Choose the Path variable, and edit it directly within the dialog box. You need to add c:\jdk\bin (or whatever your path is to your Java executables) to the existing path. Don't forget the semi-colon after the end.

Windows XP works in the same manner as the NT / 2000 method described above.  Apparently, in Windows XP, you do not have to reboot your machine to have the variables take effect.

Setting the "Class Path" Variable

If you have your SDK installed, and you can run the java compiler and interpreter from the command line, but you get a bunch of errors when you try to compile a class, then your class path system variable is probably not set correctly. The most common error is to not have the "current directory" specified (the "current directory" is any directory you happen to be working in at any given time.)

To add the "current directory" to your class path:

For Windows 95 and 98, get back into that autoexec.bat file as described above. Look for the CLASSPATH variable. It will either look like the following, or it won't exist.

SET CLASSPATH=C:\whatever; (an example)

You need to add the "current directory" to this path. The current directory is specified by a period:

SET CLASSPATH=C:\whatever;.;

Of course, if the class path doesn't exist at all, you need to add the following line.  (See the little dinky period at the end?)

SET CLASSPATH=.;

(See the little dinky period at the end?)

In Windows NT, 2000 or XP, you can directly edit the class path system variable the same way as described for the path system variable. Add the period to the end of the class path variable. Once you have made these changes, you will have to reboot your machine for the changes to take effect.  (Apparently you don't have to reboot with XP).

Creating Programs

You can develop from the command line at home, the same as you do on your Unix account at school.  You use the same commands -- javac to compile, java to run the Java intepreter, etc... You will still need to edit your source code files in one manner or another.  There is a built-in editor that runs on the command line -- it is called, simply, "Edit".  So, to edit a file called "foo", you would type edit foo on the command line.  

However, "Edit" is a clumsy program.  You can also edit java files using Notepad or Wordpad from the desktop.  These are built into Windows, and are usually accessible through the Start | Programs | Accessories menu.  But, you still need to go to the command line (and to the correct directory) to compile and run the java programs.

There are freeware and shareware java editors on the market, which do a lot for you, and make your java programming life a lot easier.  One such editor, which I am used to, and which is recommended in Cay Horstmann's Core Java book is TextPad, found at www.textpad.com .  This tool does a lot of nice things, such as marking different parts of a java program in different colors (e.g., comments are green, keywords are blue, etc.)  In addition, you can compile and run programs from within TextPad, which avoids the problem of switching between a desktop editor and the command line to write, then compile and run a program.

Another shareware text editor recommended by Mike Long is Edit Plus, available at www.editplus.com .  Edit Plus allows a 30 day free evaluation, then the software is disabled, unless you buy a license for $30.  It has similar features as TextPad.\

In Big Java, Cay Horstmann has switched from recommending the TextPad editor to the BlueJ editor.  This is available at www.BlueJ.org

If you know of any other good free or inexpensive java editors, please let me know.

 

Transferring Files to and From your Account at School Using FTP

If you choose to develop programs at home (or both at home and at school) you will need a way to transfer files from your home machine (or a PC in the lab) to your Unix account, and vice versa.  You can certainly e-mail these files back and forth, but this is a bit clumsy. 

Another way is to use FTP.  FTP is a protocol for transporting files across the internet.  (In fact, that is what FTP means -- File Transfer Protocol). 

The "Old-Fashioned" Way to use FTP

The most basic way to use FTP is given below:

  1. Log on to your ISP.  If you have DSL, or are using the school computers, you are already connected. 
  2. Open a command line window on your local machine (your PC) and navigate to the directory in which your development files are stored.  NOTE that if you have file names with spaces in them on your local machine, you will have to surround the file names with quotes.  E.g., if you have a directory called c:\my java, you will have to manipulate that directory using quotes – e.g., -- cd “my java”. 
  3. Once you are in the local directory (on your PC) where your files are stored, open up an FTP session.  Do this by typing “ftp ect-unix.ecst.csuchico.edu” on the command line.
  4. As with telnet, you should be able to establish a connection with the Unix computer at school, which will ask you for your login and password. 
  5. Once connected via ftp, you need to navigate on the remote machine to where you want to store your uploaded files.  Ftp uses a subset of the Unix commands, such as cd, mkdir, pwd, etc.  In addition, ftp has some extra commands such as “get” and “put”.  So, to get to the desired directory on your remote machine, you can use the cd command to get there.  (Or you could use the mv command to move files around once you upload them.)
  6. At this point, to transfer a file your local (home) machine to your school account, you would type “put <filename>” at the ftp prompt, where <filename> is the name of your file.  You can do an “ls” listing after the transfer to make sure the file is there. 
  7. Conversely, to get a file from your Unix account at school and transfer it to your home directory, you would type “get <filename>”.
  8. When done with your ftp session, the command to get out of ftp is “quit”, not “exit”.

 Unix has a peculiarity in which it stores ASCII information in 7 bits rather than 8 bits.  (This is actually true ASCII format, with the 8 bit ASCII being the “extended” ASCII format).  This should not normally pose a problem when transferring text files, such as “Hello.java”.  However, if you want to transfer a non-text file, such as “Hello.class” (the bytecode file) you need to tell ftp that you are transferring information where all 8 bits are important.  You do this by typing binary at the ftp prompt.  To get back to the ASCII format, you can type ascii at the ftp prompt.  (ASCII format is the default format.).  If any of your files get messed up when transferred, it is probably because they were sent as ASCII when they are actually binary, or vice versa.

Note that ftp does not obey all Unix commands, and cannot run your programs remotely.  If you type a command that ftp ignores, this is probably the situation you are dealing with.  You CAN run your programs remotely (e.g. your Java programs) via telnet, but not ftp.

For more information on ftp, you can consult the Unix “man” page on ftp.  You can also do some searches on the Internet for more information.

Easier Ways to use FTP, Including WS FTP Lite

There are also freeware and shareware products that make using ftp easier, and provide nice graphical user interfaces for transferring files.  “CuteFTP” is one such program (www.cuteftp.com) but it costs $39 (after a free 30 day period).  “SmartFTP” (www.smartftp) is free, but it is a bit more complicated and less user-friendly.   I had to buy CuteFTP awhile back for work, but it is very easy to use.

The program used on the PCs in the lab is quite nice.  This program is called WS FTP (lite), and is available to download for free at
 http://www.ftpplanet.com/download.htm .  (The free version is the "light" version).  It can also be downloaded from other sites (do a search on WS FTP).  

WS FTP Lite provides a graphical rendition of the directory and file structure on both your local machine (your PC at home or in the lab) and your Unix account.  You can easily copy files from your local account to your Unix account, and vice versa.  Make sure that you copy the files as "binary" files -- this will make sure that the files are copied verbatim byte by byte, whether or not they only contain text.

WS FTP Lite has some dangerous features that you need to be aware of.  When you copy files, WS FTP Lite does not warn you that you are about to overwrite files and will simply clobber existing files if they have the same name.  In addition, beware that double-clicking on a file name tells WS FTP Lite to copy that file to the other directory structure (PC to Unix or Unix to PC), and, again, WS FTP might clobber an existing file with the same name without warning you.