Updated on: Tuesday, January 11th 2011
The pantheon is a network system that provides access for any Yale affiliate with a NetId to a shell terminal for executing commands on a remote machine. What this means is that you can login to the pantheon from home (or any other computer with Internet access) and run your java programs. Your user account on the pantheon (automatically provided by Yale) also provides you with almost 1GB of storage. This should be more than enough for the amount of space this course will require. This document explains how to use the pantheon for the three main tasks of this course:
The first major difference between the Pantheon and a Windows or Mac computer (like most of you probably have) is that the Pantheon is a Unix/Linux environment. Because of this, there are some differences in the commands you'll use at the command line. The course webpage provides a nice tutorial on Unix/Linux, so it will not be re-covered here. We recommend that you consult that tutorial before trying to use the Pantheon.
Yale ITS provides some great resources on using the Pantheon as well. We recommend you consult those resources prior to using the Pantheon. In particular, read "How do I access the Pantheon through a Secure Terminal Client?" before starting anything on the Pantheon!
Recall again working on the Pantheon is different from working at home. On the pantheon, you ONLY have a command line interface, you do not have windows, a desktop, or taskbar. Therefore, instead of using a graphical text editor, like Notepad, Wordpad, Gedit, etc., for Task 1, you'll need to use a command-line text editor. Thus Task 1 is different for the Pantheon, but Tasks 2 and 3 should very similar.
After you have written, compiled, tested, debugged and perfected your code, you'll need to submit it as a single file (ie. archive). This means you'll need to pull the file OFF of the Pantheon. To do this, consult the Yale ITS webpage on the Pantheon again and read "How can I transfer files to and from the Pantheon?".
A Java Class file has a few naming conventions to be aware of.
Creating a new file on the pantheon is simple. To do so, you can use the
"touch" command in Unix/Linux. Once logged in to the Pantheon you will
see a $ followed by a space, like so("$ "). This is called the command
prompt. At your command prompt, type:
$ touch HelloWorld.java
To verify that your file was created, type:
$ ls
And you should see your new file among those that are listed.
Now that you've created a java file, eg. HelloWorld.java, the fun begins! To begin writing code, you'll need to use a text editor. As mentioned above, when you are logged in remotely to the Pantheon, you cannot use a graphical editor like Notepad. Instead, you will use a text editor called "pico".
Let's edit the HelloWorld.java file you created above. Type:
$ pico HelloWorld.java
This turns your terminal into a primitive text editor. Now you can enter the
source code for your first Java program. Enter the following text (spacing
does not matter):
We will cover what all of the text means. For now, let's finish up editing our source code. To exit pico, type Ctrl-x (aka ^x). You will be asked if you want to save your changes, type 'y'. You will then be prompted to save the changes under the current filename, or provide a new one. Press [Enter] to save changes to the current filename. Now, you should be back to your command prompt.
To compile a .java file, you need to have the Java Compiler installed and the classpath needs to be set. One of the benefits of working on the Pantheon is that the Java Compiler and Java Runtime are already installed on every machine. Therefore, compiling your .java files is very easy.
To start, let's make sure that the HelloWorld.java file is in the current
directory. At the command prompt, type:
$ ls
to see all the files in the current directory. Among them should be your
HelloWorld.java file.
Now invoke the Java Compiler with the command "javac" followed by the .java
file(s) you want to compile. In our case, type:
$ javac HelloWorld.java
If there are no errors, you should be presented with the command prompt once
again. (Note: If there are errors, we would start debugging our code, which is
covered in other areas of the course site.) The Java Compiler (ie. javac
command) creates a new file with a different extension as the .java file. The
new file in our case is HelloWorld.class. To verify that this file has been
created, type:
$ ls
Now the files listed should include HelloWorld.java and
HelloWorld.class. The .class file is your compiled program, and it is
required to execute your program. With the .class file, you are ready to run
your program!
Just as the Pantheon has the Java Compiler already installed, the Pantheon
also has the Java Interpreter, or Java Runtime Environment (JRE), installed.
Therefore, running a compiled Java Program is easy. Type:
$ java HelloWorld
Note: you do not type the .class extension of the file. The Java Runtime
automatically knows that it needs to use the HelloWorld.class file. Therefore,
the .class extension is always omitted!
In our case, you should see the following output: