Serializing/Deserializing objects is very useful if you want to use a Java object in the future. The following code shows how to deserialize a serialized object.

 try {

    // Deserialize from a file
    File file = new File("filename.ser");
    ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));

    // Deserialize the object
    javax.swing.JButton button = (javax.swing.JButton) in.readObject();
    in.close();
    
} catch (ClassNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}