Can anyone let me know about this?
As per JDBC guide by Sun
All Driver classes should be written with a static section (a static initializer) that creates an instance of the class and then registers it with the DriverManager class when it is loaded. Thus, a user would not normally call DriverManager.registerDriver directly; it should be called automatically by a Driver class when it is loaded
The String class is loaded and initialized. This means that memory for static variables is allocated and their values are initialized. Static initialzers are also executed. Similarly when you do
The Connection and DriverManager classes are loaded (if they aren't already loaded, that is) before the getConnection() method is even called.
However, we never use JDBC driver classes directly, so how are they loaded? By calling Class.forName()! This method will also load a class if it isn't already loaded. When the driver class is loaded, the static initializers in the class run. This is when the driver is registered with the DriverManager, as described above.
If you are interested in learning more, I suggest you look at the javadocs for Class, specifically the forName() method. you should also look at ClassLoader.
The String class is loaded and initialized. This means that memory for static variables is allocated and their values are initialized. Static initialzers are also executed.
what do you mean by that?
That was not a static variable?Am i right?
I think if its something like this, its initialized.Because we dont need to get new insatance of class A.We will reach it by A.str.However, i dont know when they are initilized?
[ July 16, 2005: Message edited by: sinasi susam ]
It looks like this:
I haven't compiled this, but it should work. Class.forName() causes the static block to 'fire' the first time, the static block creates an instance and registers it with the DriverManager. Subsequent calls to Class.forName() don't do anything.