title: How does Java Object reference works?
body: <p>I running to a situation and I am very confused. Please help me out.
  Let's say I have a code like this.</p>
  
  <pre><code>MyClass obj1 = null;
  
  List&lt;MyClass&gt; testList = new ArrayList&lt;MyClass&gt;();
  
  testList.add(obj1);//after this line of code, testList will have a "null" at first node
  
  obj1 = new MyClass();//after this line of code, testList still have a "null"
                       //at first node...
                       //What I want is that testList's first node will become a new 
                       //MyClass object
  </code></pre>
  
  <p>Here is the steps in my understanding (probably incorrect...):</p>
  
  <ol>
  <li><strong>obj1</strong> stores the pointer that points to nothing...</li>
  <li><strong>testList</strong> stores the pointer that points to the memory that holds the "new ArrayList()"</li>
  <li><strong>testList</strong> add the pointer of <strong>obj1</strong> in its collection.</li>
  <li><strong>obj1</strong> stores the pointer that points to a "new MyClass()"</li>
  <li>therefore, the <strong>obj1</strong> in the <strong>testList</strong> should automatically points to the "new MyClass()"</li>
  </ol>
  
  <p>Sorry I am new to programming...
  Any help is appreciated!</p>