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.
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.
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.
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 thatjavaw
has no associated console window. Usejavaw
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With