简体   繁体   English

关于Java版本的困惑

[英]Confusion about Java Versions

So I'm trying to get the latest version of Java. 因此,我正在尝试获取Java的最新版本。 When I run: 当我跑步时:

java -version Java版本

I get: 我得到:

java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

When I run: 当我跑步时:

javac -version javac-版本

I get: 我得到:

javac 1.6.0_65

Now I've just downloaded and installed JDK 8. When I go into System Preferences --> Java --> Update, I see: 现在,我刚刚下载并安装了JDK8。当我进入系统偏好设置-> Java->更新时,我看到:

Your system has the recommended vesion of Java.

Java 8 Update 05.

I guess I have a few questions: 我想我有几个问题:

1) Don't I want the JDK and my version of Java to match up? 1)我不希望JDK和我的Java版本匹配吗?

2) Why does my Java Control Panel claim I have Java 8, but my work in the terminal (when checking my Java version) says otherwise? 2)为什么我的Java控制面板声称我有Java 8,但是我在终端上的工作(在检查Java版本时)却相反?

Thanks for the help, Mariogs 感谢您的帮助,Mariogs

The Java Platform offers both the JRE and the JDK in order for users to run Java programs. Java平台同时提供JREJDK ,以便用户运行Java程序。 The JRE stands for the Java Runtime Environment, and the JDK stands for the Java Development Kit. JRE代表Java运行时环境,而JDK代表Java开发工具包。

The JDK is meant for Java developers - that is, those who build applications/write programs in Java. JDK适用于Java开发人员,即使用Java构建应用程序/编写程序的开发人员。 It contains tools that are needed for Java coding, including -javac to compile programs. 它包含Java编码所需的工具,包括-javac来编译程序。

The JRE is meant for regular users - those who only need to run Java programs on their computer and are not interested in development. JRE适用于普通用户-那些只需要在计算机上运行Java程序并且对开发不感兴趣的用户。

The reason for the discrepancy in your case is because you're looking at the JRE and JDK and trying to compare the two. 这种情况下出现差异的原因是因为您正在查看JRE和JDK并试图将两者进行比较。 The current JDK that you have is Java 8 , whereas the current JRE that you have is 1.6.0_65 . 您拥有的当前JDK是Java 8 ,而您拥有的当前JRE是1.6.0_65 It is problematic that your JRE version does not match your JDK version, but without your PATH variable or other information about your install, we can't help you fix your installation. 问题是您的JRE版本与您的JDK版本不匹配,但是如果没有PATH变量或有关安装的其他信息,我们将无法帮助您修复安装。

The probably "simple" answer is you have two versions of java installed. 可能的“简单”答案是您安装了两个版本的java。 On the command line you currently use 1.6. 在命令行上,您当前使用1.6。 Thus the old one is active. 因此,旧的是活跃的。 In system preferences you see the version of java 8. 在系统偏好设置中,您会看到Java 8的版本。

Windows: You can change the version of the command line to java 8. Set PATH environment variable and JAVA_HOME or via windows preferences. Windows:您可以将命令行版本更改为Java8。设置PATH环境变量和JAVA_HOME或通过Windows首选项设置。 I recommend the first one. 我推荐第一个。

Mac: /usr/libexec/java_home is the starting point for switching java versions on the command line. Mac: /usr/libexec/java_home是在命令行上切换Java版本的起点。 Check out this post to understand how to handle different java versions on the Mac. 查看这篇文章,以了解如何在Mac上处理不同的Java版本。 IMHO this answer is a good solution. 恕我直言, 这个答案是一个很好的解决方案。

1) Yes, if you use the JDK at all, you want the JRE (runtime environment) to come from the JDK (development environment) (a JDK necessarily includes a JRE). 1)是的,如果您完全使用JDK,则希望JRE(运行时环境)来自JDK(开发环境)(JDK必须包含JRE)。

2) Likely your path variable is set so that you invoke Java from your Java 6 installation; 2)可能设置了path变量,以便您从Java 6安装中调用Java; you need to find the equivalent for your Java 8 installation and set the path for that. 您需要找到与Java 8安装等效的文件并为其设置路径。 Without information about your operating system, we can't help you do that. 没有有关您的操作系统的信息,我们将无法帮助您。

Following are the things we should know 以下是我们应该知道的事情

  1. Our OS comes with predefined (built-in)set of tools and utilities. 我们的操作系统附带了预定义(内置)的工具和实用程序集。 When we try to execute command eg cls in windows command line then it is already present in system path variable and os will refer the corresponding binary of cls to execute the command. 当我们尝试在Windows命令行中执行命令( 例如cls)时 ,它已经存在于系统路径变量中,并且os将引用相应的cls二进制文件来执行命令。

  2. However, when we install any third party tool/software then path variable is not updated accordingly. 但是,当我们安装任何第三方工具/软件时, 路径变量不会相应更新。

  3. Eg When we install different versions of java on your system then installations goes to different directories. 例如,当我们在您的系统上安装不同版本的Java时,安装将转到不同的目录。 Eg for JDK: 例如, 对于JDK:

      ==> C:\\Program Files\\Java\\jdk1.8.0_161 

and for JRE: ==> C:\\Program Files\\Java\\jre1.8.0_161 对于JRE: ==> C:\\Program Files\\Java\\jre1.8.0_161

  1. We need to update path variable of OS to point to appropriate directory. 我们需要更新OS的路径变量以指向适当的目录。 If we set path of JDK then it will execute binary from JDK bin directory. 如果我们设置JDK的路径,那么它将从JDK bin目录执行二进制文件。

Let me see if I can clear it up for you. 让我看看是否可以帮您清理一下。

1)Yes, arguably you nearly want this to be true. 1)是的,可以说您几乎希望做到这一点。

2)It could be few things, but most likely that a previous instillation was not properly removed. 2)可能没什么事,但很可能是以前的灌输没有正确清除。 So one gets called instead of the other. 因此,一个被调用而不是另一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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