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)..

LVL 25
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.  :-)

> 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
InteractiveMindAuthor Commented:
Hm. Ah well.. it saves me the explicit cast  :-)

Thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.