Is Java compiled or interpreted?

Started by
30 comments, last by Extrarius 19 years ago
You know, even "native" executables are "interpreted". After all, it is the CPU's job to translate opcodes into actual "operations" - that's interpretation, isn't it? Does it really matter what form the interpretation instructions come in?

Additionally, ocodes used in earlier architectures may be interpreted by the CPU as a sequence of "newer" opcodes (or 32-bit code on 64-bit systems). Then there is microcode. Is that hardware or software?

There are some hardware JVM. Is Java bytecode interpreted then?


Does the distinction matter?
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
Original post by ProgrammingHobbit
So its compiled (though not to native executable), then interpreted?quote]Yes to first part, no to second (in general). Methods that aren't called much are interpreted, but methods that are called often are compiled (during run-time) to native executable code and the native version is used thereafter.
I guess it all depends on how you define "interpreted" and "compiled". It seems like a semantics game to me.

ProgrammingHobbit
ProgrammingHobbit------------------Don't hate me because i'm a Hobbit.If you already know C++, then you already know the D Programming Language. Its Awesome!!
I have to add your post to my list of dumbest things said on the internet, Hobbit. Thanks for expanding my list.

CPUs do not "interpret" machine code, they execute it. There's kinda a difference there. Please do yourself a favor and take some CS courses.
Quote:CPUs do not "interpret" machine code, they execute it. There's kinda a difference there.

Whats the difference between interpreting and executing? Take a transmeta CPU what does it do? A hardware JVM like the one at jopdesign.com?
Quote:Original post by boebi
I have to add your post to my list of dumbest things said on the internet, Hobbit. Thanks for expanding my list.

CPUs do not "interpret" machine code, they execute it. There's kinda a difference there. Please do yourself a favor and take some CS courses.


What did I say?
I made no attempt to define "interpreted" or "compiled" for anyone alse. I believe Fruny stated something to the effect that CPUs interpret machine code (no offense Fruny).

Don't go starting flames boebi. You know nothing about my CS knowledge and experience.

ProgrammingHobbit
ProgrammingHobbit------------------Don't hate me because i'm a Hobbit.If you already know C++, then you already know the D Programming Language. Its Awesome!!
Quote:Original post by Fruny
Does the distinction matter?
It does. By compiling you avoid one level of interpretation, and interpretation is costly. None of the interpretation happening in the lower levels matter, it's still one level *less* interpretation when the code is compiled. We could also have some term for by-passing two levels of interpretation, if that was ever practical. E.g. converting code directly to a new piece of hardware.
Interpreted code is not directly executed by the hardware...it gets "converted" during execution one instruction at a time (usually) to machine code. That process is much slower than running compiled code.

If you take Java bytecode and run it on a really old JVM, the bytecode is being interpreted. If you run the same code on a hardware JVM, the bytecode "magically" becomes compiled cause it's executing directly on the CPU...no runtime conversion.
Sorry Hobbit, that WAS Fruny....so thanks Fruny...you get added to my fun list ;) JK
I believe Fruny said it all.

Basically, the java language is compiled to bytecode, and everyone seems to agree on this.

Then, every portion of bytecode is:
- Interpreted
- Compiled and interpreted
- Compiled and executed
- Executed

Depending on the VM implementation and the processor. It is interpreted on older VMs, executed on hardware VMs, compiled-executed on older machines and compiled-interpreted on current machines (where the processor interprets x86 machine code into its own set of instructions).

Also note that many recent CPUs do not execute x86 instructions: they actually execute their own internal set of instructions, and interpret (or compile) x86 code into these instructions on-the-fly.

This topic is closed to new replies.

Advertisement