Thursday, 20 March 2014

Difference between java and javaw

java and javaw both are used to run java programs. Java.exe is console based, you must wait until the program finishes execution. Javaw.ext don't have any windows associated with it. It simply runs in separate window.

Example

import javax.swing.*;
 
public class HelloWorldSwing {
     static void createAndShowGUI() {
        JFrame jFrame = new JFrame("HelloWorld");
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JLabel hello = new JLabel("Hello World!");
        jFrame.getContentPane().add(hello);
        jFrame.pack();
        jFrame.setVisible(true);
    }
 
    public static void main(String[] args) {
        createAndShowGUI();
    }
}

Run the application with java first. Until you close the GUI prompt the terminal blocks.

 
Run the same Application with javaw, the terminal or console won't blocked.

 
javaw.exe is the better choice to launch GUI Applications.

No comments:

Post a Comment