Java.lang.System.console() Method



Description

The java.lang.System.console() method returns the unique Console object associated with the current Java virtual machine, if any.

Declaration

Following is the declaration for java.lang.System.console() method

public static Console console()

Parameters

NA

Return Value

This method returns the system console, if any, otherwise null.

Exception

NA

Example

The following example shows the usage of java.lang.System.console() method.

package com.tutorialspoint;

import java.lang.*;
import java.io.Console;

public class SystemDemo {

   public static void main(String[] args) {

      Console ob = System.console();

      ob.printf("Welcome to tutorialspoint...");

      // flushes the console
      ob.flush();
   }
} 

Let us compile and run the above program, this will produce the following result −

Welcome to tutorialspoint...
java_lang_system.htm
Advertisements