title: storing an object reference in byte array
body: <p>I have a byte array and an object reference.</p>
  
  <pre><code>    byte[] data = new byte[128];
  
      Block b = new Block();
  </code></pre>
  
  <p>I want to store reference b in last 2 (or 4) bytes of <strong>"data"</strong> array. </p>
  
  <p>Kindly Note: I dont want to serialize the object and store in byte array. I need to store a pointer( reference) referencing to a new block.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>My Block class is as follows</p>
  
  <pre><code>    public class Block {
          byte[] data ;
  
          public Block(){
              data = new byte[128];
          }
  }
  </code></pre>
  
  <p>Basically the data array will use 126 byte to store a String and last two( or 4) bytes to store reference to another block. Its kind of Link List.</p>
  
  <p>I could have done it using a different definition of Block class [By including reference to Block in class itself].. But problem statement states the constraint that only last 2 bytes should be used as a reference to another block. from other post I came to know that in jvm(32-bit) a reference is of size 4 bytes. Hence I think it can be only done using last 4 bytes</p>
  
  <p><strong>Snippet from problem statement</strong></p>
  
  <blockquote>
    <p>the last 2 bytes of the block is used to point to the next block . 
    Suppose if the file is of 8 block size, then the last 2 bytes of 4th
    block will point to 5th block and last 2 bytes of 5th block points to
    6th block and so on.</p>
  </blockquote>