javacompilationcompiler-theory

Compilation vs translation, "compiling" Java to bytecode?


My understanding is like this, definitions:

Translation - having code in some language, generating code in some other language.

Compilaton - translation to a machine code.

Machine code - direct instructions for CPU.

Now, from docs.oracle.com:

javac - Java programming language compiler

Compiler...? I think it is Java translator, because it is generating a code, that is not a machine code. Bytecode needs interpreter (JVM) to run, so it's definetely not a machine code.

From Wikipedia:

Java applications are typically compiled to bytecode

Similarly. According to definitions, I would say that Java is traslated to bytecode. There are many more examples on the Internet, I think there is confusion about that or I'm just missing something.

Could you please clarify this? What is the difference between translation and compilation?


Solution

  • It's all a matter of definitions, and there's no single accepted definition for what "compilation" means. In your eyes, compilation is transforming a source code in some language to native; so a transformation process which doesn't generate machine code shouldn't be called "compilation". In my eyes (and apparently, the javac documentation writers' eyes as well), it should.

    There are actually a lot of different terms: translation, compilation, decompilation, assembly, disassembly, and more.

    Personally, I'd say it makes sense to group all of these terms under "compilation", because all these processes have a lot in common:

    In addition, your definition of "produces native code" is problematic:

    But these are just my opinions. I think that out there, the most accepted definitions are that:

    Under these definitions, javac could definitely be considered as a compiler. But again, it's all in the definitions: from a technical standpoint, many of these actions have a lot in common.