Keywords: Java Launcher Tools | java command | javaw command | javaws command | Java Web Start | JNLP Protocol
Abstract: This technical paper provides an in-depth examination of the three core Java launcher tools—java, javaw, and javaws—detailing their functional differences, use cases, and underlying architecture. Through comparative analysis of console association, GUI application support, and network deployment capabilities, the paper elucidates the distinct roles of java as the standard console launcher, javaw as the console-less GUI launcher, and javaws as the Java Web Start network application launcher. Supported by code examples and practical scenarios, it guides developers in selecting the appropriate tool based on specific requirements, with special attention to the deprecation status of javaws in JDK 9 and beyond.
Overview of Java Launcher Tools
In the Java development ecosystem, java, javaw, and javaws are three essential application launcher tools that, while sharing the same Java Virtual Machine (JVM) core, exhibit significant differences in usage scenarios and functional characteristics. Understanding these distinctions is crucial for selecting the correct application deployment method.
java Command: Standard Console Application Launcher
The java command is the most fundamental application launcher in the Java platform, primarily responsible for starting the Java runtime environment, loading specified class files, and invoking the class's main method. As a Win32 console application, java associates with a console window upon execution, which displays program output and error logs.
In practical development, the java command is commonly used to execute command-line Java programs, especially when real-time monitoring of program output and debugging information is required. For example, running a simple HelloWorld program:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
When executed with the command java HelloWorld, the console immediately displays the output, facilitating developer observation of the program's runtime status.
javaw Command: Console-Less GUI Application Launcher
The javaw command is functionally identical to the java command, with the sole distinction being that it does not associate with any console window. This design makes javaw particularly suitable for launching Graphical User Interface (GUI) applications, as GUI applications typically do not require command-line output display.
When an application is launched using javaw, no command prompt window appears; the application runs directly in the background. This is especially important for desktop applications that need to maintain a clean user interface. For instance, developing a Swing GUI application:
import javax.swing.*;
public class HelloWorldSwing {
private static void createAndShowGUI() {
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() {
createAndShowGUI();
}
});
}
}
When launched with the command javaw HelloWorldSwing, the application displays the graphical interface directly without a console window. If program output needs to be captured, it can be redirected to a text file: javaw HelloWorld >> output.txt.
javaws Command: Java Web Start Network Application Launcher
The javaws command is specifically designed to launch Java Web Start applications based on the Java Network Launching Protocol (JNLP). This mechanism allows for the distribution and launching of Java applications over the network, providing users with the convenience of automatic updates and centralized management.
Java Web Start operates by downloading application resources from a specified JNLP file URL and caching them for execution on the local computer. Each time the application is launched, the system automatically checks the server for updated versions, ensuring users always employ the latest software. For example, launching a network application: javaws http://example.com/application.jnlp.
However, it is important to note that, according to Oracle's official announcement, Java deployment technologies—including Java Applet, Java Plugin, JNLP, and Java Web Start—have been deprecated in JDK 9 and will be removed in a future release. This indicates that the javaws tool and its associated functionalities are gradually being phased out.
Technical Architecture Comparison
From an implementation perspective, all three launcher tools rely on the same JVM core—manifested as the jvm.dll dynamic link library in Windows environments. This DLL file contains the actual implementation of the Java Virtual Machine and is a critical component of the JRE.
java.exe and javaw.exe are essentially wrappers around jvm.dll, but they employ different application types: java.exe as a Win32 console application and javaw.exe as a Win32 GUI application. This design difference dictates their interaction with the system console.
Guidelines for Application Scenario Selection
When selecting the appropriate launcher tool, developers should consider the specific needs of the application:
- Command-line programs requiring real-time output monitoring and debugging: Use the
javacommand - Graphical interface applications, particularly desktop apps needing a clean interface: Use the
javawcommand - Network-distributed applications (in JDK 8 and earlier): Use the
javawscommand
With the deprecation of Java Web Start, developers are advised to consider alternative application distribution methods, such as using local installation packages or web-based technology stacks.
Conclusion and Future Outlook
The java, javaw, and javaws launcher tools each play distinct roles in the Java ecosystem, providing specialized support for different types of application deployments. Understanding their core differences and applicable scenarios enables developers to make more informed technical choices in practical projects. Although javaws is facing obsolescence, java and javaw remain vital tools for Java application launching and will continue to play key roles in future Java development.