Below is a short tutorial designed for someone who is familiar with programming (potentially only at the level of MATLAB), and has never learned or long forgotten Java. After explaining the very basics of classes and objects, we skip all of the syntax and control flow and go straight to what you will need to complete the workshop. If your Java is not strong, please take the time to understand this tutorial, otherwise you will most likely be lost during the workshop. It should take about 30 minutes.

What is a class?

In Java, all code is associated with a class. Classes have fields and methods. Here is an example of two simple classes:

public class Cat{
  private int age;
  private String name;
  private Cat friend;

  public Cat(String name, int age){
    this.name = name;
    this.age = age;
    this.friend = null;
  }

  public Cat(String name, int age, Cat friend){
    this.name = name;
    this.age = age;
    this.friend = friend;
  }

  public String getName(){
    return name;
  }

  public String getFriend(){
    if(friend == null){
      return "I am have no friends :(";
    }
    else{
      return "My friend is " + friend.getName();
    }
  }

  public String sayHello(String aboutMe){
    return "Hello World!  My name is " + name 
        + " and I am " + age + " years old."
        + " I am " + aboutMe+".";
  }
}

public class CatsTheMusical{
  public static void main(String[] args){
    Cat mist = new Cat("Mr. Mistoffelees",8);
    System.out.println(mist.sayHello("magical"));
  }
}

Lets make sure we understand how this works. First, lets talk about the contents of the files Cat.java.

Now that we have the basic terminology down, lets examine some of the finer points:

Here, we included a method getName() in class Cat.