53

I tried java --version in the command line and I get :

Unrecognized option: --version
Error: Could not create the Java virtual machine
Error: A fatal exception has occurred. Program will exit.

Everything was working fine until I installed jre 7 (I had jdk 1.6 preinstalled ) So, I uninstalled the previous versions, restarted and then installed fresh jdk 7u5 windows i586.

Still I get the same problem. Can anyone help me with this?
I am unable to install and run maven for this reason.

Pshemo
125k26 gold badges194 silver badges280 bronze badges
asked Jul 18, 2012 at 23:31
3
  • 2
    For what it's worth, java -help prints out usage information; doing that would've given you the solution immediately. Commented Jul 18, 2012 at 23:40
  • 1
    @DennisMeng yes, if you know that you need to write just one dash. Commented Jun 24, 2020 at 11:39
  • @NilsLindemann that is why most tools come with documentation even back in 2012 (and, at least actual versions, also accept --help) Commented Nov 19, 2023 at 10:04

3 Answers 3

123

You used two - marks. Try with one: java -version.

Update: Since Java 9 java and javac commands support both --version and -version.


Bonus:

As mentioned by Stephen C java --help states (at least in recent versions supporting --version) that

-version print product version to the error stream and exit
--version print product version to the output stream and exit

This means that if you try to execute java -version programmatically, for instance via Process you will need to read its result from Process#getErrorStream() instead of Process#getOutputStream().

Such behavior can be also observed in other java options which have - and -- versions. For instance -h or -? or -help will print to error stream, while --help will print to output stream.

answered Jul 18, 2012 at 23:33
Sign up to request clarification or add additional context in comments.

2 Comments

There is a subtle difference between -version and --version. The former outputs to standard error, while the latter outputs to standard output ... as is the standard behavior for --version options on Linux, MacOS, etc. (This is mentioned by java --help ... at least on recent versions of Java that support the --version form.)
@StephenC That is very interesting. Thank you for sharing. Added this to an answer.
5
java -version

This is the command to get the current installed version info

answered Jul 15, 2021 at 16:01

1 Comment

This basically repeats the information provided in the answer from Pshemo from 2012.
0

For me the following command works: java -version instead of this: java --version

answered Mar 16, 2024 at 7:51

1 Comment

Pardon me, but I don't see how your answer adds anything that does not already appear in the other answers and since you posted your answer nearly twelve years after the question was originally posted, there is no excuse for repeating an existing answer (in my opinion). Please correct me if I have missed something in your answer. By the way (and not directly related to your answer), I suggest that you learn how to use markdown.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.