Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects Meet Objects Creating Classes

Don't know what the word instantiate means. checked on Google, java and more but it's kind of confused.

We instantiate a new Pezdispenser object and it creates a new instance this object here is referred to as an instance of type Pezdispenser

3 Answers

Instantiate is synonymous with "create". So it means you created an object of type PezDispenser.

Godsh! thanks man, now it makes sense... days on this track ! seriously, thank you!

Words like Class, object, instantiate, etc, are all terms for Object Oriented Programming.

Let's jump out of programming, and use an analogy:

Assume you have a 3D printer, and you've got a blueprint in your computer that you can use to 3D print plastic cars. This blueprint you have is only a template; it contains all the information about the car, but the blueprint itself is not a car. You use that template to print out many many real plastic cars.

Compare that example to Java:

  • Java is the 3D printer: you use this as the tool to construct everything.
  • Class is the blueprint: they are templates, containing vital information, but they're not the objects themselves.
  • Instances are the printed plastic cars: they are the actual object, created using Java (Printer), by using the information from Class (blueprint).

So with that process in mind, "instantiate" is very easy to understand: it refers to the process of using a Class to create an instance:

  • In 3D printer, your computer reads the blueprint to know how to print.
  • In Java, you say:
PezDispenser dispenser = new PezDispenser()

What Happened in That Line?

  • Java reads new, it knows "alright I gotta instantiate an object."
  • Java then sees PrezDispenser(), it knows "I'm going to use PezDispenser as my template."
  • Java then assigns the created object to a variable called dispenser, so you can use it later.

That was a very helpful answer. Thanks Charlie!

To dive in a bit deeper of Amir's answer in attempt to make it more precise than saying that it is a synonym of "create".

1) Merriam-Webster defines instantiate as, "to represent (an abstraction) by a concrete instance." Their usage example is, "Heroes instantiate ideals." Using the word instantiate in this light, "create" is not really one of the synonyms. Some synonyms from this would be: body, epitomize, express, externalize, incarnate, incorporate, embody, manifest, materialize, personalize, personify, substantiate.

Link to Merriam-Webster definition: https://www.merriam-webster.com/dictionary/instantiate

Link to Merriam-Webster thesaurus: https://www.merriam-webster.com/thesaurus/instantiate

2) However, as Craig mentioned in the beginning of the track this is similar to learning a new language and we are immersing ourselves into the new language. In the Java language, instantiate can actually mean "create" literally. Here is a quote from Oracle's website, on a page for Creating Objects, "The phrase 'instantiating a class' means the same thing as 'creating an object.' When you create an object, you are creating an 'instance' of a class, therefore 'instantiating' a class." Link to the Oracle page I referenced: https://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html

It also explains how the operator "instantiates" (or creates) a class by saying, "The new operator instantiates a class by allocating memory for a new object and returning a reference to that memory. The new operator also invokes the object constructor."

So, that is probably why you were confused after looking "instantiate" up on Google and other sources. In our everyday language (English for me), "instantiate" would not mean "create", or really even be linked to it. The definition of that word for sure points in an entirely different direction. But recognizing that you are learning a new language, even though it is a programming language and not a spoken one, some words in our vocabulary may have different uses or may not translate over the same way.