15-200 Lecture 3 (Friday, September 2, 2005)

Handing Assignments In

The first thing we looked at today was how to turn assignments in.

We will be turning assignments in to the course space in the Andrew File System also known as afs.

First of all Macs do not play nicely with the afs system, so while you can find the space using Finder it does not let you write to the AFS space. Instead we have to use the Terminal program that is in the dock of the Mac. It is the icon that is a screen with a >_ on it.

The procedure for handing assignments in is first to enter the terminal program. Since most of you will have learned the afs commands already today's lecture was brief. Here is a more thorough explanation for the freshmen. Also it is very important if you are having trouble to get help and get it early. The last thing you want to do is get to the tests where we have to turn it in using the terminal and be unable to turn in your test. The best idea is to get so used to using the afs space and the commands that you can do it in your sleep.

First of all the basic commands you will need will be:

The basic order of how to hand stuff in is:

First to navigate to the folder:

cd /afs/andrew.cmu.edu/course/15/200/handin/lab1 (or the other lab number)
Second create a directory for you to turn your work into:
mkdir gkesden (or what ever your andrew id is)

Third, enter into the folder that you just created.

cd gkesden (andrew id)

If you type ls and enter then the folder should come up as empty.

Fourth put the assignments into the folder, if the assignment is on the desktop the coding is this:

cp ~/Desktop/SimpleCollection.java .

the ~ represents /afs/andrew.cmu.edu/user#/andrew_id
the . represents the directory you are currently in.

Fifth, If you make a change to an assignment after you already turned the assignment in, Then add a number at the end example gkesden1, gkesden2. The highest number folder is the one that will be graded.

Java API Specification

Next we went to one of the favorite websites. java.sun.com/reference/api/index.html

We can see all the documentation for the java classes. This semester we will be using the version java 1.4.2

The question was asked does everyone know what a class specification file is? A class specification file is what we write when we write a class. Typically it involves two parts, the class interfaces and the implementation.

The class interfaces are the public methods that the outside world can see and use. The implementation is the code that can only be found inside the class and is private.

This website specifies the java interface. All of the prewritten classes have their implementation described here. It shows us the different constructors, what can be passed in as parameters, and what the return types are. You cannot build something based on an interface, the interface just describes what has already been built. An interface is a protocol, it lets you know how to use the code that has already been written.

Lets think of an example. (Opens wallet and takes out all the credit cards) These credit cards are all the same size. There is a standardization of credit cards that says credit cards are this wide by this long, this thick and the corners will be at least this rounded. In a car there is a gas pedal and a brake pedal and there is a standardization that governs it. Can you imagine if someone built a car where the pedals were reversed?

An interface is a standard for programming. If you are building your own class you can adhere to these requirements and then you are said to adhere to the interface.

There are many ways to store things, lists, trees, arrays. The appropriate way of organizing them depends on the particulars of how they are going to be used and how many there are going to be. Look ups may be fast but then the inputs are slow. Inputs may be fast but then look ups are slow. We may want to separate the interface from implementation so we can change the back end of the code.

We looked at an ArrayList, it is similar to what we wrote last time (SimpleCollection), but it implements Collection interfaces. Anything that implements the Collection interface will use all of the existing Collection methods and all the Collection methods will work. The list interface has a different list of methods, and some are the same and some are different. But it can use all of the same methods as the Collection class.

An ArrayList is a type of Collection and does all the basic Collection things but it is also a List and has all the ordered properties of a List.

The expectation is that you can come to the java website and use and work with ArrayLists.

Next we did a quick example.

Import java.util.* // how did I know I needed to import this? I navigated 
                   // to the java website and in the Class ArrayList
                   // it says that it is part of java.util heirarchy, that 
                   // means I need to import java.util.*

Class QuickExample{

Public static void main (String[] args){
    	ArrayList al = new ArrayLIst();
	al.add ("Greg")
	al.add("kesden");

	System.out.println(al);
    }
}

Now I can change it to just a List and it will work because ArrayList implements List.

ArrayList al = new List();

So what other kinds of lists are there? LinkedList and Vector are a couple examples.

Change ArrayList to LinkedList and it still works
ArrayList al = new LinkedList();
Instead of LinkedList it is going to be a Vector
ArrayList al = new Vector();
No matter what we change it to the output it is still the same
[Greg, Kesden]

Why? It is because they all use the List interface. Therefore the methods are inherited from the List class and can be used by the the various types of list classes(LinkedList, ArrayList, Vector). It doesn't matter what we have to use because they all have the List implementation. But if it is a method that is specific to only Vector then it doesn't work. Or if the method is only for LinkedLists then it won't work.

For example we looked at LinkedLists specifications.

The method addFirst for example, is unique to LinkedList,

List l = new LinkedList();
l.addFirst ("Greg");

This gives us a compile error, because it does not recognize the method as a List method. But if we change List to LinkedList then it works.

LinkedList l = new LinkedList();
l.addFirst("Greg");

We also can force it by casting the List as a LinkedList. This lets the computer recognize it as a LinkedList in this line of code.

((LinkedList)l).addFirst("Greg");

And on that note we ended class. We will have a new lab out sometime this weekend, once the course website is fixed.