aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static Initializer / methoed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Static Initializer / methoed " Watch "Static Initializer / methoed " New topic
Author

Static Initializer / methoed

Frank Jacobsen
Ranch Hand

Joined: May 17, 2002
Posts: 353
Example:

Can someone tell me if i can be 100 % that the first time i call this class from a other java class, using Prefill.getPrefilled that the static initializer block is done once and only once, before continueing whit the code in the getPrefilled methoed !
Edited by Corey McGlone: Added Code Tags
[ April 07, 2003: Message edited by: Corey McGlone ]
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Originally posted by Frank Jacobsen:
Can someone tell me if i can be 100 % that the first time i call this class from a other java class, using Prefill.getPrefilled that the static initializer block is done once and only once, before continueing whit the code in the getPrefilled methoed !

The static initializer is called once and only once when the class is loaded and before the body of any static method is processed and before any instance is constructed. To prove it to yourself, just write a short program that prints a message from the static initializer and also prints a message from the static method that you are interested in. If you would like to see some sample programs that demonstrate the behavior of initializers, the please see "Chapter 8: initializers", at the following URL.
http://www.danchisholm.net/dec04/guide/mughal/index.html
A note to those studying for the exam: although Mughal has included this topic in his book and although I have included it in my mock exam, it is really a little beyond the scope of the exam.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Static Initializer / methoed