Java is not a compiled language.

A while back I wrote an article clearing up several popular Java myths. One such myth is that Java can be considered a “compiled” language. It seems that a link to my article was submitted to Reddit, and one of the comments there concerned this very issue. This is a topic I would like to address further.

First we need to define what makes a language “compiled”, and what does not. I think the definition for this is simple: for a compiled language, the executable binaries produced from a segment of source code are in a machine code form that is directly executable on physical hardware. As native code compilation strategies do exist for languages like Java and Python, I think it is most prudent to consider the way a program written in a particular language is typically executed.

This definition specifically excludes something along the lines of Java bytecode, in the context that Java is generally used in today. Yes, there was hardware in the past that natively executed Java bytecode. On such a system, yes, Java could be considered a “compiled” language. But today, that is not how most Java applications are executed. Most Java applications these days are run via a virtual machine on operating systems like Linux, Solaris, Windows and Mac OS X, themselves running on generic CPUs like the x86-32, x86-64, SPARC, or PowerPC.

As the Reddit comment correctly points out, many of the production-quality Java virtual machines tend to use a JIT compilation strategy. Java bytecode is converted to native code at runtime, and the native code is directly executed for the duration of the program. But the point we have to focus on is that this translation happens at runtime. Java .class files cannot be executed directly on typical hardware today. Thus Java cannot typically be considered a “compiled” language.

Now, if we were using a native Java compiler like GCJ or Excelsior JET, the situation would be different. Those compilers can generate native code binaries from Java source code. However, they are not typically used at this point in time. Java applications, be they consumer-grade or enterprise-grade, are most often run on a JVM. Maybe this will change in the future, but at this point we cannot consider Java to be a “compiled” language.

5 Responses to “Java is not a compiled language.”

  1. wxx Says:

    that being said, what is your point?

  2. MoronHunter Says:

    Dear Author,

    You are a fake know-it-all. It is immaterial these days whether a language is compiled to machine code before loading into its execution environment or after.

    I don’t know know who you are trolling for, but I hope you get paid well to spout such asinine claptrap.

    Somebody

  3. Frater Plotter Says:

    There is no such thing as a “compiled language” or an “interpreted language” in the senses in which those words are usually used. Compilation and interpretation are implementation strategies. The same language may be implemented in both ways. Even languages that were originally conceived only for compilers (such as C) or only for interpreters (such as Lisp) have been implemented in both ways.

    There are a few exceptions: notably, where compilation or interpretation is written into the language standard. An example is Common Lisp, where the existence of the “compile” function is part of the standard. Every Common Lisp system includes a compiler; usually a native-code compiler but sometimes (as in GNU CLISP) a bytecode compiler.

    In the case of Java, the language is designed for bytecode compilation — the combination of compilation and virtual-machine bytecode interpretation you describe. Dynamic translation to machine code — JIT — was added later, as were native-code compilers. It is, as such, reasonable to talk about Java as being designed for bytecode compilation but also implemented with native-code compilers. It is wrong, however, to call it an interpreted language.

  4. Masklinn Says:

    > I think the definition for this is simple: for a compiled language, the executable binaries produced from a segment of source code are in a machine code form that is directly executable on physical hardware.

    And you’re fucking wrong, as the Dragon Book states it (first phrase of the first paragraph of the first section of the first chapter of the Red Dragon Book, right after the introduction)

    “Simply stated, a compiler is a program that reads a program written in one language — the _source_ language — and translates it into another language — the _target_ language”

    Suffice to say that while the source language is higher level than the target one it doesn’t have to be the case, and that machine code is merely one of the potential target language, and the lowest level one.

    Java isn’t a language usually compiled to native code, but it’s still a compiled language.

    Oh, and there is no strategy to compile Python to machine code, the only such compiler is the Shed Skin Python to C++ compiler, and it barely only compiles a specific subset of Python

  5. Peter Bromberg Says:

    I’m sorry I bothered to click the link on Digg. JAVA is just as much a compiled language as is C# .NET, and you haven’t the foggiest idea what you are talking about.

Leave a Reply

*
To protect against spam, please type the word in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word