Q. How Java is Portable ???
A. Java is portable due to following features :
- Output of java code is in Bytecode (ie. Non Executable code).
- Bytecode is highly optimized set of instructions.
- Bytecode is executed by machine which is Java runtime machine is also call as JVM (Java Virtual Machine).
- Because output of java is in bytecode so its not possible to modify by malicious programs thats why java is secure.
- JVM is an interpreter.
- JVM takes bytecode as input and execute it.
- Output of java is in bytecode so we need to setup JVM on other platform which makes java Platform independent.
- When JVM is installed on any system then we can execute any java program.
Why java is code safe ???
- Java program is executed by JVM.
- JVM prevent program from external side effect.
- Their are few restrictions in java which increase safety of java.
Interpreter is slower than compiler then why java use Interpreter ???
- Its true that compilers are much faster than Interpreters.
- But java compiler generate program into bytecodes which is highly optimized.
- Execution of that optimized code is much faster than compilers. which makes java program faster even using Interpreters.