Tuesday, January 28, 2014

difference between java and javaw

create this file JavaConsole.java:

import java.io.Console;

public class JavaConsole {
 public static void main(String[] args) {
  Console console = System.console();
  System.out.println("the console is " + console);

compile it:
javac JavaConsole.java
run it:
java JavaConsole > outputjava.txt
javaw JavaConsole > outputjavaw.txt

in the second case, the console object is null, because javaw has not associate a Console to allow for stdin and stdout. We can't even print to a console output, that's why I had to redirect to a file in order to observe the result of the println.

When should I use javaw? Well, frankly, I guess when you don't want a console output, like in most server side applications. Why WebLogic uses java and not javaw? Good question.... in fact, you always want to redirect the stdout of WebLogic to a file (hoping that nothing is written to it...)...

No comments: