Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Object Creation " Watch "Object Creation " New topic
Author

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,
siva
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: http://aspose.com/file-tools
 
subject: Object Creation
 
Similar Threads
Running java program from another java program
My interview questions
executeUpdate() returning unexpected results
Batch Delete Problem
Best way to search for an element in integer array