Click to See Complete Forum and Search --> : C vs java compilation


drahul
12-30-2004, 10:53 AM
I got this basic question ??

When i compile a program containing references to external objects returns no error in C or C++ ., (ie compilation succeeds with the declaration part without the definition) . the definition is resolved only during Linking !

But the same case fails when i compile a java code. Its requires all the class files in the classpath during complilation.

How does it work in Java ?

Khalid Ali
12-30-2004, 03:28 PM
my guess will be that your Compiler(IDE?) knows about the files location hence links to them successfully, where as in Java the IDE or JVM does not know so requires that you set the path to those files...I hope thats what you asked....

ray326
12-30-2004, 05:06 PM
Two things are at play here. First, C is statically linked in a separate link process. The linker needs to know where the referenced code is so it can add it into the runnable module at that time. Second, your C definitions are done at the function level and are assumed valid by the compiler. Java imports on the other hand are done at the class level and the compiler examines the class to determine its methods (the analog of the C function). Java linkage is done at run time by the classloader.

The bottom line is that Java automates a lot more of the overall process getting you from source to executing program.

Great question, BTW!