Retain Variables After Closing Program
I am new to Java and only creating pretty simple programs.
I have a problem though, the program I am creating will have variables created and values set to them. I want these variables to still exist and have these values after I close the program (so that it could be used another day), how can I (easily - I am a beginner) do this?
I am not too bothered if it is a pretty crude way of doing it, I just need it to be pretty easy and to work.
Re: Retain Variables After Closing Program
My intention isn't to mock you with the quote. But, it seems to me, we are sometimes in a hurry. And I know for a certain, sure, fact that there is nothing in this universe that is "just": morally or intellectually.
I just need it to...
You are talking about "persistence". The link gives a good introductory survey of what's involved. It talks about storing the value on a hard drive, but from the programmer's point of view we might be several steps removed from actually writing of things to a hard drive. For instance remembering the "high score" in a game might be done using some resource on the internet (a url which, when hit, records the player's name and score in a database; that way it can be read by others).
The most simple straight forward way of implementing persistence would be to write the value to a file on the computer's disk and read it again when the program starts (or whenever you want the value). Oracle's Tutorial deals with writing values to and reading them from a "stream" (which may be something persistent like a file) in the I/O Streams section. Look at the examples given there and see if they have any value for what you are trying to do.