title: Java : Char vs String byte size
body: <p>I was surprised to find that the following code</p>
  <pre><code>System.out.println(&quot;Character size:&quot;+Character.SIZE/8);
  System.out.println(&quot;String size:&quot;+&quot;a&quot;.getBytes().length);
  </code></pre>
  <p>outputs this:</p>
  <blockquote>
  <p>Character size:2</p>
  <p>String size:1</p>
  </blockquote>
  <p>I would assume that a single character string should take up the same (or more ) bytes than a single char.</p>
  <p>In particular I am wondering.</p>
  <p>If I have a java bean with several fields in it, how its size will increase depending on the nature of the fields (Character, String, Boolean, Vector, etc...) I'm assuming that all java objects have some (probably minimal) footprint, and that one of the smallest of these footprints would be a single character.  To test that basic assumption I started with the above code - and the results of the print statements seem counterintuitive.</p>
  <p>Any insights into the way java stores/serializes characters vs strings by default would be very helpful.</p>