Is java platform independent or not?

Platform-independent means that the code (bytecode) compiled by java can run on all operating systems. The program is written in a human-readable language. It may contain words, phrases, etc. that the machine cannot understand. For the source code that the machine can understand, it needs to use a language that the machine can understand, usually a machine-level language. Therefore, the role of the compiler has come. The compiler converts the high-level language (human language) into a format that the machine can understand. Therefore, a compiler is a program that translates the source code of another program from a programming language into executable code. This executable code may be a series of machine instructions that can be directly executed by the CPU, or it may be an intermediate representation interpreted by a virtual machine. This intermediate representation in Java is Java bytecode.

Step by step Execution of Java Program:

  • Whenever a program is written in JAVA, the javac compiles it.
  • The results of the JAVA compiler is that the .class file or the bytecode and not the machine native code (unlike the C compiler).
  • The bytecode generated may be a non-executable code and wishes an interpreter to execute on a machine. This interpreter is that the JVM and thus the Bytecode is executed by the JVM.
  • And finally, the program runs to offer the specified output.

In the case of C or C++ (language that isn't platform independent), the compiler generates a .exe file that is OS-dependent. once we attempt to run this .exe file on another OS it doesn't run, since it's OS-dependent and hence isn't compatible with the opposite OS.

Java is platform-independent but JVM is platform dependent

In Java, the most point here is that the JVM depends on the OS – so if you're running Mac OS X you'll have a special JVM than if you're running Windows or another OS. These facts are often verified by trying to download the JVM for your particular machine – when trying to download it, you'll tend an inventory of JVMs like different operating systems, and you'll obviously pick whichever JVM is targeted for the OS that you simply are running. So we will conclude that JVM is platform-dependent and it's the rationale why Java is in a position to become “Platform Independent”.

Important Points:

  • In the case of Javait's the magic of Bytecode that creates it platform-independent.
  • This adds to a crucial feature within the JAVA language termed portability. Every system has its own JVM which gets installed automatically when the JDK software is installed. for each OS separate JVM is out there which is capable to read the .class file or byte code.
  • An important point to be noted is that while JAVA is a platform-independent language, the JVM is platform-dependent. Different JVM is meant for various OS and byte code is in a position to run on different OS.

Submit Your Programming Assignment Details