How to Install and Switch Between Multiple JDKs on Windows
This tutorial explains how to install Java 7 and Java 8 on Windows, configure version-specific environment variables (JAVA_HOME7, JAVA_HOME8), set classpath and PATH dynamically, remove system Java executables, and verify the active JDK version using the command line.
Overview
The author describes a practical setup for running both Java 7 and Java 8 on a single Windows machine. The need arises from a new project requiring Java 7 while an existing environment uses Java 8.
Prerequisites
Download the desired JDK versions from Oracle's official website or a trusted historical archive. The author references a blog post for downloading older versions: "从官网下载历史版本的java - DbWong_0918 - 博客园 (cnblogs.com)".
Installation Directories
The example installation paths used in this guide are:
Java 7: C:\Program Files\Java\jdk1.7.0_80 Java 8:
C:\Program Files\Java\jdk1.8.0_291Environment Variable Configuration
Create two system variables, one for each JDK version: JAVA_HOME7 =
C:\Program Files\Java\jdk1.7.0_80 JAVA_HOME8= C:\Program Files\Java\jdk1.8.0_291 Then create a master JAVA_HOME variable that points to the desired version by referencing the corresponding version-specific variable. For example, to use Java 7, set JAVA_HOME to %JAVA_HOME7%.
Set the CLASSPATH variable to: .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar Update the system PATH variable: remove any existing %JAVA_HOME% entries and prepend the following entries so they take precedence: %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin; Place these entries at the very top of the PATH list.
Remove System-Wide Java Executables
Navigate to C:\Windows\System32 and delete java.exe, javaw.exe, and javaws.exe. This prevents the system from using a globally installed Java version that could conflict with the version selected via JAVA_HOME.
Verification
Open a new Command Prompt window and run: java -version The output should display the version corresponding to the currently active JAVA_HOME (e.g., Java 7).
Reference Screenshot
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Captain
Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
