A class is a compilation unit, and it combines both properties (member variables) and behavior (methods). The best way to think of it as a blueprint. You write one class, and from that, are able to create as many instances (objects) as you want. They all act the same, but represent a different entity.
public class Dog {
private String name;
public Dog(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void bark() {
System.out.println("woof!");
}
}That class represents (duh!) a dog. In this case, all dogs have a name (the properties), and are able to bark (behavior).
With this, you can do something like:
Dog cobi = new Dog("Cobi");
Dog dog2 = new Dog("Fido");
cobi.bark();
dog2.bark();So basically, a class allows you to create a blueprint for some entity. Then you use it to define particular instances, which act the same way, but have different state. It's a good way to model real-world objects.
The best thing you can do is pick up a copy of
Thinking in Java , by Bruce Eckel. And the beautiful thing is that he offers it for free on his website. So go download that, read through it, and you're well on your way.