title: Java Primitive data type on Stack or Heap?
body: <p>If i am correct Primitive data type defined locally would be on the stack. However if a primitive data type were defined as part of an instance of on object that primitive would go on heap. </p>
  
  <pre><code>class  Test
  {
      int y=10; // defined as part of the class
  
      public void function1(){
          int x = 5; // defined locally
      }
  
      public static void main(String[] args) 
      {
          Test obj = new Test();
      }
  }
  </code></pre>
  
  <p>So in the above code will x be stored on the stack and y on the heap ? I am confused how they are stored and why does it matter stack or heap ?</p>