Let it be cleared first. What do I mean by Platform? and Why a software should be independent from Platform?
What do I mean by Platform?
In general, To run any kind of softwares need a Device(computer, laptops, smart phones etc.) with architecture(i.e. x86, MIPS etc) and an Operating System(Windows, Linux, mac-OS etc.).
These two things works as a unit to make it possible to run a software.
Why a software should be independent from Platform?
People uses different Devices and Operating Systems according to their need.
If we our programming language develop a software for any specific Platform then our software has limited reachability. I will be reachable only those people who have that Platform. That's why our programming language should allow us to develop a software which run on every platform so our software will be Platform Independent.
Note: The language which develop a Platform Independent Software, is a Platform Independent language.
Now you can say, "Java is a Platform Independent language because It develop softwares which can run on any Platform." that sounds pretty good.
That's why Java has slogan to define Platform Independency "Write Once Run Anywhere"
But How Java does this?
Every Language uses a compiler, which convert source code(our written code) into machine code.
Before Java, the languages like c and c++ uses machine specific compiler which converts source into machine specific code
What do I mean by Platform?
In general, To run any kind of softwares need a Device(computer, laptops, smart phones etc.) with architecture(i.e. x86, MIPS etc) and an Operating System(Windows, Linux, mac-OS etc.).
These two things works as a unit to make it possible to run a software.
Why a software should be independent from Platform?
People uses different Devices and Operating Systems according to their need.
If we our programming language develop a software for any specific Platform then our software has limited reachability. I will be reachable only those people who have that Platform. That's why our programming language should allow us to develop a software which run on every platform so our software will be Platform Independent.
Note: The language which develop a Platform Independent Software, is a Platform Independent language.
Now you can say, "Java is a Platform Independent language because It develop softwares which can run on any Platform." that sounds pretty good.
That's why Java has slogan to define Platform Independency "Write Once Run Anywhere"
But How Java does this?
Every Language uses a compiler, which convert source code(our written code) into machine code.
Before Java, the languages like c and c++ uses machine specific compiler which converts source into machine specific code
Source code(.c, .cpp, .h)
⬇
⬇
Preprocessor
Include Header, Expand Macro(i, .ii)
⬇
⬇
Compiler(gcc, g++)
Assembly code(.s)
⬇
⬇
Assembler
Machine code(.o, .obj)
⬇
⬇
Linker
machine executable file(.exe for windows)
here the compiler(gcc, g++) produce CPU-Architecture dependent Assembly code, then Linker will add some extra code and produce Machine code which also become dependent on Operating System. and now this code became platform dependent.
Java know that if our compiler also produce machine code then story will be same. So It create a compiler(javac) which did not produce machine code, instead of that it produced their own developed code. They call it Byte code. To produce Byte code, they did not take any kind help from CPU and OS that's why Byte code was Platform Independent.
But if Byte code was their own code, it means that Operating System didn't know anything about this code, how OS can execute it? This code needed an environment for it's execution. To resolve this problem they also develop their own Machine but It was a Software not Hardware, So they called it 'Virtual Machine' and finally it know as Java Virtual Machine(JVM).
JVM provides an environment for execution of Byte code.
Now read this carefully, "Java has one unique compiler and different JVMs." Now, a twist in story here. JVMs are dependent on platform. we need to install different JVM for different platform i.e. JVMs for Windows and Linux are different.
Why JVMs are dependent?
Java know that if our compiler also produce machine code then story will be same. So It create a compiler(javac) which did not produce machine code, instead of that it produced their own developed code. They call it Byte code. To produce Byte code, they did not take any kind help from CPU and OS that's why Byte code was Platform Independent.
But if Byte code was their own code, it means that Operating System didn't know anything about this code, how OS can execute it? This code needed an environment for it's execution. To resolve this problem they also develop their own Machine but It was a Software not Hardware, So they called it 'Virtual Machine' and finally it know as Java Virtual Machine(JVM).
JVM provides an environment for execution of Byte code.
Source code(.java)
⬇
⬇
Compiler(javac)
⬇
⬇
Byte code(.class)
JVM execute .class
JVM execute .class
Now read this carefully, "Java has one unique compiler and different JVMs." Now, a twist in story here. JVMs are dependent on platform. we need to install different JVM for different platform i.e. JVMs for Windows and Linux are different.
Why JVMs are dependent?
It's very obvious that. Any number of abstraction level you are using in any specific technology. Finally it will run on a platform, on a computer. So at the core level things become Platform Dependent.
You can say, Platform Independency is a just a level of abstraction behind Dependency, for providing convenience to Developers.
It is very easy to install our required JVM. Just go to the site of oracle, there is list of all JVMs as per Platforms, Download and install and start use this. It takes few minutes only.
So Now Let see how Java made us capable of writing Platform Independent code
Write Once
You can say, Platform Independency is a just a level of abstraction behind Dependency, for providing convenience to Developers.
It is very easy to install our required JVM. Just go to the site of oracle, there is list of all JVMs as per Platforms, Download and install and start use this. It takes few minutes only.
So Now Let see how Java made us capable of writing Platform Independent code
Write Once
- Write Once our code(.java)
- Compile it with javac(.class)
- Go on Windows, install JVM and run it.
- Go on Linux, install JVM and run it.
- Go on Mac-OS install JVM and run it
We will be thankfull to you for your suggetions
ReplyDelete