Java Interview Question – JDK, JRE and JVM

Q1. (Asked in TCS): What is the JVM in Java?

JVM stands for Java Virtual Machine. It is responsible for:

  • Running Java bytecode (.class files)
  • Converting bytecode to machine code
  • Providing platform independence
    It also handles memory management, garbage collection, and security.

Q2. (Asked in Infosys): What is JRE and how is it different from JVM?

  • JRE (Java Runtime Environment) is a package that provides the libraries and JVM needed to run Java programs.
  • JVM is a part of JRE that actually executes the bytecode.
    So, JRE = JVM + Libraries + Other files needed to run Java apps.

Q3. (Asked in Capgemini): What is the JDK in Java?

JDK stands for Java Development Kit. It is used to develop Java applications.
It includes:

  • JRE (to run the program)
  • Development tools like javac (compiler), java (launcher), and debugging tools.

Q4. (Asked in Cognizant): Can you explain the difference between JDK, JRE, and JVM?


ComponentPurposeIncludes
JVMExecutes bytecodePart of JRE
JRERuns Java programsJVM + Libraries
JDKDevelops Java programsJRE + Tools like compiler

Q5. (Asked in Wipro): Is JDK required to run a Java program?

No, JDK is not required just to run a Java program.
You only need JRE to run a program.
JDK is required when you want to compile and develop Java code.


Q6. (Asked in HCL): What is the role of the Java compiler in the JDK?

The Java compiler (javac) is a tool in the JDK that converts Java source code (.java files) into bytecode (.class files), which the JVM can understand and execute.


Q7. (Asked in Accenture): What is bytecode in Java?

Bytecode is the intermediate code generated by the Java compiler.
It is a .class file that the JVM executes, making Java programs platform-independent.


Q8. (Asked in MAANG-level mock interview – Meta): Why is Java considered platform-independent but JVM is platform-dependent?

  • Java is platform-independent because bytecode can run on any system with a JVM.
  • JVM is platform-dependent because each OS has its own implementation of JVM.

Q9. (Asked in Zoho): Can you install JRE separately from JDK? When would you do that?

Yes, JRE can be installed separately if you only need to run Java applications (e.g., running Java-based tools or games).
JDK is needed only if you want to write and compile Java programs.


Q10. (Asked in Byjuโ€™s): What happens when you type java HelloWorld in the terminal?

  • The java command uses the JVM to load the HelloWorld.class file.
  • The JVM calls the main() method and starts executing the code.
  • The program runs using resources provided by the JRE.