JVM, JRE & JDK Chapter

JDK Interview Questions and Answers

Learn how the Java Development Kit combines the JRE, JVM, compiler, and tools like javac, jar, and jshell to build, debug, and run Java applications.

JDK interview questions

JDK Interview Question 10 Questions

Click on any question to expand the answer.

0 of 10 Read

Interview Answer

The Java Development Kit (JDK) is a complete software development kit used to build Java applications. It includes the Java compiler, the Java Runtime Environment (JRE), the Java Virtual Machine (JVM), and various development tools. The JDK enables developers to write, compile, debug, test, package, and run Java programs.

Key Points

  • JDK stands for Java Development Kit.
  • It is required for Java application development.
  • It includes the JRE, JVM, compiler, and development tools.
  • It converts Java source code into bytecode.
  • It provides utilities for debugging, packaging, and documentation.

Interview Tips

  • Remember the formula: JDK = JRE + Development Tools.
  • Mention that every Java developer needs the JDK.

Summary

The JDK is the complete toolkit for Java development. It provides everything required to develop, test, and execute Java applications.

Interview Answer

The JDK is a software development kit used to create Java applications. The JRE provides the runtime environment needed to run Java programs, while the JVM is the engine that executes Java bytecode. In simple terms, the JDK is for development, the JRE is for execution, and the JVM performs the actual execution.

Key Points

ComponentPurpose
JDKDevelop, compile, debug, and run Java applications
JRERun compiled Java applications
JVMExecute Java bytecode and manage memory
  • JDK contains the JRE.
  • JRE contains the JVM.
  • The compiler (javac) is available only in the JDK.
  • The JVM cannot run independently without a runtime environment.

Interview Tips

  • Explain the relationship as JDK → JRE → JVM.
  • Clearly distinguish the responsibilities of each component.

Summary

The JDK, JRE, and JVM work together to develop and execute Java applications. Each component has a specific role in the Java platform.

Interview Answer

The JDK contains all the components required for Java development. It includes the JRE, JVM, Java compiler, standard class libraries, and several command-line tools for compiling, debugging, documenting, and packaging applications. Together, these components support the complete Java development lifecycle.

Key Points

  • JVM – Executes Java bytecode.
  • JRE – Provides the runtime environment.
  • Java Compiler (javac) – Converts source code into bytecode.
  • Java Class Libraries – Provide reusable APIs.
  • Development Tools – Include java, jar, javadoc, jdb, jshell, and others.

Interview Tips

  • Mention both runtime and development components.
  • Briefly explain the purpose of each major component.

Summary

The JDK combines runtime components and development tools into one package. It provides everything needed to build, test, and deploy Java applications.

Interview Answer

The JDK is required because it contains development tools such as the Java compiler, debugger, and documentation generator. These tools allow developers to create and compile Java source code. The JRE does not include these tools; it only provides the runtime environment needed to execute compiled Java programs.

Key Points

  • The JDK includes development tools.
  • The JRE includes only runtime components.
  • The javac compiler is available only in the JDK.
  • Java source code cannot be compiled using the JRE.
  • The JRE executes compiled .class files.

Interview Tips

  • Remember that the JRE cannot compile Java source code.
  • Explain that developers use the JDK, while end users generally need only a runtime environment.

Summary

The JDK supports both development and execution, whereas the JRE supports only execution. This makes the JDK essential for software development.

Interview Answer

The JDK provides several command-line tools that help developers compile, run, debug, document, package, and test Java applications. Each tool serves a specific purpose in the development process and improves productivity. Understanding these tools is important for both interviews and real-world Java development.

Key Points

  • javac – Compiles Java source code into bytecode.
  • java – Runs compiled Java applications.
  • jar – Creates and manages JAR files.
  • javadoc – Generates HTML documentation from source code.
  • jdb – Debugs Java applications.
  • jshell – Provides an interactive Java REPL for testing code snippets.

Syntax

javac Hello.java
java Hello
jar cf app.jar Hello.class
javadoc Hello.java
jdb Hello
jshell

Example

Compile and run a Java program:

javac Hello.java
java Hello

Output

Hello, World!

Interview Tips

  • Learn the purpose of each commonly used JDK tool.
  • javac and java are the most frequently asked commands in Java interviews.
  • Mention that jshell was introduced in Java 9 for interactive programming.

Summary

The JDK includes a rich set of tools for compiling, running, debugging, documenting, packaging, and testing Java applications. Knowing their purpose is essential for every Java developer.

