I hope this isn't a total "newbie" question. I've searched everywhere (including here) and can't find a decent answer. I feel better that the Deitel Java book says that a discussion of Class.forName is "outside the scope of this book".
Here goes:
What does Class.forName(String) do?
O.K. I "know" the "answer" to that. It "loads" the class of name String and returns a Class object representing it. Fine. But what good is that? If I don't then proceed to call theClassObject.newInstance(), I won't have an actual instance will I? So what possible good has occurred? Have I got some bad blinders saying that "you must have a reference to an instance" for an object to be any use? (Of course, statics are another matter, but that's beside the point... or is it???)
As a corollary, why do you have to do a Class.forName("jdbc.driver.of.your.choice" in every JDBC app? What good does it do? We're not actually creating an instance of the driver, we're just "loading" it. What??? We're not even storing a reference to the Class object that got created. Doesn't that mean it just goes immediately to the garbage collection queue?
I'm totally befuddled.
Thanks in advance! This has been frustrating me for a while!
-DG
Here goes:
What does Class.forName(String) do?
O.K. I "know" the "answer" to that. It "loads" the class of name String and returns a Class object representing it. Fine. But what good is that? If I don't then proceed to call theClassObject.newInstance(), I won't have an actual instance will I? So what possible good has occurred? Have I got some bad blinders saying that "you must have a reference to an instance" for an object to be any use? (Of course, statics are another matter, but that's beside the point... or is it???)
As a corollary, why do you have to do a Class.forName("jdbc.driver.of.your.choice" in every JDBC app? What good does it do? We're not actually creating an instance of the driver, we're just "loading" it. What??? We're not even storing a reference to the Class object that got created. Doesn't that mean it just goes immediately to the garbage collection queue?
I'm totally befuddled.
Thanks in advance! This has been frustrating me for a while!
-DG