Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

class.forname

 
A Babu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I wrote the connection class.in that i wrote class.forname()........


etc.

now my question is every time i am calling the above connection class ,
class.forname ()method will execute or only once it will execute.

and what the class.forname() returns.

cheers,
babu.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We get this question a lot, a pervious conversation is here.

Can find out what it returns by looking at the API
 
A Babu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
class.forname returns class object.ok.

i want clarification for class.forname executes as many times as i requested the class or not?

cheers,
babu.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the class has not been loaded, the first time Class.forName() is called it will cause the class to load. Loading the class also causes it to be registered wit the DriverManager.

If the Class is already loaded, it get returned from the ClassLoader cache and does not get loaded again. Therefore you can have as many calls to Class.forName() as you like and the overhead will be minimal.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic