What is the difference between java
, javaw
, and javaws
?
I have found that on Windows most usage of Java is done using javaw
.
What is the difference between java
, javaw
, and javaws
?
I have found that on Windows most usage of Java is done using javaw
.
I have checked that the output redirection works with javaw
:
javaw -cp ... mypath.MyClass ... arguments 1>log.txt 2>err.txt
It means, if the Java application prints out anything via System.out or System.err, it is written to those files, as also with using java (without w
). Especially on starting java
, the JRE may write starting errors (class not found) on the error output pipe. In this respect, it is essential to know about errors. I suggest to use the console redirection in any case if javaw
is invoked.
In opposite if you use
start java .... 1>log.txt 2>err.txt
With the Windows console start
command, the console output redirection does not work with java
nor with javaw
.
Explanation why it is so: I think that javaw
opens an internal process in the OS (adequate using the java.lang.Process class), and transfers a known output redirection to this process. If no redirection is given on the command line, nothing is redirected and the internal started process for javaw
doesn't have any console outputs. The behavior for java.lang.Process is similar. The virtual machine may use this internal feature for javaw
too.
If you use 'start', the Windows console creates a new process for Windows to execute the command after start, but this mechanism does not use a given redirection for the started sub process, unfortunately.
java.exe is associated with the console, whereas javaw.exe doesn't have any such association. So, when java.exe is run, it automatically opens a command prompt window where output and error streams are shown.
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.
And javaws is for Java web start applications, applets, or something like that, I would suspect.
java: Java application executor which is associated with a console to display output/errors
javaw: (Java windowed) application executor not associated with console. So no display of output/errors. It can be used to silently push the output/errors to text files. It is mostly used to launch GUI-based applications.
javaws: (Java web start) to download and run the distributed web applications. Again, no console is associated.
All are part of JRE and use the same JVM.
See Java tools documentation for:
java
command1/javaw
command2javaws
command, the "Java Web Start command"See also JDK 9 Release Notes Deprecated APIs, Features, and Options: