How Is Instantiation Different from Initialization of a Java Variable?

Question
Variables in Java store data (e.g., a string or number). How is instantiation of a variable different from initialization, or are they the same?

Answer
Instantiation is different from initialization. Instantiation is the creation of the variable (e.g., through the Java syntax or invocation of a method that creates the variable). A class can be instantiated or a primitive variable can be instantiated. Instantiation involves memory allication for the object (either for a class or a primitive value). See Oracle documentation and TechTarget's definition.

Initializing a variable is the act of giving a variable a specific value. When a variable is assign an initial value, this is initialization.

"Variables are containers for storing data values." (Taken from https://www.w3schools.com/java/java_variables.asp)

Instantiation and initialization are terms used outside of Java.

Leave a comment

Your email address will not be published. Required fields are marked *