Witscale Test Center

A.1 How Java works > A.1.1 How Java program compiles?


A.1.1 How Java program compiles?

Java takes a different approach than the platform-specific compilers. The Java compiler generates hardware-independent bytecodes from the source code. These bytecodes can be executed only by a Java Virtual machine (JVM). The compilation process is illustrated on the left side of figure A.1. Java source code is compiled into Java bytecode files, also called as class files.

 


Figure A.1 Java Source compilation and Execution

 

The class files are special files with a specific format. They are not machine-readable (executable) and cannot be directly executed on a hardware platform. JVM understands the bytecodes in a class file and can execute it. The Java compiler’s job is to convert the Java source code in a class file, which can be understood and executed by the JVM.