Java Console
Java Console 1 0f 5
Class Name : Console
Package : java.io
Use : Console class provides convenient methods to input and output data on command line.
How to create a console Object ?
We cannot create a console object by using new keyword. But we can access the console by using the System class factory method console(). (Please note that the class name starts with “C” whereas method name starts with “c”.). If you remember java coding conventions says that class names should always start with capital letters and method names should start with small letters. So the Console object can be created using System.console() method.
public static Console console()
Returns the unique Console object associated with the current Java virtual machine, if any.
Returns: The system console, if any, otherwise null.
Since: 1.6
So the method definition says that “System.console()” can return null if it did not find any console. So you should always do a null check before using a console
Next >>>>