CSCI 3310
Spring 2008
Using Java with Unix


Loggin in

The Unix machines are located in Austin 208.

First, try to log into Unix. If you do not know your password, send me email soon indicating that you need your password reset. Be sure to say what your account is.

When you log in, the login window lets you select a session manager. Choose Gnome. If you get a black background, it is because your account has been set up incorrectly. Click on the background, and select new terminal. In the terminal, type

  rm .gnome-desktop
  mkdir .gnome-desktop
then log out. Log back in. You should see a better background.


Creating a program

In Unix, you simply create your program with a text editor. You can use any text editor. A simple one is available by choosing actions/accessories/text editor at the top-left of the screen.


Compiling and running a program

After creating your program, compile it in a terminal window using command

  javac Myclass.java
where Myclass.java is your program. (If your program has several files, then just write all of the files on the line. Create a script that just contains a line that compiles all of your files.) Then run the program using command
  java Myclass
If there are several files, list the name of the file that contains the main method, without the .java part.

If you get a complaint that java or javac are unknown commands, then your account has been set up incorrectly. Do the following, then start a new terminal window.

  cd ~
  cp /usr/local/site/skel/bash_profile .bash_profile


Creating and running a test script

To create a script, use a text editor. Put commands in the file. Here is an example. The first line tells which shell will process the commands.

#!/bin/bash
javac Myclass.java
echo "Test 1"
java Myclass 
If you put this into a file called runtest, then command
  chmod u+x runtest
allows you to execute runtest, and command
  ./runtest
runs it. Writing