A compiler transforms high-level programming code into platform-independent bytecode, while a Java interpreter reads and executes this bytecode on the Java Virtual Machine (JVM). Java is considered platform independent because its compiler generates a class file that can run on any machine with a JVM, although it is dependent on the presence of the JVM for execution. This distinction allows Java programs to be executed across different platforms without modification.
A compiler transforms high-level programming code into platform-independent bytecode, while a Java interpreter reads and executes this bytecode on the Java Virtual Machine (JVM). Java is considered platform independent because its compiler generates a class file that can run on any machine with a JVM, although it is dependent on the presence of the JVM for execution. This distinction allows Java programs to be executed across different platforms without modification.
• A compiler is a computer program that transforms code
written in a high-level programming language into the platform independent file. • It is the software that converts java source file into bytecode an intermediate language to generate the class file. Interpreter • Java interpreter is a computer program (system software) that implements the JVM. It is responsible for reading and executing the program. • It is designed in such a way that it can read the source program and translate the source code instruction by instruction. • It converts the intermediate-level program into machine language. Compiler vs. Interpreter Platform Dependent
• A software developed on one platform and executed on the
same platform is known as platform dependent. • Example: C, C++. Platform Independent
• A software developed on one platform and
executed on any platform is known as platform independent. Why java is platform independent? • Java compiler does not directly convert high level language into a machine understandable language, instead it converts java instructions into intermediate language called as ByteCode. • The file is known as the class file with extension .class. • Once the class file is ready it can be executed in any machine which has JVM in it. This makes the java a platform independent. Cont.…….. • Note: Java is platform independent language but, it is JVM dependent language. • We cannot execute the class file or byte code in which the system does not contain JVM.