I'm familiar with the process of serializing an object and writing it to a file, but is there a way tp dp so after the user terminates the console?
Yes, you could add SIGTERM handler. In java you can do it by using Runtime.addShutdownHook()