import java.nio.*;
class SharedBuffer {
public static void main(String[] args) {
ByteBuffer bb1 = ByteBuffer.allocate(10);
ByteBuffer bb2 = bb1.duplicate();
for (int i=0; i<bb1.capacity(); i++){
bb1.put((byte)i);
}
System.out.println(bb1.position()); System.out.println(bb2.position()); bb2.put((byte)3); System.out.println(bb1.get(0)); System.out.println(bb1.position()); ByteBuffer bb3 = bb2.asReadOnlyBuffer();
System.out.println(bb3.position()); bb3.rewind(); System.out.println(bb3.get()); bb3.put((byte)4); }
}