Hi All, Given below are the steps followed: 1) I have one class that is stored in a directory structure given below: D:\WebSphere\AppServer\installedApps\globalrfx.ear\global.war\WEB-INF\classes\com\sharedapps\globalrfx\beans\service\modify\ChangeDB.class 2) I set class path like this: D:\WebSphere\AppServer\installedApps\globalrfx.ear\global.war\WEB-INF\classes\; 3) And I put my first statement in that class as given below package com.sharedapps.globalrfx.beans.service.modify; It compiled fine 4) I have got another class up in the hierarchy as given below: D:\WebSphere\AppServer\installedApps\globalrfx.ear\global.war\WEB-INF\classes\com\sharedapps\globalrfx\beans\common\Contact.class
6) This also compiled fine 7) And What I did is I append classpath as given below D:\WebSphere\AppServer\installedApps\globalrfx.ear\global.war\WEB-INF\classes\com\sharedapps\globalrfx\beans\service\modify\; 8) And I removed package declaration from top of class ChangeDB,It again compiled fine.(removed package com.sharedapps.globalrfx.beans.service.modify; ) 9) But When I try instantiate ChangeDB in Contact class and I imported all classes from modify where class ChangeDB LOCATED. import com.sharedapps.globalrfx.beans.service.modify.*; I got error as given below Contact.java:24: cannot access com.sharedapps.globalrfx.beans.service.modify.ChangeRemoveATMDB bad class file: J:\WebSphere\AppServer\installedApps\globalrfx.ear\global.war\WEB-INF\classes\com\sharedapps\globalrfx\beans\service\modify\ChangeDB.class class file contains wrong class: ChangeDB Please remove or make sure it appears in the correct subdirectory of the classpath. ChangeRemoveATMDB objDB = new ChangeRemoveATMDB(); Even though I imported the class, why I am getting above said error? I set the classpath till where the class is situated. Now JVM can see where the class is located and that can be accessed from that package also. But When I added the package statement again in ChangeDB.class, It compiled fine!!! I was able to access the same class from the class Contact in other folder D:\WebSphere\AppServer\installedApps\globalrfx.ear\global.war\WEB-INF\classes\com\sharedapps\globalrfx\beans\common\ How does JVM locate the classes and how does it load the class? Why package declaration is necessary even if I set classpath till that point where class is resided? Can anybody explain about the relationship between classpath, package declaration et all?