Java 101 - Classes and Objects
What is a class?
A class is the blueprint that is used for instantiation (creating) objects into the computer's memory.
What is an object?
It is a self-contained entity that exists in memory that contains all of the code that exists in the .class file that it was created from.
So remember a class is our code that exists in a .class file on the hard-drive and an object is our code that exists in a .class file on the hard-drive and an object is our code that exists in memory and interacts with the JVM to run our program.
Now within our object we have access to instance variables and methods to allow us to interact with it.
What is an instance variable?
An instance variable is a particular piece of information that describes some part of our object.
Finding the components
import javax.swing.JOptionPane; public class Example
{
public static void main (String [] args)
{
JOptionPane myIO = new JOptionPane();
myIO.showMessageDialog(null, "Hello World");
}
}
In the first line we tells the compiler where to find the class called JOptionPane.