masum billah masum billah - 11 months ago 63
Java Question

is bytecode faster than any executable code(.exe etc)?

i am confused about bytecode.

suppose my code is

class Simple{
public static void main(String args[]){
system.out.print("hello Java!");

let it is compile in java compiler then it to be a Simple.class


int main(){
print("hello Java!");

after compiling it genarate sample.exe
what is faster
sample.exe or sample.class

Answer Source

It really depends on the quality of the implementation of the respective solutions - it's perfectly possible that a GOOD byte-code engine will beat a poorly written compiler, but a badly implemented byte-code engine will definitely be slower than a high quality native compiler.

A good optimiźing native compiler will often beat a compiler that produce byte-code, but there are some decent just-in-time compilers that do a VERY good job on bytecode too - with the added advantage of being able to understand what is "hot" and "cold" paths of the code through profiling information, something that requires at least one extra step in a C or C++ compiler - running some representative sample code to gather information, and then feeding that back to the compiler for "profile guided optimisation".

If the byte-code implementation is simply a byte-code interpreter (not a "just-in-time compiler"), one would expect to see better performance from a native compiled piece of code. But modern Java "byte code interpreters" nearly always have a JIT compiler built in.