Is javac a compiler?
Compilers usually produce machine code, but javac produces bytecode, which is not
that similar to machine code. However, class files are a bit like object files (like Win‐
dows .dll files, or Unix .so files)—and they are certainly not human readable.
In theoretical computer science terms, javac is most similar to the “front half ” of a
compiler—it creates the intermediate representation that can then be used to pro‐
duce (emit) machine code.
However, because creation of class files is a separate build-time step that resembles
compilation in C/C++, many developers consider running javac to be compilation.
In this topic, we will use the terms “source code compiler” or “javac compiler” to
mean the production of class files by javac.
We will reserve “compilation” as a standalone term to mean JIT compilation—as it's
JIT compilation that actually produces machine code.
Why is it called “bytecode”?
The instruction code (opcode) is just a single byte (some operations also have
parameters that follow them in the bytestream)—so there are only 256 possible
instructions. In practice, some are unused—about 200 are in use, but some of them
aren't emitted by recent versions of javac.
Is bytecode optimized?
In the early days of the platform, javac produced heavily optimized bytecode. This
turned out to be a mistake. With the advent of JIT compilation, the important meth‐
ods are going to be compiled to very fast machine code. It's therefore very important
to make the job of the JIT compiler easier—as there are much bigger gains available
from JIT compilation than there are from optimizing bytecode, which will still have
to be interpreted.
Is bytecode really machine independent? What about things like endianness?
The format of bytecode is always the same, regardless of what type of machine it
was created on. This includes the byte ordering (sometimes called “endianness”) of
the machine. For readers who are interested in the details, bytecode is always big-
Is Java an interpreted language?
The JVM is basically an interpreter (with JIT compilation to give it a big perfor‐
mance boost). However, most interpreted languages (such as PHP, Perl, Ruby, and
Python) directly interpret programs from source form (usually by constructing an
abstract syntax tree from the input source file). The JVM interpreter, on the other
hand, requires class files—which, of course, require a separate source code compila‐
tion step with javac.