This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Object Creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Object Creation " Watch "Object Creation " New topic

Object Creation

siva prakash
Ranch Hand

Joined: Aug 24, 2004
Posts: 80
Hi All,

i am going thru specification of java, and i found we can also create an instance of class using Class.forName(class_name).newInstance()

what advantage we can get using this approach instead of normal approach.

pls clarify me

With regards,
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
with this way, you don't have to know the class name at compile time. see also the reflection tutorial for more information.
William A White
Ranch Hand

Joined: Jul 01, 2004
Posts: 35
If you don't know what kind of object you want to create, this code lets you decide at run time.

You'd usually make use of it in conjunction with reflection, or some kind of factory that made different objects.
I agree. Here's the link:
subject: Object Creation
jQuery in Action, 3rd edition