Why Java is platform independent?

A platform is the hardware or software environment in which a program runs. There are two types of platforms software-based and hardware-based. Java provides a software-based platform. Java code can be run on multiple platforms, for example, Windows, Linux, Sun Solaris, Mac/OS, etc.

Platform independent language means once compiled you can execute the program on any platform (OS). Java is called platform independent because of its Bytecode which can run on any system irrespective of its underlying operating system.

When you compile Java programs using javac compiler it generates bytecode.

Note: Java is platform independent but JVM is platform dependent.