A Java object is a set of data combined with methods for manipulating that data. An object is made from a class; a class is the blueprint for the object.

Each object made from a class will have its own values for the instance variables of that class. Instance variables are things an object knows about itself.

Things an object can do are called methods.

The three steps to creating a Java object are:

  • Object Declaration
  • Object Instantiation
  • Object Initialization

Object Declaration

Declaring an object associates a variable name with an object.

Object Instantiation

Instantiating an object allocated space in memory for the object. This is accomplished with the new operator.

Object Initialization

Initializing an object fills the objects varibles with an initial set of values. This is accomplished using a constructor.

This example creates a Java object named address from the class URL and initializes it with the value http://www.java-tips.org:

 URL address = new URL("http://www.java-tips.org");