There are two types of programming languages, Few languages we call platform-dependent languages and others are platform-independent programming languages. But what does it really mean of platform Dependent and Platform Independent code? In this article, we are going to discuss the “what is platform Dependency and what is platform Independence in the context of the programming languages”
Platform = Operating System + Micro Processor (Hardware).
Platform dependent code or Platform Dependency :
Applications that are developed by using few languages such as C language cannot be executed on other operating systems, whenever we compile the source code of a program written using these languages, will generate Machine code (or ) Executable code (or) Native code.
The machine code generated for one operating system cannot execute on other operating systems. This kind of code is called platform-dependent code.
Example: Flow of Source code to binary
In The above example the .exe file which is written using the C language in Windows OS is executed only in Windows OS but not in others.
NOTE: Any application which directly contacts the OS is always dependent on OS.
Platform Independent code or Platform Independency :
It is an approach to executing an application on multiple Operating Systems, this feature is available in advanced languages like C#, JAVA as well as any .NET languages also.
In all these languages whenever we compile the source code, first it is converted into semi-finished/Intermediate code which can be carried and executed on any machine but to run the code on a machine first we need to install software on the machine which converts the intermediate code into machine code according to the Operating System.
JAVA Language (Windows):
Source code –> Compile –> Byte code
Byte code –> JVM (Java Virtual Machine) –> Machine code
In the above case of JAVA after compilation of source code, it generates byte code (Semi-Finished) which can be carried and executed on any machine where the JVM is available which converts Byte code into Machine Code.
As .NET is a collection of languages we can write the source code by using any language of our choice but the code that is written by using any .NET language once after compilation generates MSIL code, which can be carried and executed in any machine, where the CLR is available which converts the MSIL code into machine code according to the Operating System.
NOTE: Both JVM & CLR are dependent on the operating system i.e., we need to install them separately for each Operating System.