When you close NetBeans (or some other program), the objects you have created are deleted by the garbage collector.
If you want to save them, you have to implement the Serializable interface , from the java.io package. If you just declare that your class implements the Serializable interface, it becomes serializable:
public class MyClass implements Serializable { ... ... } ... MyClass my_class_instance = new MyClass(); try { FileOutputStream out = new FileOutputStream("myfile.ext"); ObjectOutputStream objout = new ObjectOutputStream(out); objout.writeObject(my_class_instance); out.close(); objout.close(); } catch (Exception e){ e.printStackTrace(); }
what is serialVersionUID?
This is the “serial number”, and you can set it while implementing the interface Serializable:
private static final long serialVersionUIT = 2L;
If you don't set this, java will generate its own serial version when it serializes an object, and you don't have the guarantee that it will generate the same version during deserialization.
Helpful Links