简体   繁体   中英

Running Java Programs in Windows 10 Command Prompt

I recently downloaded Java SDK 8.0 on my computer running Windows 10. However, when I looked on the Internet for how to use Java in the Windows 10 Command Prompt, I was only able to get the javac command to work in the prompt. When I tried to run my program, the command prompt said that it could not find the java.exe file. Does anyone know how to make Java work in Windows 10? (I'm using the x86 version of Java.)

打开命令提示符cmd并输入where java ,它将输出java可执行文件所在的位置,然后您可以转到System Propreties>Advanced>Environement Variables> (右键单击计算机,然后单击属性),然后将where java输出添加到PATH变量中用分号分隔;

Java doesn't actually have to be installed . You can run any Java that's available to you.

This is sometimes useful for running Java from a network share.

Try running the java.exe program by fully qualifying it. If it runs that way, your problem is with your PATH .


To illustrate that you can run any Java by qualifing it, I have 9 JDK's and 1 JRE installed:

  • 32-bit JDK: Versions 1.4, 5, 6, 7, and 8
  • 64-bit JDK: Versions 5, 6, 7, and 8
  • 32-bit JRE: Version 8

Copied from a single command prompt window:

C:\>"C:\prog\java32\jdk1.4.2_19\bin\java.exe" -version
java version "1.4.2_19"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_19-b04)
Java HotSpot(TM) Client VM (build 1.4.2_19-b04, mixed mode)

C:\>"C:\prog\java32\jdk1.5.0_22\bin\java.exe" -version
java version "1.5.0_22"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03)
Java HotSpot(TM) Client VM (build 1.5.0_22-b03, mixed mode)

C:\>"C:\prog\java32\jdk1.6.0_45\bin\java.exe" -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) Client VM (build 20.45-b01, mixed mode, sharing)

C:\>"C:\prog\java32\jdk1.7.0_79\bin\java.exe" -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) Client VM (build 24.79-b02, mixed mode, sharing)

C:\>"C:\prog\java32\jdk1.8.0_51\bin\java.exe" -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) Client VM (build 25.51-b03, mixed mode)

C:\>"C:\prog\java64\jdk1.5.0_22\bin\java.exe" -version
java version "1.5.0_22"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03)
Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_22-b03, mixed mode)

C:\>"C:\prog\java64\jdk1.6.0_45\bin\java.exe" -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

C:\>"C:\prog\java64\jdk1.7.0_79\bin\java.exe" -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

C:\>"C:\prog\java64\jdk1.8.0_51\bin\java.exe" -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

C:\>"C:\Program Files (x86)\Java\jre1.8.0_51\bin\java.exe" -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) Client VM (build 25.51-b03, mixed mode, sharing)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM