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 |
|---|
| Java Introduction |
| What is Java? JDK, JRE and JVM |
| Java Install and Setup |
| Your First Java Program: Hello World |
| Java Syntax |
| Java Comments |
| Java Cheat Sheet |
| Exercises & Assignments |
|---|
| No Content Found. |