Java – Difference between java and javaw

javajvm

I searched to know the difference between java.exe and javaw.exe. I read through
Difference between Java.exe and Javaw.exe.

There it is stated that java.exe is for console and javaw.exe is for window application.
In some other post it is mentioned that console is not available in javaw.

but I wonder when I run Tomcat server and see its process in process explorer I see javaw.exe even though tomcat is a console application.

Best Answer

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)