Q. How Java is Portable ???

A. Java is portable due to following features :

  1. Output of java code is in Bytecode (ie. Non Executable code).
  2. Bytecode is highly optimized set of instructions.
  3. Bytecode is executed by machine which is Java runtime machine is also call as JVM (Java Virtual Machine).
  4. Because output of java is in bytecode so its not possible to modify by malicious programs thats why java is secure.
  5. JVM is an interpreter.
  6. JVM takes bytecode as input and execute it.
  7. Output of java is in bytecode so we need to setup JVM on other platform which makes java Platform independent.
  8. When JVM is installed on any system then we can execute any java program.

Why java is code safe ???

  1. Java program is executed by JVM.
  2. JVM prevent program from external side effect.
  3. Their are few restrictions in java which increase safety of java.

Interpreter is slower than compiler then why java use Interpreter ???

  1. Its true that compilers are much faster than Interpreters.
  2. But java compiler generate program into bytecodes which is highly optimized.
  3. Execution of that optimized code is much faster than compilers. which makes java program faster even using Interpreters.