This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "classpath" Watch "classpath" New topic
Author

classpath

Vierda Mila
Ranch Hand

Joined: Feb 25, 2008
Posts: 61
hi all,

I found difficulties when I learn about classpath, it's really confusing. please find below example from my self code.



My directory structure as per below :


After several attempts, I have compiled and running above code and it was running well, here is the code :
compile Animal.java


compile Horse.java


running Horse.class


My question is why I have to specify the Animal class when I compiled and run the Horse? why I can't do it like this--> C:\Documents and Settings\Mila\Desktop\project> java -cp .\com\path;. Horse (no Animal added, only the classpath for animal??)

So confusing, really appreciate for your reply.


SCJP 5
Swapnil Sonawane
Ranch Hand

Joined: Jan 02, 2008
Posts: 190
Because your Horse class extends your Animal class. It has its own class file. Am I clear?


Swapnil S. Sonawane<br /> <br />B.Tech (Expected May 2009)<br />Computer Science, NIT Durgapur, India<br />SCJA 1.0
Vierda Mila
Ranch Hand

Joined: Feb 25, 2008
Posts: 61
Hi Swapnil,

thank you for your reply, but I'm still not clear about this. regarding this thread, it not necessary to mention the parentclass when using the classpath, or am I wrong or missing something??
Ravikanth kolli
Ranch Hand

Joined: Feb 10, 2008
Posts: 179

the reason why you need to specify the base class in the path to run the sub class is because both of them are in different packages.
As in the example above
Animal class is in the package com.path while the Horse class is in the default package.

If both the classes are declared in the same package, then we need not add the base class in the path.


-kolli
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

This question isn't really about the SCJP exam, so I am moving it to the Java in General (Beginner) forum.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Joe Fischer
Greenhorn

Joined: May 02, 2008
Posts: 25
Does not mean that you will not see something like this on the certification exam. Things like this was on the Java 6 exam, at least.


SCJP-SE6.0
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: classpath