Java - Interview Questions and Answers on "Byte Code"

Q1.  What is Java bytecode ?

Ans. “Java bytecode” is the usual name for the machine language of the Java Virtual Machine. Java programs are compiled into Java bytecode, which can then be executed by the JVM.

Q2.  Why is Java considered Portable Language ?

Ans. Java is a portable-language because without any modification we can use Java byte-code in any platform(which supports Java). So this byte-code is portable and we can use in any other major platforms.

Q3.  How Java provide high Performance ?

Ans. Java uses Just-In-Time compiler to enable high performance. Just-In-Time compiler is a program that turns Java bytecode into instructions that can be sent directly to the processor.

Q4.  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

Q5. Which memory segment holds the Byte Code ?

Ans. Code Segment.

Q6.  Is JVM an 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.