Actually, almost any language can be platform independent. It’s the distributable code that usually isn’t. Java code runs in a JVM. The JVM is platform specific, but theoretically Java programs will run on a JVM regardless of what OS it’s installed on.
Basically, any interpreted language should run on a system the successfully implements the interpreter. No one is 100% successful at this, however; no even Java. An executable is compiled for a specific OS. However, the source code can be completely portable. There are thousands of C and C++ programs that are said to be “cross platform” meaning they can be successfully compiled on different platforms without much pain. To clarify, not all languages use an interpreter.
A computer program, any program, executes within the context of some machine. The machine itself; CPU, memory, graphics card, etc, has a set of instructions it will run. These instructions are called machine code. Some, formerly most, programming languages are compiled into machine code. This results in a executable binary that runs directly against the machine itself. The result may be called compiled code and getting from source to binary is called compiling. Though sometimes as distinction is made between compiling and linking.
Java calls the process of going from source files (.java) to .class files compiling. However, the result can’t run on it’s own. The result is a preprocessed set of instructions ( p-code ) that the JVM ( interpretor ) runs. JVM stands for Java “Virtual Machine,”, the idea being that .class files are machine code inside the the VM. It’s a cute, if confusing, way for Java to obfuscate it’s interpreted nature. Because of the need for a middleman, the interpretor, interpreted languages are generally views as slower than their directly executable counter parts. However, the line can be blurry, depending how where the interpreting is happening. In some environments, the Operating System itself acts an interpretor for nearly everything executed.
A “scripting” language is usually interpreted, with an executable program reading the script and executing the instructions.