Java - Interview Questions and Answers on Platform Independence

Q1. Is Java a platform independent language ?

Ans. Yes. 

Q2. What do you mean by platform independence ?

Ans. Same Source code can be used to build applications that works on different operating systems.

Q3. What makes Java a platform independent language ?

Ans. Its Byte Code. Ability of the JVM to generate system specific binary code using intermediatery code ( class files).   

Q4. Is C a platform independent language ?

Ans. No

Q5.  Tell something about history of Java ?

Ans. Java was initially found in 1991 by James Gosling, Sun Micro Systems. At first it was called as "Oak". In 1995 then it was later renamed to "Java". java is a originally a platform independent language. Currently Oracle, America owns Java. 

Q6.  What are advantages of using Servlets over CGI ?

Ans.  Servlets are platform independent as they are written in Java.

Q7.  What is Java bytecode ?

Ans. Java bytecode is the instruction set of the Java virtual machine. Each bytecode is composed by one, or two bytes that represent the instruction, along with zero or more bytes for passing parameters.

Q8.  Is JVM a overhead ? 

Ans. Yes and No. JVM is an extra layer that translates Byte Code into Machine Code. So Comparing to languages like C, Java provides an additional layer of translating the Source Code.

C++ Compiler - Source Code --> Machine Code
Java Compiler - Source Code --> Byte Code   ,  JVM - Byte Code --> Machine Code

Though it looks like an overhead but this additional translation allows Java to run Apps on all platforms as JVM provides the translation to the Machine code as per the underlying Operating System. 

Q9.  What is Byte Code ? Why Java's intermediary Code is called Byte Code ?

Ans. Bytecode is a highly optimized set of instructions designed to be executed by the Java run-time system. Its called Byte Code because each instruction is of 1-2 bytes.

Sample instructions in Byte Code -

1: istore_1
2: iload_1
3: sipush 1000
6: if_icmpge 44
9: iconst_2
10: istore_2