Welcome to JavaRanch, Joyce!
I can answer your questions, but first, I'd like to point out our
Naming Policy. Please change your display name to include two names of at least two letters each. Thank you.
Now, on to answer your questions:
1). If you import java.lang.*, you can find the path in the classpath of the JVM. However, don't go looking for java.lang in the CLASSPATH environment variable; the JVM will have access to the java.xxx packages when it starts, regardless of what the designated classpath is.
(If you're interested, the source for the java packages can be found in the JAVA_ROOT/src.zip file, but that's not where the classes are loaded from).
2). Yes, you do have to build that directory. Any files that belong to that package should be placed in that directory.
3). A couple of problems here:
a). Your file name must match your class name. So if you defined a
it must be in the file:
{CLASSPATH}/com/myjava/tools/BaseClass.java
Likewise, the DerivedClass should be in the
{CLASSPATH}/com/myjava/tools/DerivedClass.java
The reason for this is:
When you try to compile a class, the javac compiler will attempt to resolve all external symbols. Since you have declared that DerivedClass extends BaseClass, the compiler attempts to locate BaseClass. It looks up BaseClass's package (com.myjava.tools) and locates that directory in the filesystem. Then it looks to see if there is a BaseClass.class file there. If not, it looks to see if there is a BaseClass.java there--it will then compile the BaseClass.java file, producing the BaseClass.class file. But the BaseClass files must be in that directory.
As you undoubtedly found out, it
is possible to compile a class in the wrong directory. (You compile BaseClass.java in c:\test instead of C:\test\com\myjava\tools\). The compiler won't complain about that, but when you try to either 1). Run that java program or 2). Compile another class that uses that program, you will receive an error.
So, in summary, your directory structure should look like:
C:\test\
C:\test\com\
C:\test\com\myjava\
C:\test\com\myjava\tools\
C:\test\com\myjava\tools\BaseClass.java
C:\test\com\myjava\tools\DerivedClass.java
and, after compilation, include:
C:\test\com\myjava\tools\BaseClass.class
C:\test\com\myjava\tools\DerivedClass.class
4). I'm not sure what you mean about even worse, but, unless you use the directory structure I described above, putting "C:\test" in the classpath will not solve the problem--although it would solve other problems you might encounter down the road.