Results 1 to 2 of 2
- 11-02-2012, 10:26 PM #1
Senior Member
- Join Date
- Jul 2012
- Posts
- 166
- Rep Power
- 1
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.
Thanks
- 11-03-2012, 12:08 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
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.Last edited by pbrockway2; 11-03-2012 at 12:11 AM. Reason: typos
Similar Threads
-
Using a loop to prevent a program from closing? Help greatly appreciated :)
By RarkMowe in forum New To JavaReplies: 5Last Post: 10-24-2012, 07:17 PM -
closing a program
By newbie123 in forum AWT / SwingReplies: 13Last Post: 01-12-2012, 10:20 PM -
Having a problem with a program telling me that variables are not being used
By Deafsilver in forum New To JavaReplies: 14Last Post: 09-07-2011, 01:16 AM -
closing JFrame without terminating program
By chirag123 in forum AWT / SwingReplies: 5Last Post: 04-25-2011, 01:10 PM -
Trouble with For loop and variables in a program
By dablyz in forum New To JavaReplies: 12Last Post: 05-06-2008, 04:25 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks