Help topics
Using new version (1.5 or higher) of Java
Errors and possible solutions
Logging in
Basic UNIX commands
Editing files
Compiling and running a Java program
<Back to CS445 Recitation Homepage>
Using new version (1.5 or higher) of Java
As you may know the Java language has evolved and different versions are now available. Our text uses the most recent version, Java 1.5 (also called Java 5.0). To check which version of Java you are using, type
$ java -version
Most likely, you will see
java version "1.4.0_01"
followed by some other information.
The most recent version of Java IS installed on these workstations, but it is in a different location in the machine's directories. To access the most recent version of Java, you must type out the entire path to the program. Try the following command
$ /usr/local/java/bin/java -version
You should now see
java version "1.5.0_03"
Since it's an enormous pain to have to type /usr/local/java/bin/ before javac every time you compile, you have to add the path of the program to the PATH variable every time you log in. Do this by typing
$ export PATH=/usr/local/java/bin:$PATH
But we can have UNIX do this for us every time we open a terminal window. First change directories to your home directory. This is the default directory of the cd command.
$ cd
Next, edit your BASH profile script that gets executed every time a terminal window is opened (or you log in remotely).
$pico .bash_profile
Use the Ctrl-V command to scroll down through the file. The line we need to edit is around 300 and should look like this
PREPATH=$HOME/bin
Add the path or our java compiler and interpreter so that it looks like this
PREPATH=$HOME/bin:/usr/local/java/bin
Save the file with the Ctrl-O command and exit with Ctrl-X. The change you just made haven't effected the current terminal window yet but will effect all future windows you open. To make the changes visible in the current terminal, try the following command
$ source .bash_profile
Now you should see the newest java version by simply typing
$ java -version
<back to top>
Errors and possible solutions
What can go wrong? Plenty. Here are some common problems.
You cannot access javac, java, or pico. You should ask your TA to help you set your path variable. In the meantime, you can start pico using the command /usr/local/bin/pico and you can access the Java compiler and the Java interpreter using their absolute path names shown above.
You have no available disk space. If you have used your allocation of disk space you might not be able to login. You will need to delete some files before you can continue. Ask your TA to help you with this. It is also possible to increase your disk space quote (to a limited extent). If you want to do this, ask at any of the CSSD Campus Computing Labs.
The machine freezes. You will need to reboot the machine by pressing the stop key and a simultaneously, then type boot. This will take a few minutes.
<back to top>
Logging in
At the login prompt, before you login, click on the "Options" button, then select "Session," and "Common Desktop Environment". Then login using your Pitt account (id and password). After a few moments you should see the Solaris desktop. A lot of icons should show on the screen. Experiment with some of these if you'd like. Note that the windows that appear are not the same as MS Windows. Experiment with these as well so that you become familiar with the desktop and the environment. A Help Viewer window should be present on the desktop. Read through the topics listed to learn more about using this desktop. Note the EXIT icon on the bottom of the screen. This will be used to log out of your session when you are finished. Always remember to log out before leaving the lab.
Start a terminal window (which is very much like a DOS window) by right-clicking on the background, then selecting "Tools," and "Terminal." A window with a prompt should appear.
<back to top>
Basic UNIX commands
While it is possible to issue commands through icons and mouse clicks, it is more convenient to type commands into a terminal window. If you are used to Windows, this might seem awkward at first, but will quickly become automatic to you.
Login and start a terminal window. Issue the command date, which will tell you the current date and time.
$ date
You can get documentation on most commands with man. You can view subsequent pages of documentation by hitting the space bar (or 'Q' to stop reading).
$ man date
The pwd command displays the path to your current directory. For instance, it might display:
$ pwd
/afs/cs.pitt.edu/usr0/mehmud/public/html/CS0445
You do not need to know exactly what this means, but you should be aware that UNIX has a hierarchical file system. The output above says that you are in the 'CS0445' directory, which is in the 'html' directory, which is in the 'public' directory, which is in the 'mehmud' directory, which is in the 'usr0' directory, which is in the 'cs.pitt.edu' cell, which is part of 'afs'. The directory / folder structure of MS DOS / Windows was based on that of UNIX, so if you are familiar with MS Windows folders, UNIX directories should seem familiar as well. One important difference in the two, however, is the separator used between subdirectories. In UNIX the forward slash is used (as shown in the example above) while in MS Windows the back slash is used.
You can list the your files and subdirectories with the ls command.
$ ls
Backup TA bin private
News TUTORIAL nsmail public
If you have not used this account before you might have no files. However, you should have at least two subdirectories in your main directory: 'public' and 'private'. The 'public' directory is used to store files that you wish other people to be able to read, such as your Web page files (if you have one). The 'private' directory is used to store files that can only be accessed by you.
The cd command allows you to change directories. Change to your 'private' directory by typing
cd private
Now type pwd to see that your directory level has changed. To go back up one directory level, type
cd ..
Experiment with the cd command so that you are comfortable moving from one directory to another in your account. Now make sure that you are in your 'private' directory. Then type the commands:
$ mkdir cs445
$ cd cs445
This will make a new subdirectory within your 'private' directory that you can use for your cs445 labs and projects, and then change your current directory to that new subdirectory. If you wish, you can make additional subdirectories within your 'cs445' directory for different labs and projects.
The copy command, cp FILE1 FILE2, copies one file to another. You can copy the ListInterface.java file from my Web directory to your current directory with the following command:
$ cp /afs/cs.pitt.edu/usr0/mehmud/public/html/CS0445/ListInterface.java .
The single period refers to the current working directory, which should be your 'cs445' folder. The copy command accepts any path as an argument. By not specifying a filename as the second argument here, rather a directory, the file is copied to that directory with the same file name. If a different file name is specified, the file is copied to the path location and renamed to the new file name.
You can view the contents of a file with the command, cat FILE. Thus, cat ex1.java will (very quickly) print the contents of ex1.java on the screen. If that was too fast to read, you can type, more ex1.java. Hitting the space bar will display subsequent pages and Control-C will interrupt the command.
Finally, mv FILE1 FILE2 will change the name of a file, and rm FILE will delete a file.
There are many other Unix commands that may be useful to you, but the ones above should be enough to get you started. For more information on basic Unix commands, read the following Unix Document. For more detailed information on the Unix operating system, read a good book on Unix such as Learning the UNIX Operating System (Peek, Todino, and Strang, O'Reilly 1997). The UNIX system includes a set of very powerful tools that are useful to any professional programmer.
<back to top>
Editing files
You will need to create code files. You can do this using any editor you choose (there are several available -- for example emacs and vi). However, for those of you unfamiliar with Unix I recommend pico, since it is easy to learn and use.
Now practice editing with the HelloWorld.java file that you downloaded from the handouts directory above:
$ pico HelloWorld.java
Try all of the commands to become familiar with the editor. Don't worry about changing the file -- you can always copy it again if you need to.
When developing Java applications on these workstations, one good idea is to open two terminal windows (as explained above in the Logging In section) and set both windows to your working directory. Then edit your file in one window using pico, and compile and run your program in the other window using javac and java (as explained below). You can open even more terminal windows if you wish.
<back to top>
Compiling and running a Java program
running a Java application is a two-step process. Assume we already have the HelloWorld.java file, then
1. Compile the program into byte code via the javac command:
$ javac HelloWorld.java
2. Run the byte code via the java command
$ java HelloWorld
<back to top>
(The above contents are taken from the CS401 course website of PJ Dillon) |