wood burning stoves*
The moose likes Beginning Java and the fly likes Composition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Composition" Watch "Composition" New topic
Author

Composition

Benjoe Reyes
Ranch Hand

Joined: Apr 24, 2002
Posts: 109
i have an abstract class AbsCls.java and i compiled it:
javac AbsCls.java
so the class file is saved in the current working directory...
but when i extended it :
public class Derived1 extends AbsCls
and compiled as:
javac Derived1.java
the class file should be at the same directory as that of the AbsCls.class... however i get error: unknown class AbsCls...
this is not supposed to happen right? there is no need to declare package in both classes and to import AbsCls because its in the same package( current working directory)...
i think in jdk1.2 this is ok but i'm using 1.4 now and i got this error...
[ December 17, 2002: Message edited by: Benjoe Reyes ]
Roan Nicolas
Greenhorn

Joined: Nov 11, 2002
Posts: 23
I tried reproducing your problem and I was able to compile my classes. You may want to check for typo and if the .class file itself is present in the working directory. You could trying posting your exact code so we could compile it ourselves.
Hope that makes sense.


Owee<p>SCJP 1.4
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Check wether the "current directory" (".") is in your classpath.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Divya Venkatesh
Greenhorn

Joined: Nov 05, 2002
Posts: 28
Sometimes you may have to set your class path.
If you class path is not set right the JVM may not be able to locate the other files.
(Well this is the case if you have written both your classes in different files.)


Divya
Divya Venkatesh
Greenhorn

Joined: Nov 05, 2002
Posts: 28
your class path will have to be something like this:
set classpath=(the path to get to the java library files);(the path to get to the directory where you have placed all your files);
Eg:
set classpath=c:\jdk1.4.1\lib;c:\javafiles;
This might look a bit too juvenile,But it may help you.
Wilfried LAURENT
Ranch Hand

Joined: Jul 13, 2001
Posts: 269
Even if you do not feel the need, it is a good habit to explicitely declare classes in named packages. It does not cost a lot and I have seen so many errors due to the use of the anonymous package.
W.
Benjoe Reyes
Ranch Hand

Joined: Apr 24, 2002
Posts: 109
i got it... the classpath was cancelled out when i set the classpath to JavaRanchCommon because i'm also doing the cattle drive exercises
i think i'll do what Divya Venkatesh said... set classpath for both however i put my files in different folders...
is it better if i take out the set classpath to the JavaRanchCommon and set it as needed???
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Whatever you prefer is what's better. If you think life is a bit easier to just have everything that is frequently used in your CLASSPATH setting, then do that. If such a configuration makes you feel sloppy and inefficient, then just specify class locations as they are needed.
I've included the JavaRanchCommon package and other frequently used packages (such as junit.jar and j2ee.jar) in my system's CLASSPATH setting as I prefer to be a bit lazy about not wanting to frequently adjust the CLASSPATH.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Benjoe Reyes
Ranch Hand

Joined: Apr 24, 2002
Posts: 109
Originally posted by Ilja Preuss:
Check wether the "current directory" (".") is in your classpath.

what does this one means???
set classpath = "."%classpath% ???
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
set CLASSPATH=.;%CLASSPATH% means prefix the original value of CLASSPATH with a dot and a semicolon and assign the result to CLASSPATH.
Suppose you have echo %CLASSPATH% printing C:\javaranch\lib\JavaRanchCommon.zip
Then after doing set CLASSPATH=.;%CLASSPATH%
echo %CLASSPATH% will print
.;C:\javaranch\lib\JavaRanchCommon.zip
That means two places will be searched: The first will be your current working directory (the one you cd into) represented by the dot and the second will be the JavaRanchCommon.zip file.
-Barry


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Benjoe Reyes
Ranch Hand

Joined: Apr 24, 2002
Posts: 109
so set CLASSPATH=C:\javaranch\lib\JavaRanchCommon.zip;.;%CLASSPATH% will do the trick...
because setting them up separately will cancell the previous one, right???
thanks Barry...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Composition