public void writeExternal(ObjectOutput out) throws IOException {
  String s=toString();
  if (s.length() <= 65535) {
    out.writeUTF(s);
  }
 else {
    out.writeByte(0);
    out.writeByte(0);
    out.writeInt(s.length());
    out.write(s.getBytes());
  }
}

public void writeExternal ( ObjectOutput out ) throws IOException { String s = toString ( ) ; if ( s . length ( ) <= 65535 ) { out . writeUTF ( s ) ; } else { out . writeByte ( 0 ) ; out . writeByte ( 0 ) ; out . writeInt ( s . length ( ) ) ; out . write ( s . getBytes ( ) ) ; } }
the object implements the writeexternal method to save its contents by calling the methods of dataoutput for its primitive values or calling the writeobject method of objectoutput for objects , strings and arrays .
