Search code examples
javajavac

Is Javac is platform independent


I am a newbie to Java, somebody clarify my doubt about platform independency, I know Java is a platform independent language,and JVM is platform dependent but is Java Compiler Platform independent?


Solution

  • There are four elements involved in your question:

    1. The Java source code for your program
    2. The javac compiler
    3. The bytecode that the compiler generates when it compiles your source code
    4. The Java Virtual Machine (JVM) that executes the bytecode to run your program. (This is the program that runs when you type java MyMainClass.)

    Items 1 and 3 are platform-independent (unless your program uses platform-dependent, external libraries). Items 2 and 4 are platform-dependent (that is, each platform--Windows, Linux, Mac, etc.--uses its own version of javac and the JVM).

    The result is that you can compile your Java program on any platform that runs javac and then execute the program on that same platform or on any other platform that has a JVM.