What exactly is an instance in Java?

priya picture priya · Feb 26, 2011 · Viewed 263.4k times · Source

What is the difference between an object, instance, and reference? They say that they have to create an instance to their application? What does that mean?

Answer

Mark Byers picture Mark Byers · Feb 26, 2011

An object and an instance are the same thing.

Personally I prefer to use the word "instance" when referring to a specific object of a specific type, for example "an instance of type Foo". But when talking about objects in general I would say "objects" rather than "instances".

A reference either refers to a specific object or else it can be a null reference.


They say that they have to create an instance to their application. What does it mean?

They probably mean you have to write something like this:

Foo foo = new Foo();

If you are unsure what type you should instantiate you should contact the developers of the application and ask for a more complete example.