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

10

114

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?

Swagsman answered 12/5, 2016 at 11:57 Comment(4)
Try "java -version" ... only one dash. But still, very strange.Spellbind
"java -version" is working for me no problem with that but i only hace problem with "java --version"Swagsman
--version is not an acceptable option to use with javaForeconscious
I don't get your question - if you already found out that java -version works, what do you want to know?Alagez
A
109

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

Amorette answered 18/5, 2017 at 8:17 Comment(3)
Please format commands appropriately. see stackoverflow.com/help/how-to-askGildagildas
in my case, it was java --version double slash instead of java -versionOvertrump
in my case, java -version would not work, until I first did javac -version :/Instrumentation
N
68

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)
Neoclassicism answered 26/1, 2020 at 19:47 Comment(0)
S
64

Java 8:

java -version

Java 9+:

java --version
Spanner answered 19/2, 2021 at 19:7 Comment(0)
G
31

the command should be java -version

Greenwell answered 13/11, 2017 at 11:43 Comment(0)
Q
13

Try executing below command,

java -help

It gives option as,

-version print product version and exit

java -version is the correct command to execute

Quench answered 12/5, 2016 at 12:5 Comment(0)
H
10

--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.

Huskey answered 19/10, 2019 at 12:30 Comment(0)
C
9

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

Cordeliacordelie answered 11/5, 2021 at 11:2 Comment(0)
R
6

Your command is wrong.

Linux

java -- version

macOS

java -version

You can't use those commands other way around.

Recess answered 11/11, 2017 at 21:32 Comment(0)
W
5
java -version
java -showversion

Both commands work In Linux 16.04 LTS

Watch answered 18/4, 2018 at 8:12 Comment(0)
P
0

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.

Populace answered 10/1 at 22:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.