2

I have this simple java command line application

public static void main(String[] args) throws IOException {
        System.out.println("Hello World !");
        System.in.read();
}

When I start it on Windows 10, Windows Task Manager displays two instances of java.exe as subprocesses of the Windows Command Prompt process:

  1. Java(TM) Platform SE binary from

C:\Program Files\Common Files\Oracle\Java\javapath_target_383000\java.exe

  1. OpenJDK Platform binary from

C:\Program Files\Java\jdk-15.0.1\bin\java.exe

enter image description here

One should think one instance of the JVM should be enough to run this program, so why are there two ?

Edit: I compiled this program against a JDK 1.8.0 (instead of JDK 15.0.1) and now only the Java(TM) Platform SE binary shows up.

Angle.Bracket
  • 1,438
  • 13
  • 29

1 Answers1

2

This is a feature of Oracle's installer for Java on Windows. The installer adds the folder C:\Program Files\Common Files\Oracle\Java\javapath_target to the PATH variable. This folder contains a symlink to a java.exe executable in another folder. This executable detects the location of the latest/configured JRE version by checking the registry and JAVA_HOME. Then it calls java.exe of the actual JRE. So the first java.exe is not a real JVM but a simple native app that gets executed, when you call java within the console. To avoid the usage of this mechanism simply replace the javapath_target folder with the folder of your JRE within the PATH environment variable. For a more detailed description see also this answer.

rmunge
  • 3,653
  • 5
  • 19