Java: Best approach to have a long list of variables needed all the time without consuming memory?

Posted by evilReiko on Stack Overflow See other posts from Stack Overflow or by evilReiko
Published on 2011-02-04T06:37:45Z Indexed on 2011/02/04 7:26 UTC
Read the original article Hit count: 125

Filed under:
|

I wrote an abstract class to contain all rules of the application because I need them almost everywhere in my application. So most of what it contains is static final variables, something like this:

public abstract class appRules
{
    public static final boolean IS_DEV = true;
    public static final String CLOCK_SHORT_TIME_FORMAT = "something";
    public static final String CLOCK_SHORT_DATE_FORMAT = "something else";
    public static final String CLOCK_FULL_FORMAT = "other thing";
    public static final int USERNAME_MIN = 5;
    public static final int USERNAME_MAX = 16;
    // etc.
}

The class is big and contains LOTS of such variables.

My Question:

  • Isn't setting static variables means these variables are floating in memory all the time?
  • Do you suggest insteading of having an abstract class, I have a instantiable class with non-static variables (just public final), so I instantiate the class and use the variables only when I need them.
  • Or is what am I doing is completely wrong approach and you suggest something else?

© Stack Overflow or respective owner

Related posts about java

Related posts about memory-management