The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

linking of classes

Posted by uday on May 16, 2001 at 3:44 AM

Hi tejinder,

"The classloader class dynamically links the classes." Doesn't it mean that it happens when you run the application, not when you compile it. When you compile a .java file which is using two other classes, the compiler will look for those classes to be in the classpath or so, and if they are not available fine, it should throw a compilation error saying so & so class file is not available. But whats happening hear is that the compiler is intelligent enough to find out the corresponding .java file & compiling it for its sake. Its great to have it, but would like to know how is it happening.

thanks
-uday

> hi
> java is a interpreted and compiled language.the compiled code is in the form of bytecodes which are interpreted by the interpreter and then executed.when you create a class with a main method which creates objects of two different classes ,the classloader class dynamically links these classes with your class containing the main method.by classes i mean the class objects i.e classname.class .when you change the source file i.e. .java but do not compile it ,the class file remains the original so there is no change.also changing the directory of the class file does not change the output as long as there is no change in it .but the classpath should be appropriately set so that the system can find the class file.
> hope this solves your problem .if not do write again
> tejinder
> > I am first year student at south bank university in london. i had an assignment to write a small propram that simulates softaware for creating key cards for key card locks. in writing this program i have writen three classes. two classes are used only to create objects while the third class is a class that has the main method and will use those two methods to instanciate the objects that are to be used. while testing the classes i heve realised that by compiling the class with the main method ather two clasess ser being compiled. how did i realise this. i made some changes to one of the class more precise i changed the value of the string variable called status from own to withdrawn and did not compile that class but compiled the class with the main method but wen run the class the variable status had the value withdrawn. all the classes wer in the same directory so i changed the variable status back to own and moved the source with extension java to ather directory and than compiled the class with the main method but this time the variable status was still withdrawn. does this mean that javac will check the date of the files if the class was resantky modified and if the source code has more resent date than the class file it will be compiled automatically.sory for my spelling mistakes.





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us