via: http://www.codeguru.com/forum/showthread.php?t=487190 for detail
Before using a method it always pays to read the API documents on what the method does. For example docs for the console() method say:
Quote:
Whether a virtual machine has a
console is dependent upon the
underlying platform and also upon the
manner in which the virtual machine is
invoked. If the virtual machine is
started from an interactive command
line without redirecting the standard
input and output streams then its
console will exist and will typically
be connected to the keyboard and
display from which the virtual machine
was launched. If the virtual machine
is started automatically, for example
by a background job scheduler, then it
will typically not have a console.
If this virtual machine has a console
then it is represented by a unique
instance of this class which can be
obtained by invoking the
System.console() method. If no console
device is available then an invocation
of that method will return null.of that method will return null.
If you try invoking the program from the command line using the java command then it will have a console and the method should not return null.of that method will return null.
Alternatively, using the Scanner class will work inside of your IDE:
Scanner sc = new Scanner(System.in);