This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class.forName

 
tribhuwan soni
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any one can tell me about Class.forName();
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should ask in the Java In General(Beginner) forum. This forum is about Servlets. Thank you.

(A moderator will probably move this thread for you)
 
Bill Cruise
Ranch Hand
Posts: 148
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you give this method a String representing a fully qualified Class name ("java.lang.Thread"), it returns the Class descriptor for the specified class. Note that this is not the same as returning an object of the specified type. Also note that this method can throw a ClassNotFoundException if you give it a bad argument.

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html#forName(java.lang.String)
 
Kaydell Leavitt
Ranch Hand
Posts: 689
Eclipse IDE Firefox Browser Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class.forName() is a method of the class, Class that takes a String which is the name of a class and returns an object of type Class. This is usually used to dynamically instantiate an object as in the following example.

This kind of advanced instantiation in place of using the new operator can be used when the class to be instantiated is not known at compile-time.

Like the previous poster said, you have to be careful to use the full name of a class and note that the throws declaration says that several Exceptions can be thrown.


[ June 19, 2007: Message edited by: Kaydell Leavitt ]
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Kaydell,

Good explanation. Good quotes as well..
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class.forName() is a method of the class, Class that takes a String which is the name of a class and returns an object of type Class.


This may look like doubletalk from a bad comedy about scientific babble, but it's right on the money. If you can parse out the proper use of the word "class" in every instance, give yourself a treat and take the rest of the day off.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This may look like doubletalk from a bad comedy about scientific babble, but it's right on the money. If you can parse out the proper use of the word "class" in every instance, give yourself a treat and take the rest of the day off.


Well Said Stan James Thats indeed true! Need to be a bit patient and understanding while reading through.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
forName() is a static method, also known as a "class method". We could have gotten "class" in the sentence one more time.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic