954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to initialize a static class variable only for one time

I have a static class, with all methods and fields static. My methods in that class are going to use a static field declared in that class.

I want that static variable(which can not be made final) to be initialized with a value taken from a database when that static class is accessed for the first time. And this variable should not be initialized later on in any case.

warlord902
Junior Poster
120 posts since Dec 2010
Reputation Points: 19
Solved Threads: 0
 

By using a Static Initialization Block.
Just check this tutorial

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 
By using a Static Initialization Block. Just check this tutorial

Oh yeah....how did I forgot this, its so stupid of me...Thanks buddy :)

warlord902
Junior Poster
120 posts since Dec 2010
Reputation Points: 19
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: