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.
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
| Component | Purpose |
|---|---|
| JDK | Develop, compile, debug, and run Java applications |
| JRE | Run compiled Java applications |
| JVM | Execute 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
javaccompiler is available only in the JDK. - Java source code cannot be compiled using the JRE.
- The JRE executes compiled
.classfiles.
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
jshellExample
Compile and run a Java program:
javac Hello.java
java HelloOutput
Hello, World!Interview Tips
- Learn the purpose of each commonly used JDK tool.
javacandjavaare the most frequently asked commands in Java interviews.- Mention that
jshellwas 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
javaccompiles.javafiles into.classfiles.- The
javacommand 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 HelloExample
Compile and execute a Java program:
javac Hello.java
java HelloOutput
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
| Distribution | Description |
|---|---|
| OpenJDK | Open-source reference implementation of Java |
| Oracle JDK | Commercial build with Oracle support |
| Eclipse Temurin | Free OpenJDK distribution maintained by the Eclipse Foundation |
| Amazon Corretto | Free OpenJDK distribution with long-term support from Amazon |
| Azul Zulu | Enterprise-ready OpenJDK distribution with extended support |
| Microsoft Build of OpenJDK | Optimized 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_HOMEto the JDK installation directory. - Add
%JAVA_HOME%\bin(Windows) or$JAVA_HOME/bin(Linux/macOS) to thePATH. - 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 -versionLinux/macOS:
export JAVA_HOME=/usr/lib/jvm/jdk-21
export PATH=$JAVA_HOME/bin:$PATH
java -version
javac -versionOutput
java version "21"
javac 21Interview Tips
- Always verify both
java -versionandjavac -version. - Ensure that
JAVA_HOMEpoints 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_HOMEto switch between versions. - Modify the
PATHto 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.
Interview Answer
Modern JDK releases introduced several features that improve application modularity, developer productivity, code readability, and application performance. Features such as the Module System, jshell, jlink, Records, Sealed Classes, and Virtual Threads simplify development while making Java applications more efficient, scalable, and maintainable.
Key Points
- Module System (Java 9) – Improves modularity and dependency management.
jshell(Java 9) – Enables interactive Java programming.jlink(Java 9) – Creates custom runtime images.- Records (Java 16) – Reduce boilerplate code for immutable data classes.
- Sealed Classes (Java 17) – Restrict class inheritance for better design.
- Virtual Threads (Java 21) – Improve scalability for concurrent applications.
Interview Tips
- Remember the major features introduced in Java 9, 16, 17, and 21.
- Explain the practical benefit of each feature rather than only naming it.
Summary
Modern JDK releases have significantly enhanced Java by introducing features that improve modularity, simplify coding, strengthen application design, and increase scalability. These improvements help developers build more efficient and maintainable applications.