How exactly does java compilation take place?

前端 未结 9 985
执笔经年
执笔经年 2020-12-07 07:56

Confused by java compilation process

OK i know this: We write java source code, the compiler which is platform independent translates it into bytecode, then the jvm

相关标签:
9条回答
  • 2020-12-07 08:26

    Windows doesn't know how to invoke Java programs before installing a Java runtime, and Sun chose to have native commands which collect arguments and then invoke the JVM instead of binding the jar-suffix to the Java engine.

    0 讨论(0)
  • 2020-12-07 08:27

    Well, javac and the jvm are typically native binaries. They're written in C or whatever. It's certainly possible to write them in Java, just you need a native version first. This is called "boot strapping".

    Fun fact: Most compilers that compile to native code are written in their own language. However, they all had to have a native version written in another language first (usually C). The first C compiler, by comparison, was written in Assembler. I presume that the first assembler was written in machine code. (Or, using butterflies ;)

    .class files are bytecode generated by javac. They're not textual, they're binary code similar to machine code (but, with a different instruction set and architechture).

    The jvm, at run time, has two options: It can either intepret the byte code (pretending to be a CPU itself), or it can JIT (just-in-time) compile it into native machine code. The latter is faster, of course, but more complex.

    0 讨论(0)
  • 2020-12-07 08:33
    1. .java file
    2. compiler(JAVA BUILD)
    3. .class(bytecode)
    4. JVM(system software usually build with 'C')
    5. OPERATING PLATFORM
    6. PROCESSOR
    0 讨论(0)
提交回复
热议问题