Here you can find the source of deepCopy(Object oldObj)
static public Object deepCopy(Object oldObj) throws Exception
//package com.java2s; import java.io.*; public class Main { static public Object deepCopy(Object oldObj) throws Exception { ObjectOutputStream oos = null; ObjectInputStream ois = null; try {/*from w ww . j av a2s . c om*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bos); // serialize and pass the object oos.writeObject(oldObj); oos.flush(); ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray()); ois = new ObjectInputStream(bin); // return the new object return ois.readObject(); } catch (Exception e) { System.out.println("Exception in ObjectCloner = " + e); throw (e); } finally { oos.close(); ois.close(); } } }