title: Java variable placed on stack or heap
body: <p>I don't have much idea on Java.</p>
  
  <p>I was going through few links and found blog says "Java Primitives stored on stack", which I feel it depends on instance variable or local variable.</p>
  
  <p>After going through several links my conclusion is,</p>
  
  <hr>
  
  <p>Class variables – primitives – are stored on heap as a part of Object which it contains.</p>
  
  <p>Class variables – object(User Defined) – are stored on heap as a part of Object which it contains. This is true for both reference and actual object.</p>
  
  <p>Method Variables – Primitives – are stored on stack as a part of that stack frame.</p>
  
  <p>Method Variables – object(User Defined) – are stored on heap but a reference to that area on heap is stored on stack as a part of that stack frame.
  References can also be get stored on heap if Object contains another object in it.</p>
  
  <p>Static methods (in fact all methods) as well as static variables are stored in heap.</p>
  
  <p>Please correct me if my understanding is wrong. Thanks.</p>