Interview Answer

When you compile a Java program, the javac compiler converts the source code (.java) into platform-independent bytecode (.class). When you run the program using the java command, the JVM loads the bytecode, verifies it for security, allocates memory, and executes it using the Interpreter and JIT Compiler. During execution, the Garbage Collector automatically reclaims unused memory.

Key Points

  • javac compiles .java files into .class files.
  • The java command starts the JVM.
  • The Class Loader loads the required classes.
  • The Bytecode Verifier checks code safety.
  • The Execution Engine executes bytecode using the Interpreter and JIT Compiler.
  • The Garbage Collector manages memory automatically.

Syntax

javac Hello.java
java Hello

Example

Compile and execute a Java program:

javac Hello.java
java Hello

Output

Hello, World!

Interview Tips

  • Explain the execution flow in the correct order: Source Code → Compiler → Bytecode → JVM → Machine Code.
  • Mention the roles of the Class Loader, JIT Compiler, and Garbage Collector.

Summary

The JDK compiles Java source code into bytecode, and the JVM executes that bytecode. This process enables Java programs to run on any platform with a compatible JVM.

Interview Answer

OpenJDK is the open-source reference implementation of Java and serves as the foundation for most JDK distributions. Oracle JDK is Oracle's commercial build of OpenJDK and may include additional support and enterprise features. Other distributions, such as Eclipse Temurin, Amazon Corretto, Azul Zulu, and Microsoft Build of OpenJDK, are OpenJDK-based builds that offer different support models and optimizations.

Key Points

DistributionDescription
OpenJDKOpen-source reference implementation of Java
Oracle JDKCommercial build with Oracle support
Eclipse TemurinFree OpenJDK distribution maintained by the Eclipse Foundation
Amazon CorrettoFree OpenJDK distribution with long-term support from Amazon
Azul ZuluEnterprise-ready OpenJDK distribution with extended support
Microsoft Build of OpenJDKOptimized OpenJDK distribution maintained by Microsoft
  • Most distributions are compatible with Java standards.
  • The main differences are licensing, support, updates, and vendor-specific optimizations.

Interview Tips

  • Recommend Eclipse Temurin or OpenJDK for most developers.
  • Mention Oracle JDK when enterprise support from Oracle is specifically required.

Summary

Most modern JDK distributions are built from OpenJDK and are functionally compatible. The choice depends mainly on licensing, support requirements, and organizational preferences.

Interview Answer

Install the JDK from a trusted distribution, then configure the JAVA_HOME environment variable to point to the JDK installation directory. Add the JDK's bin directory to the PATH so Java commands can be executed from any terminal. Finally, verify the installation using the java and javac version commands.

Key Points

  • Download and install the desired JDK.
  • Set JAVA_HOME to the JDK installation directory.
  • Add %JAVA_HOME%\bin (Windows) or $JAVA_HOME/bin (Linux/macOS) to the PATH.
  • Restart the terminal after updating environment variables.
  • Verify the installation using version commands.

Syntax

Windows:

set JAVA_HOME=C:\Program Files\Java\jdk-21
set PATH=%JAVA_HOME%\bin;%PATH%
java -version
javac -version

Linux/macOS:

export JAVA_HOME=/usr/lib/jvm/jdk-21
export PATH=$JAVA_HOME/bin:$PATH
java -version
javac -version

Output

java version "21"
javac 21

Interview Tips

  • Always verify both java -version and javac -version.
  • Ensure that JAVA_HOME points to the JDK, not the JRE.

Summary

Properly configuring JAVA_HOME and PATH allows Java tools to be accessed from anywhere. Verification confirms that the JDK is installed and configured correctly.

Interview Answer

Multiple JDK versions can be managed by installing each version in a separate directory and switching between them using environment variables or version management tools. Enterprise projects often depend on specific Java versions, so maintaining multiple JDKs ensures compatibility with different applications and frameworks.

Key Points

  • Install each JDK in a separate location.
  • Update JAVA_HOME to switch between versions.
  • Modify the PATH to use the selected JDK.
  • Use version managers such as SDKMAN! or package managers where supported.
  • Different projects may require different Java versions.

Interview Tips

  • Mention that legacy applications often cannot be upgraded immediately.
  • Explain that multiple JDK versions improve compatibility and testing.

Summary

Managing multiple JDK versions allows developers to work on projects with different Java requirements. It is a common practice in enterprise software development.