• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

Static constants

I've got a class that looks like this:

public final class C
{
     // M A T H   C O N S T A N T S
     
     public static final float TO_RADS = 0.017453292f ;
     public static final float TO_DEGS = 57.29577951f ;
     public static final float PI = 3.141592654f ;
     
     // etc ..
}

I was just wondering - will the VM store _all_ of the static members in memory as soon as just one of them has been used, or will it only store/load each one after that one has been used?

So, if I were to just use PI within my program, would the VM still load all of the other variables? (Seeing as I actually have a pretty large list)..

Thanks.
0
InteractiveMind
Asked:
InteractiveMind
  • 2
  • 2
1 Solution
 
objectsCommented:
they would all get loaded when the class is loaded (as they are class vartiables)
What is your concern?

btw, The Math class already has PI

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Math.html
0
 
InteractiveMindAuthor Commented:
> What is your concern?
Well, my list of variables is quite large as it is, and I will probably expand it at some stage... But some programs that use this class will only use 1 or 2 of these variables - so I was wondering about memory being wasted.
(Mind you, I suppose it's not significant on today's machines — but I was interested to know anyway :-)).

> btw, The Math class already has PI
Yer, but doesn't that class actually use some algorithm to calculate the value of PI on first use, or something?
Besides, I need it as a float, and it saves me casting.  :-)

Thanks.
0
 
objectsCommented:
> Yer, but doesn't that class actually use some algorithm to calculate the value of PI on first use, or something?

don't think so, think it uses 3.141592653589793
0
 
InteractiveMindAuthor Commented:
Hm. Ah well.. it saves me the explicit cast  :-)

Thank you
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now