try{
// obtain cabin 100
Context jndiContext = getInitialContext();
CabinHome home = (CabinHome)jndiContext.lookup("CabinHome");
CabinPK pk_1 = new CabinPK();
pk_1.id = 100;
Cabin cabin_1 = home.findByPrimaryKey(pk_1);
// serialize the Handle for cabin 100 to a file.
Handle handle = cabin_1.getHandle();
FileOutputStream fos = new FileOutputStream("handle100.ser");
ObjectOutputStream outStream = new ObjectOutputStream(fos);
outStream.writeObject(handle);
outStream.flush();
fos.close();
handle = null;
// deserialize the Handle for cabin 100
FileInputStream fis = new FileInputStream("handle100.ser");
ObjectInputStream inStream = new ObjectInputStream(fis);
handle = (Handle)inStream.readObject();
fis.close();
// re-obtain a remote refernce to cabin 100 and read its name
Cabin cabin_2 = (Cabin)handle.getEJBObject();
System.out.println(cabin_2.getName());
}catch(java.rmi.RemoteException re){re.printStackTrace();}
catch(javax.naming.NamingException ne)
{ne.printStackTrace();}
catch(Throwable t){t.printStackTrace();}