jQuery in Action, 3rd edition
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 Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "about static final" Watch "about static final" New topic

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

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 ?

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
It's not a secret anymore!