What is the difference between 'java', 'javaw', and 'javaws'?
Asked Answered
P

5

233

What is the difference between java, javaw, and javaws?

I have found that on Windows most usage of Java is done using javaw.

Powder answered 19/11, 2011 at 14:35 Comment(1)
That's because Windows has this annoying habit of starting an actual Terminal (which should not even be called a "Terminal"...) in the foreground whenever you start a program with java -cp .... As almost nobody wants that, javaw is the choice to make that annoying window disappear.Mcgehee
N
265

See Java tools documentation for:

  1. The java tool launches a Java application. It does this by starting a Java runtime environment, loading a specified class, and invoking that class's main method.
  2. The javaw command is identical to java, except that with javaw there is no associated console window. Use javaw when you don't want a command prompt window to appear.

The javaws command launches Java Web Start, which is the reference implementation of the Java Network Launching Protocol (JNLP). Java Web Start launches Java applications/applets hosted on a network.

If a JNLP file is specified, javaws will launch the Java application/applet specified in the JNLP file.

The javaws launcher has a set of options that are supported in the current release. However, the options may be removed in a future release.

See also JDK 9 Release Notes Deprecated APIs, Features, and Options:

Java Deployment Technologies are deprecated and will be removed in a future release
Java Applet and WebStart functionality, including the Applet API, the Java plug-in, the Java Applet Viewer, JNLP and Java Web Start, including the javaws tool, are all deprecated in JDK 9 and will be removed in a future release.

Nickelson answered 19/11, 2011 at 14:43 Comment(0)
P
80

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.

Phonemics answered 4/2, 2014 at 4:11 Comment(2)
so if I've installed JRE, javaw should be in my PATH? (It isn't)Jonahjonas
@endolith, Java installation on Windows doesn't, in my experience, add anything to the PATH variable. If you've only installed JRE, you'll probably have to add the JRE/bin directory to PATH manually; if you've installed JRE and JDK, you'd add the JDK/bin to PATH instead.Lowder
G
10

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.

Glaive answered 19/11, 2011 at 14:40 Comment(0)
H
7

From http://publib.boulder.ibm.com/infocenter/javasdk/v6r0/index.jsp?topic=%2Fcom.ibm.java.doc.user.aix32.60%2Fuser%2Fjava.html:

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.

Highsmith answered 19/11, 2011 at 14:47 Comment(1)
The link is broken: "The requested page does not exist or might have moved."Willner
N
4

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.

Neediness answered 5/10, 2018 at 14:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.