File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Class.forName(thisclass) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Class.forName(thisclass)" Watch "Class.forName(thisclass)" New topic


Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Can anyone gives me explanation about forName()?
When is forName() used for?
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner!

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
It is a static member of the 'Class' class. Forname() gives you a reference to the 'Class'class. It takes a string containing the name of the class you want a reference for loads the class.

So much trouble in the world -- Bob Marley
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Originally posted by monang:
Can anyone gives me explanation about forName()?
When is forName() used for?

Class.forName() is used to reference classes you don't want to have a compile time dependency to - for example because you don't know which actual class to use before runtime.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link:
subject: Class.forName(thisclass)
It's not a secret anymore!