Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between C++ and Java compilation process [duplicate]

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

like image 200
Boolean Avatar asked Jan 19 '10 17:01

Boolean


People also ask

What is the difference between C compiler and Java compiler?

C is a compiled language that is it converts the code into machine language so that it could be understood by the machine or system. Java is an Interpreted language that is in Java, the code is first transformed into bytecode and that bytecode is then executed by the JVM (Java Virtual Machine).

How is compilation different from Java compilation?

The Java classes/bytecode are compiled to machine code and loaded into memory by the JVM when needed the first time. This is different from other languages like C/C++ where programs are to be compiled to machine code and linked to create an executable file before it can be executed.

What is the differences between C C++ and Java?

C++ supports features like operator overloading, Goto statements, structures, pointers, unions, etc. Java does not support features like operator overloading, Goto statements, structures, pointers, unions, etc. C ++ is only compiled and cannot be interpreted. Java can be both compiled and interpreted.

Why is compiling and executing a C++ program and compiling and running a Java program different?

C++ uses compiler only. C++ is compiled and run using the compiler which converts source code into machine code so, C++ is platform dependent. Java uses both compiler and interpreter. Java source code is converted into bytecode at compilation time.


2 Answers

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).
like image 192
Joachim Sauer Avatar answered Sep 22 '22 01:09

Joachim Sauer


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.

like image 26
Aaron Avatar answered Sep 23 '22 01:09

Aaron