Hello,
I wonder... why the Java compiler does not work as a JVM?
I mean I download Java with its compiler that is dedicated for a chosen operation system / processor. Why the compiler does tranlate the source code to the byte code instead of changing it straight to the machine code (zeros and ones) for this operation system / processor?
Is JVM really needed?
Comments (7)
- Popular
- New
- Old
You must be signed in to leave a comment
Willi Ehrmann
4 July 2021, 19:01
The point of this whole System is that you can execute the same bytecode for example on andoid and windows or any other machine. the JVM is the one that is specific and turns the same bytecode to machinecode for the appropriate machine. So you only have to provide one softwarerevision which can run anywhere.
+1
Monika
11 July 2021, 12:23
Do I understand correctly that:
- I can code on a computer with e.g. Windows system
- then I compile the code to the byte code
- and this version (byte code) can be sent to another machine?
Can't I send a source code from e.g. Windows system to Android and the code would be compiled on an Android device?
0
Willi Ehrmann
12 July 2021, 02:53
Yes you're correct. That's one of the big strengths of Java. You could still send sourcecode from Windows to Android and use a Java Compiler which runs on Andoid. But it would create the same bytecode. In Java the Java Virtual Machine is the difference on every system the Bytecode is the same and gets interpreted (translated into machinecode) differently on Android and Windows by the corresponding Java Virtual Machine.
0
Monika
15 July 2021, 18:43
Sorry for being stubborn... but why compiler on Android does create the same bytecode as on Windows? Aren't they (I mean compilers) customized - different for every operating system?
0
Willi Ehrmann
16 July 2021, 07:03
normally yes. But for Java the Compiler doesnt compile the source code directly int machine code for that specific machine. Instead it gets compiled into some intermediate thing called bytecode. This bytecode then gets interpteted differently by a Java Virtual Machine on Windows or Android into an appropriate machine code for that machine. So the JVM is the one translating it into machinecode and is the one costumized differently for every operatiing system. That's what Java does differently from like every other programming language.
0
Monika
25 July 2021, 09:43
Thanks!
0
Monika
29 July 2021, 06:53
Thanks!
0