Java Introduction Chapter
Java Installation Interview Questions and Answers
Learn how to install the JDK, configure JAVA_HOME and PATH, and verify your Java setup on Windows, Linux, and macOS.
History of Java interview questions
Java Installation Interview Question 10 Questions
Click on any question to expand the answer.
Interview Answer
Before installing Java, confirm that the operating system and processor architecture are supported by the selected JDK distribution. You need sufficient disk space, permission to install software, and the correct installer for Windows, Linux, or macOS. Administrative access is generally required for system-wide installation, while archive-based installations can often be performed without it.
Key Points
- Identify the operating system: Windows, Linux, or macOS.
- Check whether the processor uses x64 or ARM64 architecture.
- Download the JDK from an official or trusted distributor.
- Ensure sufficient storage space is available.
- Obtain administrator or root access for system-wide installation.
- Check the version required by the project or development tools.
Interview Tips
- Always select an installer that matches the operating system and processor.
- Mention that developers require the JDK rather than only a runtime.
- Check project compatibility before selecting a Java version.
Summary
Java installation requires a supported operating system, suitable hardware architecture, disk space, and installation permissions. Selecting the correct JDK version and installer prevents most installation problems.
Interview Answer
The JDK contains the tools required to develop and run Java applications, including the javac compiler, Java launcher, debugger, and runtime components. The JRE provides only the environment needed to run Java applications and does not contain development tools such as javac. Developers should install the JDK because it supports both compilation and execution.
Key Points
| JDK | JRE |
|---|---|
| Used to develop and run applications | Used only to run applications |
| Contains the javac compiler | Does not contain javac |
| Contains development and diagnostic tools | Contains runtime components |
| Suitable for developers | Traditionally suitable for end users |
| Can compile and execute programs | Cannot compile source code |
- Modern Java development normally uses a complete JDK.
- Separate public JRE downloads are mainly associated with legacy Java 8 distributions.
- As of July 2026, JDK 26 is the latest Java release, while JDK 25 is the latest LTS release.
Interview Tips
- Remember the relationship: JDK includes development tools and runtime capabilities.
- A JRE cannot compile a Java source file because it does not provide javac.
- Developers should normally choose an LTS JDK when long-term stability is required.
Summary
The JDK supports both Java development and execution, whereas the JRE supports only execution. Therefore, developers should install a JDK.
Interview Answer
Download a trusted JDK distribution that matches the operating system and processor architecture. Windows commonly uses an EXE or MSI installer, Linux supports archive, Debian, and RPM packages, while macOS supports DMG installers and compressed archives. After installation, configure JAVA_HOME and PATH when required by development tools or build systems.
Key Points
- Select the Java version required by the project.
- Select x64 or ARM64 according to the processor.
- Use an official or trusted JDK distribution.
- Complete the operating-system-specific installation.
- Configure environment variables when necessary.
- Verify both the Java launcher and compiler.
Syntax
Windows
- Download the Windows EXE or MSI installer.
- Run the installer with administrative permission.
- Select the installation directory.
- Complete the installation.
- Configure JAVA_HOME and PATH.
An MSI installer can also be installed from an administrator terminal.
msiexec.exe /i jdk-<version>_windows-x64_bin.msiDebian-Based Linux
Oracle provides Debian packages for system-wide installation and compressed archives for private installation.
sudo dpkg -i jdk-<version>_linux-x64_bin.debRPM-Based Linux
sudo rpm -ivh jdk-<version>_linux-x64_bin.rpmLinux Archive Installation
tar -xzf jdk-<version>_linux-x64_bin.tar.gz
sudo mv jdk-<version> /opt/java/macOS
- Download the DMG matching Intel x64 or Apple Silicon ARM64.
- Open the DMG file.
- Run the PKG installer.
- Enter administrator credentials.
- Complete the installation.
Oracle JDK installations are normally placed under /Library/Java/JavaVirtualMachines.
Interview Tips
- Do not install an ARM64 JDK on an x64 system or vice versa.
- Linux installation commands depend on the package format and distribution.
- Verify the installation before configuring an IDE.
Summary
Java installation differs mainly in the installer format used by each operating system. The final objective is the same: install the JDK, configure its location, and verify the Java tools.
Interview Answer
JAVA_HOME should point to the JDK installation directory, not its bin directory. PATH should include the JAVA_HOME/bin directory so commands such as java and javac can be executed from any terminal location. Incorrect or conflicting PATH entries can cause the system to use a different Java version.
Key Points
- JAVA_HOME stores the JDK installation path.
- JAVA_HOME must not end with the bin directory.
- PATH should include JAVA_HOME/bin.
- Existing PATH values should not be deleted.
- Restart the terminal after changing variables.
- Verify that java and javac resolve to the expected JDK.
Syntax
Windows
Set the following system variable:
JAVA_HOME=C:\Program Files\Java\jdk-25Add this entry to PATH:
%JAVA_HOME%\binVerify the configuration:
echo %JAVA_HOME%
where java
where javac
java -version
javac -versionLinux
Add the following lines to .bashrc, .profile, or the appropriate shell configuration file:
export JAVA_HOME=/opt/java/jdk-25
export PATH="$JAVA_HOME/bin:$PATH"Reload and verify:
source ~/.bashrc
echo $JAVA_HOME
which java
which javac
java -version
javac -versionmacOS
The java_home utility can locate an installed JDK version on macOS.
export JAVA_HOME=$(/usr/libexec/java_home -v 25)
export PATH="$JAVA_HOME/bin:$PATH"Add these lines to .zshrc and reload it:
source ~/.zshrc
echo $JAVA_HOME
which java
which javacInterview Tips
- JAVA_HOME points to the JDK root; PATH points to its bin directory.
- Use where on Windows and which on Linux or macOS to detect conflicting installations.
- A correct java command does not guarantee that javac is available.
Summary
JAVA_HOME identifies the JDK installation, while PATH makes its commands globally accessible. Both variables should reference the same JDK version to avoid configuration conflicts.
Interview Answer
Run java -version to verify the runtime and javac -version to verify the compiler. If both commands return the expected version, the JDK is available through PATH. A final verification is to compile and execute a small Java program. The java launcher starts the JVM, while javac compiles source files into class files.
Key Points
- java -version verifies the Java runtime.
- javac -version verifies the Java compiler.
- JAVA_HOME should point to the expected JDK.
- java and javac should resolve from the same installation.
- Successful compilation generates a .class file.
- Successful execution confirms the complete setup.
Syntax
java -version
javac -version
echo %JAVA_HOME%On Linux or macOS:
echo $JAVA_HOMEExample
Create Hello.java:
public class Hello {
public static void main(String[] args) {
System.out.println("Java installed successfully");
}
}Compile and run it:
javac Hello.java
java HelloOutput
Java installed successfullyInterview Tips
- If java works but javac does not, only a runtime may be available or PATH may be incorrect.
- Never include the .class extension when executing a class with the java command.
- Check the displayed versions when multiple JDKs are installed.
Summary
A correct Java installation should provide both java and javac commands. Successfully compiling and running a test program confirms that the JDK, JVM, and environment variables are configured correctly.
Interview Answer
java -version checks the installed Java Runtime version used to run Java programs. javac -version checks the Java compiler version available in the JDK. java --version is a newer long-form command that also displays Java runtime version details.
Key Points
- java runs Java bytecode
- javac compiles .java files into .class files
- java -version prints runtime version
- javac -version prints compiler version
- java --version is supported in newer Java versions
- If javac is missing, JDK is not configured properly
Syntax
java -version
javac -version
java --versionExample
java -version
javac -versionInterview Tips
- Remember java means runtime, javac means compiler.
- If only java works but javac fails, JRE or PATH setup may be incomplete.
- Developers should install JDK, not only JRE.
Summary
java checks the runtime, while javac checks the compiler. These commands help verify whether Java is installed and configured correctly.
Interview Answer
Multiple Java versions can be installed on the same system by placing each JDK in a separate directory. The active Java version is controlled using JAVA_HOME and PATH. Tools like SDKMAN, jEnv, update-alternatives, or IDE settings can make version switching easier.
Key Points
- Install each JDK separately
- Set JAVA_HOME to the required JDK path
- Add JAVA_HOME/bin to PATH
- Use version managers for easy switching
- IDEs can use project-specific JDKs
- Build tools like Maven and Gradle can also use selected Java versions
Syntax
set JAVA_HOME=C:\Java\jdk-17
set PATH=%JAVA_HOME%\bin;%PATH%Example
java -version
javac -versionInterview Tips
- Explain both manual setup and tool-based setup.
- Mention project-specific Java versions.
- Always verify both java and javac versions after switching.
Summary
Multiple Java versions are managed by changing JAVA_HOME and PATH. Version managers and IDE configurations make this process safer and faster.
Interview Answer
Common Java installation errors include java not recognized, javac not found, wrong Java version, and incorrect JAVA_HOME path. These issues usually happen because the JDK is not installed correctly or environment variables are wrongly configured. Troubleshooting starts by checking installation path, JAVA_HOME, PATH, and version commands.
Key Points
- java not recognized means PATH is missing Java bin
- javac not found usually means JDK is missing or PATH is wrong
- Wrong version means another Java path is used first
- JAVA_HOME should point to JDK root, not bin
- Restart terminal after changing environment variables
- Verify using java -version and javac -version
Example
JAVA_HOME=C:\Program Files\Java\jdk-17
PATH=%JAVA_HOME%\binInterview Tips
- Say that JAVA_HOME should not point to the bin folder.
- Check PATH order when multiple Java versions exist.
- Always restart terminal after environment changes.
Summary
Most Java setup errors are related to incorrect PATH or JAVA_HOME values. Correcting environment variables and verifying commands solves most installation issues.
Interview Answer
OpenJDK is the open-source reference implementation of Java. Oracle JDK is Oracle’s build of the JDK, often used in enterprise environments with Oracle support. Other distributions like Temurin, Amazon Corretto, Microsoft Build of OpenJDK, and Azul Zulu provide production-ready OpenJDK builds.
Key Points
- OpenJDK is open source
- Oracle JDK is maintained by Oracle
- Other JDK builds are based on OpenJDK
- Licensing and support can differ
- Performance is usually similar for most applications
- Choose an LTS version for production projects
Interview Tips
- Do not say Oracle JDK and OpenJDK are completely different Java versions.
- Mention licensing and support as key differences.
- For learning, OpenJDK or Temurin is usually enough.
Summary
Oracle JDK, OpenJDK, and other JDK distributions provide Java development tools. The best choice depends on licensing, support, company policy, and production requirements.
Interview Answer
Java setup starts by installing the JDK, which contains the compiler, runtime tools, libraries, and JVM. JAVA_HOME points to the JDK installation folder, while PATH allows the system to access java and javac commands from anywhere. The javac compiler converts source code into bytecode, and the JVM executes that bytecode.
Key Points
- JDK is required for Java development
- JAVA_HOME stores the JDK location
- PATH provides access to Java commands
- javac compiles .java files
- JVM runs .class bytecode files
- Java execution is platform-independent because of bytecode and JVM
Example
JDK Installation
|
v
JAVA_HOME = JDK Folder
|
v
PATH = JAVA_HOME/bin
|
v
Hello.java
|
v
javac Hello.java
|
v
Hello.class
|
v
java Hello
|
v
JVM executes bytecode
|
v
Program OutputOutput
Program runs successfully when JDK, JAVA_HOME, PATH, javac, and JVM are configured correctly.
Interview Tips
- Explain the flow from source code to output.
- Clearly separate compiler and JVM responsibilities.
- Mention that javac creates bytecode, not machine code directly.
- Connect PATH with command execution from terminal.
Summary
The JDK provides everything needed to compile and run Java programs. JAVA_HOME and PATH configure the system, javac compiles code, and JVM executes the generated bytecode.