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
posted
0
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
posted
0
Yes, just like you said.
Steven Zeng
Ranch Hand
Joined: Jan 15, 2002
Posts: 41
posted
0
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.
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