杰瑞科技汇

Java、Windows、SO如何协同工作?

Of course! It looks like you're asking about Java on the Windows operating system. This is a very common topic.

Java、Windows、SO如何协同工作?-图1
(图片来源网络,侵删)

Let's break it down into the key concepts you need to know.

What is Java on Windows?

Java is a programming language and a computing platform. On Windows, it means you can:

  • Run Java Applications: Many popular programs, especially enterprise software, scientific tools, and games, are built on Java. If you see a .jar file, that's a Java application.
  • Develop Java Programs: You can write, compile, and run your own Java code on a Windows machine.

The core component that makes this possible is the Java Runtime Environment (JRE) or its more modern successor, the Java Platform, Standard Edition (Java SE).


Key Components You Need to Know

a) Java Development Kit (JDK)

This is what you need if you want to develop Java applications.

Java、Windows、SO如何协同工作?-图2
(图片来源网络,侵删)
  • What it includes: It contains everything in the JTE, plus:
    • The Java Compiler (javac): Translates your human-readable Java code into Java bytecode (.class files).
    • Debugging Tools: Help you find and fix errors in your code.
    • Documentation APIs: References for all the Java libraries.
  • Who needs it? Programmers, software developers, and students learning Java.

b) Java Runtime Environment (JRE) / Java SE Runtime Environment (JRE)

This is what you need if you only want to run Java applications (not create them).

  • What it includes: It contains the essential parts to execute Java bytecode:
    • The Java Virtual Machine (JVM): This is the magic "virtual computer" that runs Java bytecode. It's the heart of Java's "write once, run anywhere" capability.
    • Core Libraries: Pre-built code for common tasks (like handling data, networking, etc.).
    • Other Components: Like the Java Plug-in (for running Java in web browsers, though this is now largely deprecated).
  • Who needs it? End-users who want to run software that requires Java (e.g., Minecraft, some Eclipse IDE versions, financial tools).

Important Note: Oracle now bundles the JRE inside the JDK. So, if you install the JDK, you automatically get the JRE. You no longer need to download them separately.


How to Install Java on Windows

Here is a step-by-step guide for the most common scenario: installing the JDK.

Step 1: Download the JDK

  1. Go to the official Oracle Java downloads page: https://www.oracle.com/java/technologies/downloads/
  2. Select the latest version of Java LTS (Long-Term Support). For most users, this is the best choice (e.g., Java 21, Java 17, or Java 11).
  3. Under the "Windows x64 Installer" section, click the download link. You will need to accept the Oracle license agreement.

Step 2: Install the JDK

  1. Find the downloaded .exe file (e.g., jdk-21_windows-x64_bin.exe) in your Downloads folder and double-click it.
  2. The installer wizard will open. Click "Next".
  3. You can change the installation directory if you wish, but the default is usually fine. Click "Next" again.
  4. The installer will extract and copy the files. This may take a minute.
  5. Once it's done, click "Close".

Step 3: Configure Environment Variables (Crucial Step!)

The Windows command line needs to know where to find the Java tools (java, javac). You do this by setting environment variables.

  1. Open the Start Menu, type env, and select "Edit the system environment variables".
  2. In the System Properties window, click the "Environment Variables..." button.
  3. In the "System variables" section (the bottom half), find and select the Path variable, then click "Edit...".
  4. Click "New" and add the following two paths. Make sure to replace C:\Program Files\Java\jdk-21 with your actual installation path if you changed it.
    • C:\Program Files\Java\jdk-21\bin
    • C:\Program Files\Java\jdk-21\lib (This is often not strictly necessary but good practice)
  5. Click "OK" on all the windows to save your changes.

Step 4: Verify the Installation

  1. Open a new Command Prompt or PowerShell window. (It's important to open a new one so it reads the new environment variables).

  2. Type the following commands and press Enter after each:

    java -version

    You should see output like this:

    java version "21.0.1" 2025-10-17
    Java(TM) SE Runtime Environment (build 21.0.1+12-LTS-29)
    Java HotSpot(TM) 64-Bit Server VM (build 21.0.1+12-LTS-29, mixed mode, sharing)
    javac -version

    You should see output like this:

    javac 21.0.1

If both commands work and show version numbers, your Java installation is successful!


Popular Java Software on Windows

  • Minecraft: The original Java version of the game requires the JRE to run.
  • Eclipse IDE: A very popular free, open-source Integrated Development Environment (IDE) for Java development.
  • IntelliJ IDEA: Another powerful IDE, made by JetBrains, with a free community edition.
  • Apache NetBeans: A classic, free, open-source IDE.
  • Enterprise Applications: Many large-scale business applications (e.g., banking systems, logistics software) are built on Java and run on Windows servers.

Common Issues & FAQs

  • Q: 'java' is not recognized as an internal or external command...

    • A: This is the most common error. It means the Path environment variable is not set correctly. Go back to Step 3 and make sure the path to the JDK's bin directory is added and saved correctly. Remember to open a new command prompt.
  • Q: Which JDK version should I download?

    • A: For beginners and most projects, download the latest LTS (Long-Term Support) version (like Java 21 or 17). These versions are supported for many years and are very stable. Use non-LTS versions (like Java 20) only if you need the latest features and are okay with potential changes.
  • Q: Do I need to uninstall old Java versions?

    • A: Generally, no. You can have multiple versions of Java installed. The java -version command will typically use the one listed first in your Path variable. If you want to switch versions, you can edit the Path variable to point to the bin directory of the desired JDK.

I hope this detailed guide helps you get started with Java on Windows

分享:
扫描分享到社交APP
上一篇
下一篇