| Author |
Class.forName()
|
Suresh Appagundi
Ranch Hand
Joined: Sep 22, 2003
Posts: 44
|
|
What makes the difference between getting the instance of the Particular class using Class.forName() {what is dynamic loading? how it useful?} and new keyword? thanks in advance Suresh
|
 |
Amit KumarS
Ranch Hand
Joined: Oct 10, 2003
Posts: 100
|
|
hiiiii.... as far as Class.forName() is concerned it is used to load a class at runtime. i.e. at the time of compilation we don't know which class should be loaded in memory but through programming we decide which class is to be loaded then we say Class.forName("Foo"); this will load Foo into memory when this line is reached during runtime. now if you want to make an instance of this at that time then you can call now this will return an object of Class "Object" and you can typecast it to your class and then use it.. but new is used to create an object of the class when that class is already loaded in the memory. we use new for those classes which we have added in bytecode using import statement. i hope i have answered your query.. if any doubt please revert back Thanks Amit
|
****************************<br />In 24 hrs Earth rotates once on its Axis.
|
 |
Pradeep bhatt
Ranch Hand
Joined: Feb 27, 2002
Posts: 8876
|
|
|
Some of the examples of dynamic classloading are JDBC drivers, Servlet instance, EJB instances etc.
|
Groovy
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
|
Moving this to the intermediate format...
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
Jacquie Barker
author
Ranch Hand
Joined: Dec 20, 2000
Posts: 201
|
|
|
A class's byte code is loaded by the Java Virtual Machine at run time the first time an instance of that object is created using the "new" operator; but, if you want to load a class WITHOUT having to create an instance of it, Class.forName() does the trick!
|
Author of Beginning Java Objects, Beginning C# Objects, and Taming the Technology Tidal Wave
|
 |
 |
|
|
subject: Class.forName()
|
|
|