Search code examples
javaattributesdefaultfinal

Change class variables and save changes for future program runs?


For example, say I have:

public Class Foo {
    public final int X = 1;

    public getX() {
        return this.X;
    }
}

Is it possible to write something to change the value of X for future runs of the program? So if the value the user wanted to use for X changes, and all they have is a compiled .jar file, they could run said method and then the value of X in the compiled code would be forever changed.

I am developing software for a research lab, at which I work temporarily. What the lab techs will be interacting with is just a bunch of JFrames. They don't know how to change it in the code and then recompile, etc. So I am trying to find the best way to have a "Change Defaults" button which would open a window for them that they can edit the default values, click "Save," and then the new value is what is used until they change it again. How can I do this?


Solution

  • java.util.Preferences, designed for this purpose, but involves a little work