The meaning of platform independent is that, the java source code can keep running on every operating system.
A program is written in a language which is a comprehensible language. It might contain words, phrases and so forth which the machine does not understand it. For the source code to be known by the machine, it should be in a language understood by machines, ordinarily a machine-level language. Along these lines, here comes the role of a compiler. The compiler changes over the abnormal state language into a configuration understood by the machines. Accordingly, a compiler is a program that deciphers the source code for another program from a programming language into executable code.
This executable code might be an arrangement of machine guidelines that can be executed by the CPU specifically, or it might be an intermediate representation that is translated by a virtual machine. This intermediate represented in Java is the Java Byte Code.
Step by step Execution of Java Program:
- At whatever point, a program is written in JAVA, the javac gathers it.
- The result of the JAVA compiler is the .class record or the bytecode and not the machine native code (unlike C compiler).
- The bytecode created is a non-executable code and needs a interpreter to execute on a machine. This interpreter is the JVM and along these lines the Bytecode is executed by the JVM.
- And finally the program runs to give the desired output.
In case of C or C++ the compiler produces an .exe file which is OS dependent. When we attempt to run this .exe file on another OS it doesn’t run, since it is OS dependent and thus isn’t compatible with the other OS.
Java platform is independent but dependent on JVM platform
In Java, the main point here is that the JVM relies upon the operating system – so on the off chance that you are running Mac OS X you will have an alternate JVM than if you are running Windows or some other operating system. This reality can be confirmed by trying to download the JVM for your specific machine – when attempting to download it, you will given a list of JVM’s comparing to various operating system, and you will clearly pick whichever JVM is focused for the OS that you are running. So we can complete that JVM is platform dependent and it is the reasons why Java is able to become “platform Independent”.
Important Points:
- In the case of Java, it is the appearance of Bytecode that makes it platform independent.
- This adds to a vital component in the JAVA language termed as portability. Each system has its own JVM which gets installed automatically when the jdk software is installed. For each OS separate JVM is accessible which is capable to read the .class file or byte code.
- An imperative point to be noted is that while JAVA is platform independent language, the JVM is platform dependent. Distinctive JVM is designed for various OS and byte code can keep running on various OS.
This article is contributed by professional java trainers of java training in Chandigarh.