Stephan van Hulst wrote:Hi Christoffer, welcome to CodeRanch!
No, packages and class paths are completely unrelated. Packages are name spaces where related classes are bundled together. Class paths just specify where to find a loose hierarchy of packages. The import statement tells the compiler that a class wants to use a class from a specific package, without using the package name all the time. Import has nothing to do with where the actual files are located.
So consider the classes B and com.foo.MyClass. Their respective source files are c:\...\myProject\B.java and c:\...\myProject\com\foo\MyClass.java.
If you remove the import statement from the B class, the compiler won't know that MyClass refers to com.foo.MyClass, because its in a different package. If you remove package com.foo from MyClass, then the compiler *will* know, because they are in the same package. It will also be able to find both class definitions, because the compiler looks for files on the class path, and in the current working directory.
Import statements and package names have to do with the logical grouping of classes. The class path is only related to finding source files.