aspose file tools*
The moose likes Beginning Java and the fly likes Class.forName Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Class.forName" Watch "Class.forName" New topic
Author

Class.forName

tribhuwan soni
Greenhorn

Joined: May 23, 2007
Posts: 6
any one can tell me about Class.forName();
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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)


[My Blog]
All roads lead to JavaRanch
Bill Cruise
Ranch Hand

Joined: Jun 01, 2007
Posts: 148
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

Joined: Nov 18, 2006
Posts: 689

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

Joined: Apr 20, 2006
Posts: 3344

Hello Kaydell,

Good explanation. Good quotes as well..


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344


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

Joined: Jan 29, 2003
Posts: 8791
forName() is a static method, also known as a "class method". We could have gotten "class" in the sentence one more time.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class.forName