1

In my C:\Program files\java folder I have three folders:

jdk1.6.0_45
jre6
jre7

However typing the command java -version in the command prompt gives the following output:

java version "1.7.0_51"

How does that make sense? I think it should have outputed jdk1.6.0_45. How can this be explained?

8
  • Why do you think it should have printed a version corresponding to Java 6? Commented May 1, 2014 at 22:33
  • 1
    The java command invokes the Java interpreter not the compiler so it would be found in a JRE package (i.e. jre7). Commented May 1, 2014 at 22:33
  • @Elliott If I want to compile using JDK7, should I be able to do that? Commented May 1, 2014 at 22:36
  • @Prog You need to install a JDK7 package (just go download latest version!) and then use the javac command to compile. :) Commented May 1, 2014 at 22:37
  • @Elliott I see. What does it actually mean to compile using JDK X instead of JDK Y? Is it that a program compiled with JDK X will be able to run on JRE X and a program compiled with JDK Y will be able to run on JRE Y? Commented May 1, 2014 at 22:39

4 Answers 4

1

Already answered this in the comments thread but for future reference:

Broadly speaking, the JDK package determines the version of the Java compiler (javac) you have and the JRE package determines the version of the Java interpreter (java) you have.

The version that is run when you type java or javac in the command line is the version that is listed in your PATH environmental variable, which will generally point to the newest version from the newest package (the Java installer does this for you).

The JDK will install the corresponding JRE at the same time so you'll have the same version of java and javac by just installing the latest JDK.

Sign up to request clarification or add additional context in comments.

1 Comment

After installing a new JDK (and JRE), do I need to 'tell Java' to 'connect' to the new JDK? Or is it enough to just download and install it?
1

Perhaps it finds have from inside the jre7 folder? You can check your PATH to see where it finds executables.

Comments

0

You have a jre7 so I assume it is update 51

Java takes the newest version by default.

Comments

0

It could also be if and where the JAVA_HOME ENV points to.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.