dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Find the Console of the Current Runtime Environment

See how to use the Runtime class to get the console of the current runtime environment.


advertisement

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


The Runtime class provides a mechanism to get the console of the current runtime environment. Using this, we can perform needed actions on the console.

import java.io.*;

public class SystemConsole
{
   public static void main(String args[])
   {
      SystemConsole systemConsole = new SystemConsole();
      systemConsole.proceed();
   }
   
   private void proceed()
   {
      System.out.println("Getting handle of runtime Console");
      Console runtimeConsole = System.console();
      System.out.println("Got handle of runtime Console");
      System.out.println("You can now use runtimeConsole object to perform actions of your choice on java.io.Console");
   }
}

/*

Expected output:

[root@mypc]# java SystemConsole
Objects.deepEquals(1,1): true
Objects.deepEquals(1,2): false
Objects.deepEquals("abc","abc"): true
Objects.deepEquals("aa","ab"): false

*/

 

Visit the DevX Tip Bank

 





   
Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
Thanks for your registration, follow us on our social networks to keep up-to-date