Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does JVM ensure platform independency across all processor architectures? [closed]

In my quest to understand the reasoning to use Java over C++ or vice versa for writing applications, I became stuck on this one point. I watched a video introducing me to Java and they said the reason there is a JVM is because it makes Java portable, meaning it runs on many architectures like phones and stuff without having to write a new compiler for each different CPU OS combo. But people must have to do something to make it compatible with each CPU and OS. I don't see how using a JVM changes anything.

like image 530
Lv99Zubat Avatar asked Aug 10 '16 22:08

Lv99Zubat


1 Answers

The initial (BETA) versions of Java were derided for being "write once, test everywhere". Improving the quality of the software on the initial platforms (SunOS/Solaris, Windows, Mac, etc) greatly increased its' portability (and portable software is inherently easier to port). Currently, there are multiple implementations of Java (IBM, JRockit, etc).

Fundamentally, Java is the specification of a virtual machine that executes byte codes; and not any particular implementation. Because the byte code is the same across platform the Java compiler doesn't need to be altered to support new platforms. Further, much of the OpenJDK (and, thus, the Oracle JVM) is written in Java. Basically, bootstrapping Java is simplified compared to bootstrapping a compiler for a "real" CPU architecture1.

1Excluding CPUs that natively execute Java byte code.

like image 104
Elliott Frisch Avatar answered Sep 27 '22 19:09

Elliott Frisch