|
|
Re: Importing classes again
|
Posted: Dec 1, 2005 10:53 PM
|
|
You must understand that Java uses files, but is not file-based.
With another class loader you would also be able to put all classes in one file.
If the JVM should find a class you specify, it must be in the classpath. The package name must be the same as the subdirectory the file is in, just exchange "\" with "." Example. classpath = c:\MyProgram\ Class1 lies in c:\MyProgram\package1\subPackage\Class1.class the package of Class1 MUST be "package1.subPackage"
If you compile the program, you must do it using "c:\MyProgram" as classpath.
You can of course add more directories or JAR files to the classpath.
for example: classpath = c:\MyPersonProgram;c:\MyFamilyProgram;c:\somwhereElse\MyFinishedProgram.jar It does not matter in which directory / JAR file your classes are stored (only if you have classes with the same classpath and name, the first one will be used). You can access all files in the path using package and class name.
One note to naming. 1. Class names should begin with a capital letter, but should also contain small letters ("MyClass"); 2. Packages and variables should have a lower case character at the beginning ("myPackage")
Only constants should be written in capital letters ("direction.LEFT", where direction can be a instance variable or a enumeration. If "direction" would be a class, it should be "Direction.LEFT"). Constants usually are defined by setting a class variable to final or using a enumeration.
|
|