“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”
That’s because the Java bytecode is interpreted, not compiled. Programs written in C are compiled into binaries which can be executed by a specific computer processor. Programs written in Java require one more step — they must be interpreted by the Java “virtual machine” before running on a particular computer architecture. As a result, a computer running a Java program has to execute more machine-language instructions to do the same amount of work than a computer running an equivalent program written in C.
C++ does not necessarily give better run-time performance than Java.
With Just-In-Time compilers, the cost of bytecode conversion is low for a long-running program.
With modern VMs (like Sun’s HotSpot), many optimizations can be made dynamically. The VM analyzes various metrics of the program at run-time and tweak it’s bytecode. An example: seeing that a particular case in a switch statement occurs more frequently than others, so the VM will reorganize the code to check that case first. Modern C++ environments can acheive similar goals via “Profile-Guided Optimization”. However, they do not dynamically adjust at run-time.
That’s because the Java bytecode is interpreted, not compiled. Programs
written in C are compiled into binaries which can be executed by a specific computer processor. Programs
written in Java require one more step — they must be interpreted by the Java “virtual machine” before running
on a particular computer architecture. As a result, a computer running a Java program has to execute more
machine-language instructions to do the same amount of work than a computer running an equivalent
program written in C.
C++ does not necessarily give better run-time performance than Java.
With Just-In-Time compilers, the cost of bytecode conversion is low for a long-running program.
With modern VMs (like Sun’s HotSpot), many optimizations can be made dynamically. The VM analyzes various metrics of the program at run-time and tweak it’s bytecode. An example: seeing that a particular case in a switch statement occurs more frequently than others, so the VM will reorganize the code to check that case first. Modern C++ environments can acheive similar goals via “Profile-Guided Optimization”. However, they do not dynamically adjust at run-time.
Few more points:
1) C is a low-level language in which you can execute certain assembly level instructions.
2) You can also access memory locations directly using pointers and optimize the implementations.
3) You can optimize certain methods by closely integrating with specific architecture and platform.
Leave an Answer/Comment