Here's what sparked off this question in me:
Because the Java VM is available on many different operating systems, the same .class files are capable of running on Microsoft Windows, the Solaris TM Operating System (Solaris OS), Linux, or Mac OS. Some virtual machines, such as the Java HotSpot virtual machine, perform additional steps at runtime to give your application a performance boost. This include various tasks such as finding performance bottlenecks and recompiling (to native code) frequently used sections of code. -
The Java Tutorials Well, my question is: Is this the sole reason why JVM was created - for making your programs portable? Can't we take the same approach without having a JVM? Why not have different compilers (that compile source code directly to machine code) for different platforms? (Of course, then we would be faced with two situations
1. we need to distribute the source code to the end users; could be a security issue - but we could encrypt the source code or restrict access to the source code except for compiling purpose.
2. the end users would need to recompile the source code - at least initially; this could delay program start up.)
I feel that the creation of the JVM was more a result of taking the 'seperation of concerns' approach than just to address the portability issue. I presume the designers of Java wanted to give the Java programmer a single interface by providing a compiler whose only job would be to compile the source code to an intermediate bytecode. And they encapsulated the task of making sense of the bytecode in the JVM. Shouldn't we also highlight this design strategy being the cause of the JVM apart from portability?
[ April 22, 2008: Message edited by: Gaura Hari ]