Difference between C++ and Java compilation process

Possible Duplicate:
Why does C++ compilation take so long?

Hi,

I searched in google for the differences between C++ and Java compilation process, but C++ and Java language features and their differences are returned.

I am proficient in Java, but not in C++. But I fixed few bugs in C++. From my experience, I noticed that C++ always took more time to build compared to Java for minor changes.

Regards Bala


There are a few high-level differences that come to my mind. Some of those are generalizations and should be prefixed with "Often ..." or "Some compilers ...", but for the sake of readability I'll leave that out.

  • C/C++ compilation doesn't read any information from binary files, but reads method/type definitions only from header files that need to be parsed in full (exception: precompiled headers)
  • C/C++ compilation includes a pre-processor step that can do a wide array of text-replacement (which makes header pre-compilation harder to do)
  • The C++ syntax is a lot more complex than the Java syntax
  • The C++ type system is a lot more complex than the Java type system
  • C++ compilation usually produces native assembler code, which is a lot more complex to produce than the relatively simple byte code
  • C++ compilers need to do optimizations because there isn't any other thing that will do them. The Java compiler pretty much does a simple 1:1 translation of Java source code to Java byte code, no optimizations are done at that step (that's left for the JVM to do).
  • C++ has a template language that's Turing complete! (so strictly speaking C++ code needs to be run to produce executable code and a C++ compiler would need to solve the halting problem to tell you if arbitrary C++ code is compilable).

  • Java compiles code into bytecode, which is interpreted by the Java VM. C++ must compile into object code, then to machine language. Because of this, it's possible for Java to compile only a single class for minor changes, while C++ object files must be re-linked with other object files to machine code executable (or DLLs). This may make the process take a bit longer.


    I am not sure why you expect the compilation speed of Java and C++ to be comparable since they are different languages with completely different design gaols and implementations.

    That said a few specific differences to keep in mind are:

  • Java is compiled to byte code and not right down machine code. Compiling to this abstract virtual machine is simpler.
  • C++ compilation involves not only compilation but also linking. So it is typically a multi step process.
  • Java performs some late binding that is the association of a call to a function and the actual code to run is done at runtime. So a small change in one area need not trigger a compile of the whole program. In C++ this association needs to be done at compile time this is called early binding.
  • 链接地址: http://www.djcxy.com/p/14962.html

    上一篇: 为什么C#编译比C ++快得多?

    下一篇: C ++和Java编译过程之间的区别