-bash-4.1$ ls -ld *.java
-rw-r--r-- 1 dgerman faculty 544 Apr  3 14:48 Collections.java
-rw-r--r-- 1 dgerman faculty  62 Apr  3 14:47 Comparable.java
-rw-r--r-- 1 dgerman faculty 341 Apr  3 14:49 Program.java
-rw-r--r-- 1 dgerman faculty 316 Apr  3 14:48 Student.java
-bash-4.1$ cat Program.java
import java.util.*;

class Program {
  public static void main(String[] args) {
    ArrayList<Student> a = new ArrayList<Student>();
    a.add(new Student("Larry", 12));
    a.add(new Student("Laura",  7));
    a.add(new Student("Alex",  9));
    System.out.println( a );
    Collections.sort( a );
    System.out.println( a );
  }
}
-bash-4.1$ cat Student.java
class Student implements Comparable<Student> {
  String name;
  private Integer age;
  Student(String name, Integer age) {
    this.name = name;
    this.age = age;
  }
  public int compareTo(Student other) {
    return this.age - other.age;
  }
  public String toString() {
    return name + "/" + age;
  }
}

-bash-4.1$ cat Comparable.java
interface Comparable<T> {
  public int compareTo(T other);
}
-bash-4.1$ cat Collections.java
import java.util.ArrayList;

class Collections {
  public static <T extends Comparable<T>> void sort(ArrayList<T> students) {
    boolean sorted = false;
    while(! sorted) {
      sorted = true;
      for (int i = 0; i < students.size() - 1; i = i + 1) {
        T a = students.get(i);
        T b = students.get(i+1);
        if (a.compareTo(b) > 0) {
           students.set(i, b);
           students.set(i+1, a);
           sorted = false;
           System.out.println("Swapping " + a + " with " + b);
        }
      }
    }
  }
}
-bash-4.1$ javac Program.java
-bash-4.1$ java Program
[Larry/12, Laura/7, Alex/9]
Swapping Larry/12 with Laura/7
Swapping Larry/12 with Alex/9
[Laura/7, Alex/9, Larry/12]
-bash-4.1$