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.

Recommended Answers

By using a Static Initialization Block.
Just check this [URL="http://docs.oracle.com/javase/tutorial/java/javaOO/initial.html"]tutorial[/URL]

Jump to Post

All 2 Replies

By using a Static Initialization Block.
Just check this tutorial

By using a Static Initialization Block.
Just check this tutorial

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.