aspose file tools
The moose likes Beginning Java and the fly likes class.forName() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "class.forName()" Watch "class.forName()" New topic
Author

class.forName()

Steven Zeng
Ranch Hand

Joined: Jan 15, 2002
Posts: 41
here is a piece of smaple code:

if i change the line "Class.forName("java.io.File")" to "Class.forName("File")" then the result of running should be "not exist" while remain the original code, it doesn't throw the exception.So i want know why and i hava set the enviroment variable classpath to the position of the installation of jdk in my computer.
In the doc of jdk1.3 I found that the method forName of "Class" class in java.util has a another overloading version with a argument ClassLoader.But i can't understand that how can i create a ClassLoader and make it works.Of course I know that ClassLoader is a abstract class,but if I want make my ClassLoader extends from it works, which methods should i implement.
Thanks in advance!
[ edited to preserve formatting using the [code] and [/code] UBB tags and to remove tabs -ds ]
[ July 22, 2002: Message edited by: Dirk Schreckmann ]

SCJP2
Wilfried LAURENT
Ranch Hand

Joined: Jul 13, 2001
Posts: 269
Can you be more explicit?
What do you expect? What to you want to know?
Do you want to create your own ClassLoader so that Class.forName("File") does not throw an exception?
W.
Steven Zeng
Ranch Hand

Joined: Jan 15, 2002
Posts: 41
Yes, just like you said.
Steven Zeng
Ranch Hand

Joined: Jan 15, 2002
Posts: 41
Maybe I didn't explain my question clearly.In fact I want know the following:
1 how to use the method of class.forName() that it works in findng a existing class without throwing the exception.
2 how to use the classloader
3 Moreover, how can i know the sequence that the classloader load in the classes.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

From the API:
Given the fully qualified name for a class or interface
ie it needs to be the complete package and class name. Therefore 'File' won't work, but 'java.io.File' will.
The basic version of Class.for name is equivelent to Class.forName("Foo", true, this.getClass().getClassLoader()), so that usually the default ClassLoader is used, and this is usually enough.
The ordering is locate, load, and link the class or interface. The extra info is that a Class will only be loaded once by a specific ClassLoader and it will only be initialised once. Also, it is possible to create a ClassLoader heirarchy which muddles things, but usually it isn't a problem.
Dave
Steven Zeng
Ranch Hand

Joined: Jan 15, 2002
Posts: 41
Thank you ,David.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: class.forName()
 
Similar Threads
passed with 91%
Completed with 91%
91%
Passed part-I with 91%
passed with 91%, a good start of a long journey