title: Where and when the use of primitive data types in Java is effectively appropriate?
body: <p>Consider the following two segments of code in Java,</p>
  
  <pre><code>Integer x=new Integer(100);
  Integer y=x;
  Integer z=x;
  
  
  System.out.println("Used memory (bytes): " +   
  (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory()));
  </code></pre>
  
  <p>In which the memory usage was when tested on my system <strong>: Used memory (bytes): 287848</strong></p>
  
  <hr>
  
  <p>and</p>
  
  <pre><code>int a=100;
  int b=a;
  int c=a;
  
  System.out.println("Used memory (bytes): " + 
  (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory()));
  </code></pre>
  
  <p>In which the memory usage was when tested on my system <strong>: Used memory (bytes): 287872</strong>    </p>
  
  <hr>
  
  <hr>
  
  <p>and the following</p>
  
  <pre><code>Integer x=new Integer(100);       
  System.out.println("Used memory (bytes): " +  
  (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory()));
  </code></pre>
  
  <hr>
  
  <p>and </p>
  
  <pre><code>int a=100;        
  System.out.println("Used memory (bytes): " + 
  (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory()));
  </code></pre>
  
  <p>in both of the above cases, the memory usage was exactly the same when tested on my system <strong>: Used memory (bytes): 287872</strong></p>
  
  <hr>
  
  <hr>
  
  <p>The statement </p>
  
  <pre><code>System.out.println("Used memory (bytes): " + 
  (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory()));
  </code></pre>
  
  <p>will display the total memory currently in use [Total available memory-Currently free available memory], (in bytes).</p>
  
  <hr>
  
  <p>I have alternatively verified through the above mentioned methods that in the first case <strong>the memory usage (287848) was lower</strong> than the second one <strong>(287872)</strong> while in the rest of the two cases it was exactly the same <strong>(287872)</strong>. Of course and obviously, it should be such because in the very first case, y and z contain a copy of the reference held in x and they all (x, y and z) point to the same/common object (location) means that the first case is <strong>better</strong> and <strong>more appropriate</strong> than the second one and in the rest of the two cases, there are equivalent statements with <strong>exactly the same memory usage (287872)</strong>. If it is so, then the use of primitive data types in Java should be useless and avoidable though they were basically designed for better memory usage and more CPU utilization. still why do primitive data types in Java exist? </p>
  
  <hr>
  
  <p>A question somewhat similar to this one was already posted here but it did not have such a scenario.</p>
  
  <p><a href="https://stackoverflow.com/questions/2509025/when-to-use-primitive-and-when-reference-types-in-java">That question is here.</a></p>