reference:http://javapapers.com/core-java/java-vs-javaw-vs-javaws/
This article gives an awareness tip. Do you know the difference between java, javaw and javaws tools. All these three are java application launchers. We know well about java.exe which we use quite often. Our command line friend, mostly we use it for convenience to execute small java programs. javaw is rare for us. Sometimes we have seen that in running application list in windows task manager. javaws is web start utility.
jvm.dll
We need to know about jvm.dll also. This is the actual java virtual machine implementation in windows environment and it is part of the JRE. A ‘C’ program can use this jvm.dll directly to run the jvm.
java.exe
java.exe is a Win32 console application. This is provided as a helper so that, instead of using jvm.dll we can execute java classes. As it is a Win32 console application, obviously it is associated with a console and it launches it when executed.
javaw.exe
javaw.exe is very similar to java.exe. It can be considered as a parallel twin. It is a Win32 GUI application. This is provided as a helper so that application launches its own GUI window and will not launch a console. Whenever we want to run a GUI based application and don’t require a command console, we can use this as application launcher. For example to launch Eclipse this javaw.exe is used. Write a small java hello world program and run it as “javaw HelloWorld” using a command prompt. Silence! nothing happens then how do I ensure it. Write the same using Swing and execute it you will see the GUI launched. For the lazy to ensure that it is same as java.exe (only difference is console) “javaw HelloWorld >> output.txt”. It silently interprets and pushes the output to the text file.
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();
}
});
}
}
|
We can execute the above GUI application using both java.exe and javaw.exe If we launch using java.exe, the command-line waits for the application response till it closes. When launched using javaw, the application launches and the command line exits immediately and ready for next command.
javaws.exe
javaws.exe is used to launch a java application that is distributed through web. We have a jnlp_url associated with such application. We can use as “javaws jnlp_url” to launch the application. It downloads the application from the url and launches it. It is useful to distribute application to users and gives central control to provide updates and ensures all the users are using the latest software. When the application is invoked, it is cached in the local computer. Every time it is launched, it checks if there is any update available from the distributor.
-----------------------------------------------------------------------------华丽的分割线--------------------------------------------------------------------
如果你英文够好的话,请忽视下面吧,这个中文翻译个人感觉不是很到位,虽然加入了一些图和自己理解.
转自:http://www.myexception.cn/program/1221139.html
java ,javaw 和 javaws 的区别:
首先,所有的这些都是java的启动装置,java.exe经常使用,当用命令行输出到window的时候,会有java.exe进程,通过任务管理器可以看到。通常 我们执行一些小的java程序的时候会有 java.exe进程在运行。javaw.exe对于我们也比较特殊,我们也能够通过任务管理器看到javaw.exe进程的运行。javaws通常web开启的时候的进程。
jvm.dll
jvm.dll是一个java虚拟机在windows平台环境上的实现,也是JRE的一部分,一个C程序能够使用jvm.dll直接运行在jvm上。
java.exe
java.exe是win32控制台应用,它提供了一种帮助,代替使用jvm.dll执行java classes 文件,作为一个win32控制台应用,显然他是和一个控制台相关联,当执行java classes的时候,它运行。
javaw.exe
javaw.exe是相似的和java.exe 是一个win32的GUI应用,应用提供自己的GUI窗口,不启用控制台。
因此我们想运行一个GUI程序不需要命令控制台。
下面是一个例子:
package javaw; 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(); } }); } }
上面是一个GUI程序,按照如下方式运行就是在控制台上运行:
java -classpath . javaw.HelloWorldSwing
解释:其中 -classpath . 代表把classpath 的路径设置为当前目录。
运行后查看任务管理器出现了 java.exe进程 ------ 因为这是通过控制台运行的。
图如下:
如果在eclipse中直接运行:运行后 查看任务管理器出现 javaw.exe进程 --因为没有通过控制台输出运行。
图如下:
如果用javaw通过命令行运行也是如上图所示:
注: javaw -classpath . javaw.HelloWorldSwing 启动的进程为javaw.exe
java -classpath . javaw.HelloWorldSwing 启动的进程为java.exe
java.exe 和 javaw.exe两种运行方式的区别还有一点 java运行GUI以后堵塞在那里直到窗口关闭。
javaw运行GUI后 直接就可以进行下一条命令的运行了。
javaws.exe
javaws.exe进程适用于启动通过web 配置的程序,简而言之就是在web应用程序中应用。
总结:
java.exe用于启动window console 控制台程序
javaw.exe用于启动 GUI程序
javaws.exe用于web程序。
jvm.dll就是java虚拟机规范在windows平台上的一种实现