ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

Console class in Java

In this article we will learn about Console class in Java.

In JDK 1.5 a new class was introduced under IO package i.e. Console class which is a concrete class. Although Console class is a concrete class we can’t create object of this class but we can retrieve the reference of console object by using System.Console.

Since Console class has a private constructor that is why we are unable to create an object to Console class.

 

Let us take a look at the below program:

 

  1. public class Manager{
  2.  
  3. public static void main(String[] args){
  4.  
  5. System.out.println(1);
  6.  
  7. Console c1=System.console();
  8.  
  9. System.out.println(c1);
  10.  
  11. System.out.println(2);
  12.  
  13. Console c2=System.console();
  14.  
  15. System.out.println(c1==c2);
  16.  
  17. }
  18.  
  19. }

 

OUTPUT:

1

null

2

true

Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!