Macos – java virtual machine and what does it have to do with Java

javajrejvmmacos

I was trying to install eclipse on my Macbook Air. When I run the installer I get this message

enter image description here

There seems no official page dedicated to JVM like other Apps. When I search "install jvm" I was lead to a "download java" page.

I installed the latest java from this page anyway but the message is still there, which makes me more confused.

Questions are:

  1. If the JVM is meant to enable Java "anywhere", shouldn't it be already installed after I install the latest Java?

  2. When I search around google presents a lot of pages, none of them looks like a genuine page, I even search jvm in java.com, but nothing useful comes up.

    Why is it so hard to find such a popular tool and where exactly should I go to download the JVM?

Best Answer

What is the JVM?

The Java Virtual Machine (JVM) is an interpreter that runs Java bytecode.

When you compile a Java program the output is Java bytecode which can then be executed by the any computer that has a native JVM.

In the Java programming language, all source code is first written in plain text files ending with the .java extension.

Those source files are then compiled into .class files by the javac compiler.

A .class file does not contain code that is native to your processor; it instead contains bytecodes — the machine language of the Java Virtual Machine (JVM).

The java launcher tool then runs your application with an instance of the Java Virtual Machine.

enter image description here

Because the Java VM is available on many different operating systems, the same .class files are capable of running on Microsoft Windows, the Solaris™ Operating System (Solaris OS), Linux, or Mac OS.

Some virtual machines, such as the Java SE HotSpot at a Glance, perform additional steps at runtime to give your application a performance boost. This includes various tasks such as finding performance bottlenecks and recompiling (to native code) frequently used sections of code.

enter image description here

Source About the Java Technology


So how do I download a JVM?

The Java Runtime Environment (JRE) includes a JVM.

  • If you are just running Java programs the JRE is sufficient.

The Java Development Kit is a superset of the JRE (so it also includes a JVM). It also contains other tools required to develop Java programs, for example a compiler.

  • If you are developing Java programs you should download the JDK.

You can download both the JRE and the JDK at http://www.oracle.com/technetwork/java/javase/downloads/index.html


So why am I getting an error message?

The version of the JVM you already have installed is too old for the version of Eclipse you are trying to install.

In order to get a newer version you need to install either a newer JRE or a newer JDK, which both include a JVM.


I installed the latest java from this page anyway but the message is still there

A potential solution to your problem might be to uninstall Java6 (provided by Apple itself) and only have Java7 installed in your system. This only applies in case you have no applications that desperately need the old Java6 version to be installed.

To remove the Apple-like Java6 installation open a Terminal and:

sudo rm -rf /System/Library/Java/JavaVirtualMachines/1.6.0.jdk

After this step you should only have Java7 by Oracle installed in your system. To verify, open another terminal and do a:

java -version 

It should display something like "java version "1.7.0_XX" where XX is the current update version of the Java7 installation. If not: proceed with the next step.

Redefine the JAVA_HOME variable (to support IDEs like Eclipse and other developer tools...), which helps detecting where the "active" Java installation is situated in your system. Open a terminal and (Note: replace XX first!):

sudo rm /Library/Java/Home

sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_XX.jdk/Contents/Home /Library/Java/Home

Afterwards, a fresh installation of Eclipse should detect Java7 in your system and should work with this version out of the box. You can modify an installed Eclipse to use this installation by navigating in Eclipse to:

Preferences -> Java -> Installed JREs.

Then remove the old Java6 system entry AND add new path (see above) with the name Java7.

Source answer to I installed Java 7 but Eclipse keep saying that 1.6 is not suitable for this product by MWiesner

Related Question