Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between java and javaw

Tags:

java

jvm

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.

like image 226
Kusum Adhikari Avatar asked Aug 26 '12 10:08

Kusum Adhikari


People also ask

What is the difference between java exe and Javaw exe?

Both java.exe and javaw.exe can execute java programs including jar file, the only difference is that with java.exe you have a console executed and you need to wait until your java program finishes to run any other command on the other hand in case of javaw.exe no console or window is associated with execution.

What is Javaw exe used for?

This non-console version of the application launcher is used to launch java applications usually with graphical user interfaces (GUIs). These applications have windows with menus, buttons and other interactive elements.


1 Answers

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)

like image 105
prayagupa Avatar answered Nov 13 '22 06:11

prayagupa