Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By pbrockway2

Thread: Retain Variables After Closing Program

  1. #1
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    241
    Rep Power
    3

    Default 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

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default Re: Retain Variables After Closing Program

    I just need it to...
    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.

    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 01:11 AM. Reason: typos
    DarrylBurke likes this.

Similar Threads

  1. Replies: 5
    Last Post: 10-24-2012, 08:17 PM
  2. closing a program
    By newbie123 in forum AWT / Swing
    Replies: 13
    Last Post: 01-12-2012, 11:20 PM
  3. Replies: 14
    Last Post: 09-07-2011, 02:16 AM
  4. closing JFrame without terminating program
    By chirag123 in forum AWT / Swing
    Replies: 5
    Last Post: 04-25-2011, 02:10 PM
  5. Trouble with For loop and variables in a program
    By dablyz in forum New To Java
    Replies: 12
    Last Post: 05-06-2008, 05:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •