Difference Between Java.Exe and Javaw.Exe

Difference between java.exe and javaw.exe

java.exe is the command where it waits for application to complete untill it takes the next command.
javaw.exe is the command which will not wait for the application to complete. you can go ahead with another commands.

Difference between java and javaw

The java and javaw commands states

The java and javaw tools start a Java application by starting a JRE and loading a specified class.

The javaw command is identical to java, except that javaw has no
associated console window. Use javaw when you do not want a command
prompt window to be displayed.

The javaw launcher displays a window with error information if it fails.
In case of Tomcat you won't see Win32 console application running, similarly to launch Eclipse, javaw.exe is used.

Example :
Write the following code :

import javax.swing.*;
public class JavavsJavaw {
private static void renderGUI() {
JFrame jFrame = new JFrame("HelloWorld Swing");
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel helloLabel = new JLabel("Hello World!");
jFrame.getContentPane().add(helloLabel);
jFrame.pack();
jFrame.setVisible(true);
}

public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
renderGUI();
}
});
}
}

Step 1 : C:\>java JavavsJavaw
(the command-line waits for the application response till it closes)
Step 2 : C:\>javaw JavavsJavaw
(the application launches and the command line exits immediately and ready for

next command)

What is the difference between 'java', 'javaw', and 'javaws'?

See Java tools documentation for:

  • java command1/javaw command2
  1. The java tool launches a Java application. It does this by starting a Java runtime environment, loading a specified class, and invoking that class's main method.
  2. The javaw command is identical to java, except that with javaw there is no associated console window. Use javaw when you don't want a command prompt window to appear.
  • javaws command, the "Java Web Start command"

The javaws command launches Java Web Start, which is the reference implementation of the Java Network Launching Protocol (JNLP). Java Web Start launches Java applications/applets hosted on a network.


If a JNLP file is specified, javaws will launch the Java application/applet specified in the JNLP file.

The javaws launcher has a set of options that are supported in the current release. However, the options may be removed in a future release.

See also JDK 9 Release Notes
Deprecated APIs, Features, and Options:

Java Deployment Technologies are deprecated and will be removed in a future release

Java Applet and WebStart functionality, including the Applet API, the Java plug-in, the Java Applet Viewer, JNLP and Java Web Start, including the javaws tool, are all deprecated in JDK 9 and will be removed in a future release.

Difference between java.exe, javaw.exe and jvm.dll

  • jvm.dll is the actual Windows implementation of the JVM (or better, the main entry point). C or C++ applications can use this DLL to run an embedded Java runtime, and that would allow the application to interface directly with the JVM, e.g. if they want to use Java for its GUI.

  • java.exe is a wrapper around the DLL so that people can actually run Java classes without the need for a custom launcher application. It is a Win32 Console application, so Windows will open a fresh Command Prompt window if the exe is not run from a batch file.

  • javaw.exe is a wrapper like java.exe, but it is a Win32 GUI application. Windows doesn't have to open a Command Prompt window, which is exactly what you want to run a GUI application which opens its own windows.

EDIT: These shouldn't make any difference in performance except for the overhead of process creation and initialization.

The most important thing: it should't matter; if you are worrying about this you might actually want to keep Java running instead of launching it hundreds of times.

Difference between running Eclipse on jvm.dll and java.exe (or javaw.exe)

How Eclipse is launched when no -vm is specified

OK, just to resolve a confusion: fresh installation of Eclipse on Windows has no -vm configuration specified in the eclipse.ini file.

Let's see what the official Equinox Launcher documentation says about situation when no -vm is specified (emphasis mine):

When no -vm is specified, the launcher looks for a virtual machine first in a JRE directory in the root of eclipse and then on the search path. If
Java is found in either location, then we look for a JVM shared library (jvm.dll on Window, libjvm.so on *nix platforms) relative to that Java executable.

  • If a JVM shared library is found we load it and use the JNI invocation API to start the vm
  • If no JVM shared library is found, we exec the Java launcher to start the vm in a new process

So as you can see, the jvm.dll is the one that is searched for in the first place, and ONLY if it is not found, THEN the Java launcher (i.e. java.exe or javaw.exe) is used.



Difference between using jvm.dll and javaw.exe (or java.exe)

  • When using jvm.dll Eclipse uses the JNI Invocation API to
    start the vm in the current process. You will see only ONE process in the task manager:

    eclipse.exe

  • When using javaw.exe (or java.exe) Eclipse executes that Java
    Launcher to start the vm in a new process. You will see TWO processes in the task manager:

  1. eclipse.exe
  2. javaw.exe (or java.exe if it was configured)

The javaw.exe will be the sub-process (child process) of the eclipse.exe process.

So the choice is up to you.



Other thoughts

One of the most recommended options to use is to specify a specific JVM for Eclipse to run on. Doing this ensures that you are absolutely certain which JVM Eclipse will run in and insulates you from system changes that can alter the "default" JVM for your system. Read more here: Specifying the JVM

java.exe is faster than javaw.exe

Found the problem using VisualVM (profiler).
Found out that there was logging instructions which were taking much time.
Removed all logs as below:

LogManager.getLogManager().getLogger("").setLevel(Level.OFF);

Thanks to fl0w.

How java.exe and javaw.exe are used in Eclipse?

The Eclipse launcher uses javaw internally to launch Eclipse. You can see the settings in eclipse.ini file in your installation. This lets you easily identify Eclipse in the list of processes in the task manager instead of seeing another Java process.

When you Run/Debug Java programs inside Eclipse, it defaults to using Java to launch another jvm, but I believe you can set it to use javaw if need. Some launchers use javaw by default, I think the Tomcat launcher (in WTP) is one of them.

java how to know if you're running javaw.exe vs. java.exe

If the VM has no Console available (say, because you started it with javaw.exe), then a call to System.console() will return null.

edit: i.e.,

final boolean amRunningJavaW = System.console() == null;


Related Topics



Leave a reply



Submit