title: How are class attributes/fields stored
body: <p>I know that an instance of this <strong>C++</strong> class :</p>
  
  <pre><code>class A {
     char c;
     int iiii;
     short ss;   
  };
  </code></pre>
  
  <p>would look kind of like this in memory :  <code>c| | | |i|i|i|i|s|s| | |</code> </p>
  
  <p><em>This 4/2 letter annotation has no sense (But I think that my point is clear)</em></p>
  
  <p><code>1 byte for char</code>, <code>3 bytes of padding</code>, <code>4 bytes of int</code>, <code>2 bytes for the short</code>, and <code>2 bytes of tail padding</code>  (platform dependant, but it won't change the logic)</p>
  
  <p>From C++ standards (Compilers wouldn't change the order of the fields in my example):</p>
  
  <blockquote>
    <p>Nonstatic data members of a (non-union) class with the same access
    control (Clause 11) are allocated so that later members have higher
    addresses within a class object. The order of allocation of non-static
    data members with different access control is unspecified (Clause 11).
    Implementation alignment requirements might cause two adjacent members
    not to be allocated immediately after each other; so might
    requirements for space for managing virtual functions (10.3) and
    virtual base classes (10.1).</p>
  </blockquote>
  
  <p>so, I would like to know if it is the same for Java classes, Can the compiler change the order to reduce the padding ? </p>