Maheshwar Reddy K
Maheshwar Reddy K

Reputation: 1231

Error:could not create the Java Virtual Machine Error:A fatal exception has occured.Program will exit

I have just installed Java SE Development Kit 8u91 on my 64 bit Windows-10 OS. I set my path variables . I tried java --version in my command prompt it gave me an error.

c:\Users\Onlymanu>java --version
Unrecognized option: --version    
Error: Could not create the Java Virtual Machine. 
Error: A fatal exception has occurred. Program will exit.

But when i tried java -version it worked.

I tried initializing _JAVA_OPTIONS environment variable and ever tried re-installation none of them worked. Can any one help me please?

Upvotes: 116

Views: 413028

Answers (10)

herion05
herion05

Reputation: 29

As someone has pointed out before you get that error because java --version doesn't exist as a command before java 9+. I had a similar issue where I installed the latest version of jdk and the command would still return the exact same error you have provided. In my case the error came from having an older version of java still installed on my system.

To fix this, since you're on Windows go to "Settings"->"Apps & Features" and then search for "Java". If you find that a you still have an older version of Java installed, particularly one before Java 9 like Java 8 for example, uninstall that version and install a newer version instead. Don't forget to configure the "Environment Variables" afterwards.

Upvotes: 1

Jeremias Bila
Jeremias Bila

Reputation: 121

This happens because the CMD doesn't recognize the "java --version" try writing "java -version" when "java --version" it tries to create a JVM. IT Fails because that's wrong command.

enter image description here

Upvotes: 11

codingjeremy
codingjeremy

Reputation: 5741

Java 8:

java -version

Java 9+:

java --version

Upvotes: 71

Saumya Agnihotri
Saumya Agnihotri

Reputation: 894

I was facing a similar issue. Actually the command is :

java -version and not java --version.

You will get output something like this:

java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)

Upvotes: 72

Santosh Sindham
Santosh Sindham

Reputation: 919

--version is a valid option from JDK 9 and it is not a valid option until JDK 8 hence you get the below:

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

You can try installing JDK 9 or any version later and check for java --version it will work.

Alternately, from the installed JDK 9 or later versions you can see from java -help the below two options will be available:

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

where as in JDK 8 you will only have below when you execute java -help

    -version      print product version and exit

I hope it answers your question.

Upvotes: 10

Dhaval Dalsania
Dhaval Dalsania

Reputation: 1099

I think you have put command like java -VERSION. This is in capital letters You need to put all command in lowercase letters

javac -version
java -version

All characters must be in lowercase letter

Upvotes: 109

monti
monti

Reputation: 794

java -version
java -showversion

Both commands work In Linux 16.04 LTS

Upvotes: 5

Veli Mpinda
Veli Mpinda

Reputation: 435

the command should be java -version

Upvotes: 31

Akash Perera
Akash Perera

Reputation: 115

Your command is wrong.

Linux

java -- version

macOS

java -version

You can't use those commands other way around.

Upvotes: 6

Ankur Singhal
Ankur Singhal

Reputation: 26067

Try executing below command,

java -help

It gives option as,

-version print product version and exit

java -version is the correct command to execute

Upvotes: 13

Related Questions