One of the most important features of java is platform independency and to understand how java achieved platform indecency, one must learn what is platform dependency. Let us understand what is a platform to understand platform dependency. Platform is a combination of hardware and software. Hardware mainly refers to microprocessors and software refers to the Operating system. For example, the platform in your computer could be the combination of i5 processor and windowsOS or it could be i9 processor and mac OS as shown below. However, from the software engineers perspective, platform only refers to OS.
Platform=Hardware + Software.
After getting to know what is platform let us now understand platform dependency by considering different cases of C language which is very much platform-independent.
we considered a file of C programming language as the extension is exmp.c. Since C programming language is platform dependent programming language, its platform of execution and platform of compilation must be the same. In the above case the platform of compilation and platform of execution is the same which is windows operating system and hence we got the output.
we again considered the file of C programming language as the extension is exmp.c. In this case, we considered two computers having the same operating system connected via LAN connection. If we now take a copy of MLL(Machine Level Language) file from first computer and try to execute it on the second computer, according to you will the file execute????
Compilation Phase | Execution Phase |
Windows | windows |
If in case you are still confused, just check two phases. COMPILATION PHASE EXECUTION PHASE Windows Windows If you can refer the above table, compilation happened on windows and execution happened on windows. Since platform of compilation is the same as that of platform of execution,the file gets executed which simply means you will get the output.
This case is the same as that of case ii except the platform of the second computer that is C
If you can refer the above table, compilation happened on windows and execution happened on UNIX. Since the platform of compilation is not same as that of platform of execution file will not get executed which simply means you will not get the output.
Compilation Phase | Execution Phase |
Windows | UNIX |
The problem faced in C or C++ programming language is that their compiler directly converts High-level language code to machine level language codeand if this code is copied on other type of operating system and tried to execute, it doesn’t work because the code was written using platform dependent programming language.To reslove this issue, JAMES GOSLING, the inventor of java programming language which was platform-independent.
Let us now learn how java achieved platform independence
Let us assume you are writing code using java on your computer which has windows os. Since Machine understands machine-level code not your high-level code, the conversion must happens. Let us see how exactly conversion happens in java. Initially, your HLL code is given as input to the compiler but the java compiler will not give MLL code as output like c and c++ compiler rather it takes HLL as input and gives a special type of code as output called as byte code which is platform-independent. Byte code is neither HLL code nor MLL code, hence it is also referred to as intermediate code. If you can recollect machine understands only MLL code but java compiler gave you byte code. To resolve this, James Gosling provided software called JVM(Java virtual Machine)which was platform-dependent that is different OS have different JVM. Since you are writing code on windows OS, you will have to download windows compatible JVM . JVM will now convert byte code to machine level code which machine can easily understand. In this way, java achieved platform independence using a special type of code which is byte code.
0 Comments:
Post a Comment