title: Mixed Integer and String bytebyffer in java
body: <p>I have a bytebuffer in java that is a mix of string and integer types, here is the code to get a better idea of what I mean.</p>
  
  <pre><code>    int ID_SIZE = 8;
      int LENGTH_SIZE = 8;
      int MESSAGE_SIZE = 30;
      char[] id = new char[ID_SIZE];
      int length = 12;
      String message = "\0";
      for(int i = 0;i&lt;MESSAGE_SIZE;i++)
          message+="a";
      ByteBuffer bbuf = ByteBuffer.allocate(35);
      bbuf.putInt(length);
      bbuf.put(message.getBytes());
      for(int i = 0;i&lt;36;i++)
          System.out.println(bbuf.get(i));
  </code></pre>
  
  <p>and as the result I get</p>
  
  <pre><code>0
  0
  0
  12
  0
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  97
  </code></pre>
  
  <p>I know the <code>97</code> is ASCII <code>a</code>. However I am curious as to why before the <code>12</code> it is <code>0</code> <code>0</code> <code>0</code>? Does this have anything to do with it being a mixed bytebuffer or is this just normal byetbuffer behavior?</p>