|
Help | Solution | API Docs | Expected Output
Help is available for each task, or you can go straight to the solution source code.
Working from the
FileClassLoader.java skeleton, have extends ClassLoader
Find out if the requested class to
If the class isn't loaded, you'll need to convert the class name to a file name and load the data from the class. The filename conversion
is already done for you and the loading of the data is already done. The only thing you need to do is connect everything. Just call the
private byte data[] = loadClassData(filename);
Once you have the class data in a byte array, convert the byte array into a
Be sure to use the four argument variety of c = defineClass (name, data, 0, data.length); if (c == null) throw new ClassNotFoundException (name); Resolve the class definition if appropriate. if (resolve) resolveClass (c); Return the class object just created. return c;
In the
CLTester.java skeleton, create an instance of the FileClassLoader loader = new FileClassLoader(args[0]);
Next, have the test program load a class whose name will be provided from the command line, also, as Class c = loader.loadClass (args[1]);
After loading the class, create an instance of it. You can use reflection and the Object tester = c.newInstance(); The Tester.java file contains a test class to use for the class loader. The only thing it does is print messages when the class file is loaded and instances are created. Save and compile the file. Shift-click on the Tester.java link to save. Then compile with the following command: javac Tester.javaTask 11
If you have a " Something like the following will do. Depending upon your platform, the specific command may vary. mkdir test move Tester.class test
Run the java CLTester test Tester Copyright © 1998 MageLang Institute. All Rights Reserved. | |||||||||||||||||
|
| ||||||||||||