This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes about static final Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "about static final" Watch "about static final" New topic
Author

about static final

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
Hi, I want to define some static final variables so that they will be loaded at first time when the class is up.

Like this:
static final ImageIcon icon = new ImageIcon("d.gif");
static final Vector vec = new Vector();

Question 1.
How and where can I add the icon into vec so that the data will be added into vector at class load first time ?
vec.add(icon); // could be loaded up at first time.

Question 2:
When the static final could be loaded up ? for example

so,
VecA will be created before main method or after ?
VecB will be created before methodCall() or after ?

In my understanding, both VecA and VecB should be created before A's main method.

Am I right ?

Thanks
Dun Dagda
Ranch Hand

Joined: Oct 12, 2004
Posts: 54
Would enclosing the variables you want to initialise at class load time in a static initializer block help?
static {
// list of things you want to do
}


SCJP 1.4<br />SCWCD (in progress)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about static final
 
Similar Threads
Creating a JAR file: File finding problem
loaded vs instantiated
when the block code is execute?
method call
Just Another Resource problem