//// urlloader.java// urlloader//// Created by Ryan MacArthur on 2/18/07.// Copyright (c) 2007 __MyCompanyName__. All rights reserved.//import java.net.*;import java.io.*;public class urlloader extends ClassLoader { public static void main (String args[]) throws Exception { boolean testobj; // Create an array of URLs // From directory name specified as args[0] URL urlList1[] = {new File(args[0]).toURL()}; URL urlList2[] = {new File(args[0]).toURL()}; URL urlList3[] = {new File(args[0]).toURL()}; // Create a URLClassLoader ClassLoader loaderPart1 = new URLClassLoader(urlList1); ClassLoader loaderPart2 = new URLClassLoader(urlList2); ClassLoader loaderPart2diff = new URLClassLoader(urlList3); // Load class from class loader // Use args[1] as class name Class TestClassOneA = loaderPart1.loadClass (args[1]); Class TestClassOneB = loaderPart1.loadClass (args[1]); Class TestClassTwoC = loaderPart2.loadClass (args[1]); Class TestClassTwoD = loaderPart2diff.loadClass (args[1]); // Create an instance of the class just loaded Object Part1OBJA = TestClassOneA.newInstance(); Object Part1OBJB = TestClassOneB.newInstance(); Object Part2OBJC = TestClassTwoC.newInstance(); Object Part2OBJD = TestClassTwoD.newInstance(); System.out.println("--------------HW2 Part 1---------------"); System.out.println("TestClass [" + TestClassOneA.hashCode() + "] loaded by loader URLClassLoader ["+ loaderPart1.hashCode()+"]"); System.out.println("TestClass [" + TestClassOneB.hashCode() + "] loaded by loader URLClassLoader ["+ loaderPart1.hashCode()+"]"); System.out.println("Object 1 [" + Part1OBJA.hashCode() + "] is an instance of class TestClass ["+ TestClassOneA.hashCode()+"]"); System.out.println("Object 2 [" + Part1OBJB.hashCode() + "] is an instance of class TestClass ["+ TestClassOneB.hashCode()+"]"); testobj = Part1OBJA.equals(Part1OBJB); if(!testobj) System.out.println("Objects are not equal"); else System.out.println("Objects are equal"); System.out.println("======================================="); System.out.println("TestClass [" + TestClassTwoC.hashCode() + "] loaded by loader URLClassLoader ["+ loaderPart2.hashCode()+"]"); System.out.println("TestClass [" + TestClassTwoD.hashCode() + "] loaded by loader URLClassLoader ["+ loaderPart2diff.hashCode()+"]"); System.out.println("Object 1 [" + Part2OBJC.hashCode() + "] is an instance of class TestClass ["+ TestClassTwoC.hashCode()+"]"); System.out.println("Object 2 [" + Part2OBJD.hashCode() + "] is an instance of class TestClass ["+ TestClassTwoD.hashCode()+"]"); testobj = Part2OBJD.equals(Part2OBJC); if(!testobj) System.out.println("Objects are not equal"); else System.out.println("Objects are equal"); }}