Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Is Java compiled or interpreted?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
31 replies to this topic

#1 ProgrammingHobbit   Members   -  Reputation: 100

Like
0Likes
Like

Posted 07 April 2005 - 07:49 AM

I am not much of a Java programmer (I prefer C++), but I am firmly of the opinion that Java is an interpreted language. However, other people disagree with that assesment saying it is compiled. Who is right? I hope this is the right forum for this. [edit] This thread probably should have gone in the Java Development Forum [/edit] ProgrammingHobbit [Edited by - ProgrammingHobbit on April 7, 2005 3:31:54 PM]

Sponsor:

#2 Extrarius   Members   -  Reputation: 1412

Like
0Likes
Like

Posted 07 April 2005 - 07:54 AM

Java is compiled to bytecode, which was then traditionally interpreted. I hear that Java is JITed to native code these days, but there is much conflicting information about modern methods of Java execution.

#3 joew   Crossbones+   -  Reputation: 3678

Like
0Likes
Like

Posted 07 April 2005 - 07:54 AM

both depending on version/method.

#4 Alpha_ProgDes   Crossbones+   -  Reputation: 4692

Like
0Likes
Like

Posted 07 April 2005 - 07:55 AM

AFAIK, the VM is written in the C, C++, and/or ASM (or even the OS' API). which would be compiled code. the java that is sent to the VM is interpreted code. that allows the write once, run anywhere effect. with JIT compilers though you can either bypass the interpreting the code and compile it in the cpu's machine code and run it. or the VM will take certain interpreted code parts and machine code compile them.

i'm pretty sure i'm wrong, but that's how i understand it.

#5 pinacolada   Members   -  Reputation: 834

Like
0Likes
Like

Posted 07 April 2005 - 07:58 AM

Considering that you have to use a program called the Java Compiler, so that you can compile your Java program, then the naive answer is that it's compiled.

Also, the definition I found on Wikipedia for "interpreted language" defines it as "a programming language whose programs may be executed from source form, by an interpreter". Since you cannot run Java programs from source form, it stands to reason that it's not an interpreted language.

#6 ProgrammingHobbit   Members   -  Reputation: 100

Like
0Likes
Like

Posted 07 April 2005 - 08:02 AM

So its compiled (though not to native executable), then interpreted?

Does that sound right?

ProgrammingHobbit

#7 markr   Crossbones+   -  Reputation: 1653

Like
0Likes
Like

Posted 07 April 2005 - 08:06 AM

The question is really, are Java bytecodes compiled or interpreted?

The answer is typically both.

A modern JVM is capable of compiling (to native code) and interpreting bytecodes. How and where it does this is really up to the compiler.

Most of them are based on the "Hotspot" client or server VM. I'm not completely sure how these work, but I think it decides based on how often a method is run, whether it compiles or interprets it.

Compiling takes a significant amount of effort, so the VM doesn't just compile every method of every class by default - that would take too long (apparently). There are VMs however, which do compile every method of every class normally.

For example, with GJC you can compile every method of every class (it has an interpreter too though, but this is only used for code which hasn't been ahead-of-time compiled).

However, it seems that benchmarks have shown that GJC ahead-of-time compiled code performs considerably worse than hotspot just-in-time compiled code.

I don't know about commercial VMs though, they might be somewhat better than GJC.

Mark

#8 RomSteady   Members   -  Reputation: 248

Like
0Likes
Like

Posted 07 April 2005 - 08:06 AM

Java is compiled into Java bytecode, but how it executes on your system is dependant on the Java Virtual Machine installed on the machine.

Some Java VM's interpret the bytecode, others compile the bytecode to native code and execute the native code. Still others do what is called "hotspot" compilation, where it will occasionally recompile certain areas of the code to more efficient native code based on how often the code is executed and how expensive the method is.

I hope that answers your question.
Michael Russell / QA Manager, Ritual EntertainmentI used to play SimCity on a 1:1 scale.

#9 pinacolada   Members   -  Reputation: 834

Like
0Likes
Like

Posted 07 April 2005 - 08:06 AM

Quote:
Original post by ProgrammingHobbit
So its compiled (though not to native executable), then interpreted?

Does that sound right?

ProgrammingHobbit


Actually yeah, that does sound right. I did more reading on Wikipedia and found this quote:

"Most so-called interpreted languages use an intermediate representation, which combines both compilation and interpretation. In this case, a compiler may output some form of bytecode, which is then executed by a bytecode interpreter. Examples include Python, Java, and Perl."

#10 justo   Members   -  Reputation: 184

Like
0Likes
Like

Posted 07 April 2005 - 08:11 AM

java is compiled to a byte code that is platform neutral (based on a hypothetical stack based system) much like .net and then, when run, it is JIT compiled to native code for the host machine, with optimizations performed on the most active parts (the "hot spots").

the first JIT compiler for java came out in 1996. the current hotspot compiler came out 6 years ago in 1999. java's been a compiled language for a long time. try and run a similar program in an interpreted language and you'll see the difference.

the only real things holding back java performance-wise are array bounds checking, increased precision required for functions like sin, cos, sqrt, etc, and the lack on an easy assembly inliner. but you get built in bounds checking, increased precision and theres always JINI, so its all about trade-offs.

#11 Fruny   Moderators   -  Reputation: 1653

Like
0Likes
Like

Posted 07 April 2005 - 08:27 AM

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?

#12 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

0Likes

Posted 07 April 2005 - 08:46 AM

[quote]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.


#13 ProgrammingHobbit   Members   -  Reputation: 100

Like
0Likes
Like

Posted 07 April 2005 - 08:47 AM

I guess it all depends on how you define "interpreted" and "compiled". It seems like a semantics game to me.

ProgrammingHobbit

#14 boebi   Members   -  Reputation: 100

Like
0Likes
Like

Posted 07 April 2005 - 08:48 AM

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.

#15 Trap   Members   -  Reputation: 684

Like
0Likes
Like

Posted 07 April 2005 - 08:54 AM

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?

#16 ProgrammingHobbit   Members   -  Reputation: 100

Like
0Likes
Like

Posted 07 April 2005 - 08:59 AM

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

#17 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

0Likes

Posted 07 April 2005 - 09:08 AM

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.

#18 boebi   Members   -  Reputation: 100

Like
0Likes
Like

Posted 07 April 2005 - 09:11 AM

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.

#19 boebi   Members   -  Reputation: 100

Like
0Likes
Like

Posted 07 April 2005 - 09:13 AM

Sorry Hobbit, that WAS Fruny....so thanks Fruny...you get added to my fun list ;) JK

#20 ToohrVyk   Members   -  Reputation: 1591

Like
0Likes
Like

Posted 07 April 2005 - 09:25 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS