> Question
>
> If I have two static member variable in a class and a
> static code block to initialize the variables. I want
> to know exactly when the static code block will be run.

All static blocks are run as the class is loaded in the order listed in the
source file, well before anyone else can call one of your static methods.

> Ok the quick answer is when the JVM loads the class into
> memory, but what I want to know is when does the JVM
> load the class into memory.

This will vary from implementation to implementation depending on how
aggressive a loader it has.

> is it only the first time a static method on the class
> is called. ( e.g. MyClass.callStaticMethod() ) or can you
> use Class.forname("MyClass");

See above. Static blocks run when the class loads. If Class.forname causes
the class to be loaded, the static block will run then. If the class has
already been loaded, Class.forname will just return the Class class (and the
static block will not be re-run).

> I want the static block of code to have already run
> before any of the static methods are called, how can I
> force this.

You're ok, it's done for you.

Jeff

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to