File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Classpath problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Classpath problem" Watch "Classpath problem" New topic
Author

Classpath problem

Mubeen Shaik
Ranch Hand

Joined: Jan 26, 2004
Posts: 67
Hi All,
I have created a class - ClassA (This class is not a main Class) in a directory C:\JAVA\Examples\Chapter10.
Now i have created one more class TestClass (This is main class - Please correct me if my terminology is wrong). This "TestClass" is invoking the method of ClassA.
I created a object of type ClassA and refered to a variable Var1.
ClassA Var1 = new ClassA();
When i compiled this i got an error ClassA Not found.Then i set my classpath to
.;C:\JAVA\Examples\Chapter10. Then it compiled normally.
I want to know the importance of Classpath and why it worked when i changed with "." and Directory name? Please explain me more about the Classpath.
Thanks in advance,
Mubeen Shaik.


Sun Certified Java Programmer
David Peterson
author
Ranch Hand

Joined: Oct 14, 2001
Posts: 154
When you compile your source code (which normally has a ".java" extension), the result is ".class" file which contains a compiled "bytecode" version.
Classes are compiled one by one. If the class you are developing depends on another class (e.g. TestClass refers to ClassA), the compiler must be able to access the relevant ".class" file for that other class.
The classpath tells the Java compiler where it can find these precompiled Java classes.
The ".", at the start of the classpath you mentioned, means: "search the current directory" first, then if no "ClassA.class" file can be found, try the next directory in the classpath ("C:\JAVA\Examples\Chapter10"). If it still can't find the class file, you'll get a "Class not found" error message.
Hope this helps.
Mubeen Shaik
Ranch Hand

Joined: Jan 26, 2004
Posts: 67
Originally posted by David Peterson:
When you compile your source code (which normally has a ".java" extension), the result is ".class" file which contains a compiled "bytecode" version.
Classes are compiled one by one. If the class you are developing depends on another class (e.g. TestClass refers to ClassA), the compiler must be able to access the relevant ".class" file for that other class.
The classpath tells the Java compiler where it can find these precompiled Java classes.
The ".", at the start of the classpath you mentioned, means: "search the current directory" first, then if no "ClassA.class" file can be found, try the next directory in the classpath ("C:\JAVA\Examples\Chapter10"). If it still can't find the class file, you'll get a "Class not found" error message.
Hope this helps.

David,
Thanks for that detailed explanation.
Mubeen.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Classpath problem
 
Similar Threads
classpath
Package
package
Problem running swt in command line
Working with Packages