Badal Chowdhary wrote:1) Platform Independence: It basically means write once, run anywhere. You write a piece of Java utility in Windows, the same piece can be run on Linux or Solaris without any change to source.
That's the basic principle, but it does require the programmer to not use any platform specific code. The use of wrong line breaks (\r\n vs \r vs \n), file separators (/ vs \), path separators (: vs ;) etc can break the entire platform independence.
2) Why you need to compile Java classes? Well, computer only understands binary (class files).
The computer doesn't understand class files. The JVM does, and it translates it into code the operating system understands - a lever lower than Java byte code. This is done by the JIT.
It basically wouldn't have any clue about logic written using various programming constructs. Perl on the other hand is a scripting language and not a programming language.
But Python, Perl and PHP all allow code to be directly executed without the need to compile it. Java could have chosen for the same approach. It was a design decision to compile into intermediate byte code - a middle way to running code directly (usually slower but platform independent) and compiling into code native to the operating system (usually faster but no longer platform independent). In the old days, this middle way caused Java programs to run significantly slower than native applications, but the JVM has been improved quite a bit to decrease this slowness. Java applications hardly run slower than native applications these days.