Hello,
I understand that when we write a java program (the source code) we must then pass the source to another program called "interpreter" which comprises both a compiler and a JVM (java virtual machine). The job of the compiler is to convert the source code into bytecode. Byte code is NOT machine code but it is closer to assembly-like code... Bytecode is executed by the JVM which is a program that acts like an abstract/virtual hardware. The JVM does NOT convert the bytecode into machine code, correct?
Bytecode is platform independent. However, the JVM software component is platform specific: if we use Windows, we must download a Windows specific JVM, if we use a Mac a different JVM. The JMV is therefore platform dependent.
When we talk about code written in C, we say that C is not a portable language because the C compiler is platform dependent and the resulting machine code is platform dependent. More portability means "less" platform dependent. However, while the Java bytecode may be platform independent, a user still needs to have a platform dependent piece of software, the JVM, to run the bytecode. So why do we then say that Java is more portable than C?
We could write the same code in C and either compile it and share the executable with users having our same platform (OS+CPU) or directly share the C source code as long as the users have a suitable C compiler on their machine. If we wrote the same program in Java, users would still need to have a platform specific JVM. In both cases (C and Java), the users need platform specific software installed on their machine. So how is java more portable than C?
Thanks!
I understand that when we write a java program (the source code) we must then pass the source to another program called "interpreter" which comprises both a compiler and a JVM (java virtual machine). The job of the compiler is to convert the source code into bytecode. Byte code is NOT machine code but it is closer to assembly-like code... Bytecode is executed by the JVM which is a program that acts like an abstract/virtual hardware. The JVM does NOT convert the bytecode into machine code, correct?
Bytecode is platform independent. However, the JVM software component is platform specific: if we use Windows, we must download a Windows specific JVM, if we use a Mac a different JVM. The JMV is therefore platform dependent.
When we talk about code written in C, we say that C is not a portable language because the C compiler is platform dependent and the resulting machine code is platform dependent. More portability means "less" platform dependent. However, while the Java bytecode may be platform independent, a user still needs to have a platform dependent piece of software, the JVM, to run the bytecode. So why do we then say that Java is more portable than C?
We could write the same code in C and either compile it and share the executable with users having our same platform (OS+CPU) or directly share the C source code as long as the users have a suitable C compiler on their machine. If we wrote the same program in Java, users would still need to have a platform specific JVM. In both cases (C and Java), the users need platform specific software installed on their machine. So how is java more portable than C?
Thanks!