title: Is a character 1 byte or 2 bytes in Java?
body: <p>I thought characters in java are 16 bits as suggested in <a href="http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html" rel="nofollow">java doc</a>. Isn't it the case for strings? I have a code that stores an object into a file:</p>
  
  <pre><code>public static void storeNormalObj(File outFile, Object obj) {
      FileOutputStream fos = null;
      ObjectOutputStream oos = null;
      try {
          fos = new FileOutputStream(outFile);
          oos = new ObjectOutputStream(fos);
          oos.writeObject(obj);
          oos.flush();
      } catch (IOException e) {
          e.printStackTrace();
      } finally {
          try {
              oos.close();
              try {
                  fos.close();
              } catch (Exception e) {
                  e.printStackTrace();
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>Basically, I tried to store an string <code>"abcd"</code> in to file <code>"output"</code>, when I opened up <code>output</code> with an editor and deleted the none string part, what's left is just the string "abcd", which is 4 bytes in total. Anyone knows why? Does java automatically saves space by using ASCII instead of UNICODE for Strings that can be supported by ASCII? Thanks</p>