Deepak behera
Deepak behera

Reputation: 681

java --version doesn't work in the command line

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.

Upvotes: 52

Views: 60167

Answers (3)

Traore Bakary
Traore Bakary

Reputation: 1

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

Upvotes: 0

Pshemo
Pshemo

Reputation: 124215

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.

Upvotes: 123

Anuj
Anuj

Reputation: 147

java -version

This is the command to get the current installed version info

Upvotes: 5

Related Questions