Why is Java platform independent?
When you compile a Java file, javac does not make code for Windows or Linux. It makes bytecode in a .class file. Each operating system has its own JVM, which reads the same bytecode and runs it. So the same .class file works everywhere.
Note that the JVM is platform dependent (there is a different JVM for each system), but the bytecode is platform independent.
public class Hello {
public static void main(String[] args) {
System.out.println("Hello");
}
}
Terminal
$ javac Hello.java
$ ls
Hello.class
Hello.java
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |